What happens if you compile an empty java file?

javac starts, sees there is no class declared in the file, and finishes. In order for a .class file to be created you must at least have the class declaration in the file.


What most of the answers are saying is really that a class file is not a compiled java file but a binary representation of a class.

Compiling a java file could result in two class files if the java file contains two classes (although only one can be public) and that is why compiling something with zero classes will result in zero class files.

Tags:

Java