This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes public class in a file question . Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "public class in a file question ." Watch "public class in a file question ." New topic
Author

public class in a file question .

Sahil Reddy
Ranch Hand

Joined: Jan 24, 2011
Posts: 145
Hello Pals

I have read that

" The name of a file should be same as that of the public class in a file, if any "

I just want to know why ???


Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

Please SearchFirst. 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
Sahil Reddy
Ranch Hand

Joined: Jan 24, 2011
Posts: 145
I think almost every question have been answered , if one has to search for everything then it is not more a forum, it would be like google search.
After all , my same question would give some newcomer to answer it and enforces his/her learning. This is what a benefit of forum is at the first place.

Regards
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4338
    
    7

Of course, for such questions Google search (or a forum search) is far more efficient than posting to a forum. You'll find an answer much quicker that way.

It's not a very helpful question to give a newcomer anyway, because the answer is simply "the designers of the language decided to do it that way". They could have decided to make it work another way, but they didn't. it has the advantage that for any given public class, it's very easy to identify which file it's in.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: public class in a file question .
 
Similar Threads
Two public classes in a file
Why one public class
Query -> inheritance
URGENT
Code problem or logic problem ?