This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes why do we need to save the java file with the name of public class file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why do we need to save the java file with the name of public class file" Watch "why do we need to save the java file with the name of public class file" New topic
Author

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

shekar krishna
Greenhorn

Joined: Jan 08, 2006
Posts: 4
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

It won't compile. Just follow such simple rules.
It's actually very convenient to search for a class, by looking at filenames.


[My Blog]
All roads lead to JavaRanch
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
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.


There is no emoticon for what I am feeling!
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17258
    
    6

Moving to the Java In General (Beginner) forum.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Because the Java Gods said so!


Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why do we need to save the java file with the name of public class file