aspose 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 Spring in Action this week in the Spring 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: 19720
    
  20

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Why filename.java should be same as public class name declared inside java file