wood burning stoves
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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "public class in a file question ." Watch "public class in a file question ." New topic

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 ???

Rob Spoor

Joined: Oct 27, 2005
Posts: 20184

Please SearchFirst. This question has been asked many, many times before.

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.

Matthew Brown

Joined: Apr 06, 2010
Posts: 4541

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.
I agree. Here's the link: http://aspose.com/file-tools
subject: public class in a file question .
It's not a secret anymore!