This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes java class names Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java class names" Watch "java class names" New topic
Author

java class names

yaswanth yash
Greenhorn

Joined: Apr 18, 2012
Posts: 12
why a java file name and its class names should be same?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4369
    
    8

Because that's how the language was designed.

You'd have to ask the language designers for the real reason, but it's a sensible way of organising your code, and they decided to enforce one approach.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11250
    
  16

If you search through this forum, you will find this has been asked and discussed many times.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7684
    
  19

yaswanth yash wrote:why a java file name and its class names should be same?

Why not? What would you suggest instead?

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Naishadh Parmar
Ranch Hand

Joined: Jun 02, 2011
Posts: 95

You may ask this question to James Gosling, Mike Sheridan and Patrick Naughton this question(designers of this programming language) !!!
Its just a way of organizing and it is actually good so that there is no disconnect between the class name and the file name.
Or else if you wanted to know where an error occured you would have to open all the files see the class names and then identify the problem which would consume a lot of your quality time.
yaswanth yash
Greenhorn

Joined: Apr 18, 2012
Posts: 12
I hope you can guess my suggestion...mr.winston
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61082
    
  66

yaswanth yash wrote:I hope you can guess my suggestion...mr.winston

No we can't. I can think of no better reasonable suggestion.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
jQuery in Action, 2nd edition
 
subject: java class names