For a Java VM, class files are the only way to deliver executable Java code and Java libraries are just variations of containers containing class files.
When Java was created, there was a direct mapping of source level Java classes and class files, so the only way to generate such a class file containing executable code, was to declare a class.
Nowadays, the relation is not so strict, there are non-class artifacts of the Java language which could lead to the generation of a class file, e.g. package annotations or module declarations, further, classes may get generated by the runtime, like for lambda expressions.
So, in principle, there could be a new language construct to allow to define a stand-alone main
method without a class declaration, which gets compiled to a class file behind the scenes. But since a typical application has only one entry point (and without a named hosting class, the possibility to define more than one would be gone anyway), it would not justify creating a new language construct.