I read it is mandatory to have the same name for the public class as the source filename for the program to compile. I also read it somewhere that it is a compiler constraint to have the same name at both the places. Could someone please give me an insight into it. Why exactly same name is needed, is it tht the compiler searches for a class with the same name for the starting point of the file?
As the file must have the same name as the public class contained in it, it's impossible to have more than one public class in a file. If you put only non-public classes in a file there's no restrictions to filenaming.
It is a good practice to not have more than one class per file though (not counting inner classes) and to always give the file the name of the class. Makes it so much easier to find the right files when you need to change a class
It's a requirement laid down in the JLS and/or JVMS. Those form the bible which determine the behaviour of the JVM and compiler. As gospel they don't have to be logical or reasonable (though by and large they are) and no explanation of their reasoning need be given.