Generally the file name and the class name must be same. Then again if they are different, even then you can compile your code.
javac filename.java
java classname
Hope this helps!
Check out Java certification course to become certified expert.
Thanks!