aspose file tools*
The moose likes Java in General and the fly likes why to save same name as class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "why to save same name as class" Watch "why to save same name as class" New topic
Author

why to save same name as class

pradipta kumar rout
Ranch Hand

Joined: Sep 13, 2010
Posts: 43
Sir,

As we know that to save the java file when the class is public ,we have to give the same name to both class and the fie.
but why this is ?

kindly give me some sugesstion .

Thank you
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

The compiler has to have some way to find the .java files it needs to compile, and to link those .java files with the classes which are stored in them and required elsewhere. The makers of Java decided that the way to provide the link between the .java file and the Class name was to force them to be the same,


Steve
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4467
    
    8

Because that's the way the language is designed. It's one of those things that's not worth thinking too much about - the language designers had various decisions to make, and this was what they decided. Why use semi-colons at the end of the line? Because that's how it works.
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

In addition to Matthew's post, it have something to do with abstraction. If we as the Java programmer had to worry about things like likes classes and files having the same name and what symbol to use at the end of the line to terminate a command(";" or "." or " ") programming in Java would be A LOT more complicated. It is abstraction that gives high-level languages the ease of programming we know as Java or PHP or Visual Basic programmers.
[url]
http://en.wikipedia.org/wiki/Abstraction#Abstraction_in_computer_science[/url]

Hunter


"If the facts don't fit the theory, get new facts" --Albert Einstein
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why to save same name as class