• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why to save same name as class

 
pradipta kumar rout
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic