Possible Duplicate:
Can I compile a java file with a different name than the class?
Why must a file contain only a single, same-named Java class? Is there any way around this limitation?
Possible Duplicate:
Can I compile a java file with a different name than the class?
Why must a file contain only a single, same-named Java class? Is there any way around this limitation?
Only name of public
classes must be equivalent to the file name. And why do you want to break this?
That's because the normal ClassLoader (URLClassLoader
) uses the class (and package) name to find and load a class from the filesystem, a JAR file or a webserver (in the case of applets or Java WebStart).
In order to get around this, you would have to implement your own ClassLoader (not particularly difficult), and if you also want class names to be independant from source files, you're have implement/modify the compiler (probably a lot more difficult).
Java is just a broken language, you just have to accept that file name and path names have to match the class names.
No -- you do not want to break it.