File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Why filename.java should be same as public class name declared inside java file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Why filename.java should be same as public class name declared inside java file" Watch "Why filename.java should be same as public class name declared inside java file" New topic
Author

Why filename.java should be same as public class name declared inside java file

Satyajit Bhadange
Ranch Hand

Joined: May 13, 2010
Posts: 104
hi,

Why filename.java should be same as public class name declared inside java file. Why this convention is followed

and also...why cant we declare class as a private or protected.


Thanks
user101
Problems And Solutions - Algorithms
Yucca Nel
Ranch Hand

Joined: Nov 20, 2008
Posts: 147

Satyajit Bhadange wrote:hi,

Why filename.java should be same as public class name declared inside java file. Why this convention is followed

and also...why cant we declare class as a private or protected.

As for question one don't question the language layout, it's not our issue..
Question2: Read up on this matter urgently as it's related to some of the security features of Java.


SCJP 6.0, SCJD (400/400), SCBCD for JEE 5, SCWCD 1.4 I do videos for development at
http://www.youtube.com/user/thejartender?feature=mhee
I am probably the only developer ever to have had an orange sized brain tumor in my brain while learning development!!
Naman Patidar
Greenhorn

Joined: Oct 03, 2008
Posts: 15
To be precise, because JAVA specifications say this .

and to be specific now, Why would any language make it difficult to find your source for absolutely no benefit by allowing arbitrary file/class naming?
public class is entry point for the JVM (which in turn help compiler to compile dependencies.).

private and protected classes are allowed but only as inner classes.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Please SearchFirst, especially in the Beginning Java forum. This question has been asked many, many times before.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Naman Patidar wrote:Why would any language make it difficult to find your source for absolutely no benefit by allowing arbitrary file/class naming?

To provide another level of functional grouping.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why filename.java should be same as public class name declared inside java file
 
Similar Threads
inbuild classes shows only filename.class why ?
Why does java not allow multiple public classes in a java file ?
Name of java file with public class
A very simple question (Please Answer)
class name & file name