Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.
It is not mandatory to make the file name and class name same but if you make it then it will increase the readability of the code.
I was about to say, that it is simply a must. But I looked at the JLS, and it is not that strict. From the JLS's perspective, it is left to the compiler to choose whether to set such a restriction or not.
Practically spoken - common compilers do have that restriction, it's much easier for the compiler to find a compilation unit or for a classloader to find a class file with such a restriction in place.
Hello JayaKumar,I think this is simply a convention which helps JVM to find the Source Files.This restriction is not by Java Language Specification, its compiler's duty to handle souce code in files. common compilers do have that restriction, it's much easier for the compiler to find a compilation unit or for a classloader to find a class file with such a restriction in place.