This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Why File Name as same name as public class Name. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why File Name as same name as public class Name." Watch "Why File Name as same name as public class Name." New topic
Author

Why File Name as same name as public class Name.

sudharsan reddy
Greenhorn

Joined: Oct 22, 2008
Posts: 5
Hello Ranchers,

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


Thanks in Advance
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

i may be wrong but i believe this is just an eclipse thing, i don't think it is java.
sudharsan reddy
Greenhorn

Joined: Oct 22, 2008
Posts: 5
its not problem with eclipse.
its JSL specification.

but JSL didn't specify the exact reason
Matteo Di Furia
Ranch Hand

Joined: Jun 20, 2008
Posts: 102
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

Joined: Apr 06, 2008
Posts: 21
-----------------
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why File Name as same name as public class Name.
 
Similar Threads
public class
file name same as public class?
A very simple question (Please Answer)
why .java filename constraint ?
class name & file name