• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Why File Name as same name as public class Name.

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ranchers,

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


Thanks in Advance
 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
its not problem with eclipse.
its JSL specification.

but JSL didn't specify the exact reason
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic