Technically class name and file name must only be identical if the class is public accessible.
The JVM looks for the filename in the file system to run it. If the (public) class name is different from the file name, the JVM cannot find it.
If it wasn't like that JVM would need some kind of map/dictionary to link a class identifier to it's corresponding file to be able to call it. That would decrease performance.
It is not compulsory to give same name as class name. when we compiled the code then .class file is generated and jvm run that .class file instead of running our file. *so u can compile your file with any name but when u running your file then u need to write .class file name*