Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why do we need to save the java file with the name of public class file

 
shekar krishna
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

I have a basic doubt. why do we need to save the file with that name of public class name.If i dont what will happen. why it should be done.

Thanks,
krishna
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It won't compile. Just follow such simple rules.
It's actually very convenient to search for a class, by looking at filenames.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by shekar krishna:
Why do we need to save the file with that name of public class name?


Because that is how the language is defined. The motivation was to make it
easier for the compiler to find source code, but ultimately the answer is that's the way Java is defined.

Originally posted by shekar krishna:
If i dont what will happen?


Try it and see.

Originally posted by shekar krishna:
Why it should be done?


Because that is the way Java is defined.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Java In General (Beginner) forum.

Mark
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because the Java Gods said so!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic