Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why File Name as same name as public class Name.

 
sudharsan reddy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers,

Why file name and public class name are same.
please explain the reason.


Thanks in Advance
 
Wendy Gibbons
Bartender
Posts: 1110
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i may be wrong but i believe this is just an eclipse thing, i don't think it is java.
 
sudharsan reddy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its not problem with eclipse.
its JSL specification.

but JSL didn't specify the exact reason
 
Matteo Di Furia
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I may be wrong, but could have something to do with classloaders. If the program needs the specification/implementation of class X, where should it look for if not in file name X.class ? Should the JVM look in *every* .class file to find it ?
 
V Vijay Veeraraghavan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
-----------------
it is easy for the class loader to load and initialize the particular class. as the classname and filename is same the job becomes easier. also it help the compiler too in the same way...
-----------------
vijay
[ October 22, 2008: Message edited by: V Vijay Veeraraghavan ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It has nothing to do with class loading, since *.java files don't contain loadable classes!

It has everything to do with making the command-line compiler's life easier. If class A refers to class B, and class B is stored in a file named B.java, then when A is being compiled, the compiler can find the source for class B automatically. If it were stored in a file by any other name, then the compiler would have to search every *.java file it could find, which is obviously not so efficient.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic