Regards, Suhas S. Mandrawadkar.
Certifications: SCJP 6, SCWCD 5, Oracle WebLogic Server Administrator, OCE Java EE 6 EJB Developer
Suhas Mandrawadkar wrote:Hi Mayuresh,
According to my understanding, this rule is not applied when there is no public class in the source code file. But when there is a public class, there can be only one Public class in the source code file and the file name must match the class name in that case.
I guess thats done to let JVM know about our public class and hence the entry point.
Campbell Ritchie wrote:Welcome to the Ranch
CapitalLettersForClassNames, please.
It is a requirement for most compilers that the name of a public top-level class match the file name. It makes for faster compilation of the compiler does not have to "search" every file in the directory to find a particular class.
Regards, Suhas S. Mandrawadkar.
Certifications: SCJP 6, SCWCD 5, Oracle WebLogic Server Administrator, OCE Java EE 6 EJB Developer
Have you tried it?Mayuresh Rahate wrote:... i just want to know that what will happen if i wrote class name different and file name different....
Campbell Ritchie wrote:Welcome to the Ranch
CapitalLettersForClassNames, please.
It is a requirement for most compilers that the name of a public top-level class match the file name. It makes for faster compilation of the compiler does not have to "search" every file in the directory to find a particular class.
Campbell Ritchie wrote:Welcome to the Ranch
CapitalLettersForClassNames, please.
It is a requirement for most compilers that the name of a public top-level class match the file name. It makes for faster compilation of the compiler does not have to "search" every file in the directory to find a particular class.
When packages are stored in a file system (�7.2.1), the host system may choose to enforce the restriction that it is a compile-time error if a type is not found in a file under a name composed of the type name plus an extension (such as .java or .jav) if either of the following is true:
* The type is referred to by code in other compilation units of the package in which the type is declared.
* The type is declared public (and therefore is potentially accessible from code in other packages).
This restriction implies that there must be at most one such type per compilation unit. This restriction makes it easy for a compiler for the Java programming language or an implementation of the Java virtual machine to find a named class within a package; for example, the source code for a public type wet.sprocket.Toad would be found in a file Toad.java in the directory wet/sprocket, and the corresponding object code would be found in the file Toad.class in the same directory.
Don't play dumb with me! But you can try this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|