Empty file is valid Java source file, but how it is handled inside the JVM?
There is no one-to-one relation between .java-files and .class-files. What you have is a one-to-one relation between classes (or class-declarations) and .class-files.
A Java-source file with zero class-declarations will not result in any .class
files, so it's not really handled by the JVM at all.
$ touch Test.java
$ ls
Test.java
$ javac Test.java
$ ls
Test.java
In the Java Language Specification a Java-source file is synonym with a Compilation Unit. The relevant section in the JLS is 7.3 Compilation Units.
The grammar is described as follows:
CompilationUnit:
PackageDeclarationopt ImportDeclarationsopt TypeDeclarationsopt
...
The opt-subscript says that the part is optional. Since TypeDeclarations is optional, no class-declarations need to exist.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With