Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Satyajit Bhadange
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Yucca Nel
Ranch Hand
Posts: 147
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Naman Patidar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please SearchFirst, especially in the Beginning Java forum. This question has been asked many, many times before.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic