When a classfile that belongs to a package, then

package PackageName;

is included in the source code of that file. So when jvm is invoked by writing

java PackageName.classfilename

it gets executed.

Is it that "package PackageName" guarantees the jvm that this classfile belongs to this very package? Because if we omit the "package PackageName" statement, then jvm still finds out the class file but gives

Exception in thread "main" java.lang.NoClassDefFoundError: Classfilename
wrongname PackageName/ClassfileName
It means jvm finds out the file but there is some reason for which it considers that this classfile has a wrong name.