"A Java file without any class or interface definitions can also be compiled."
From JLS 7.3:
CompilationUnit:
PackageDeclaration(opt) ImportDeclarations(opt) TypeDeclarations(opt)
As above, since all the parts of a CompilationUnit in Java is optional, I think it is right to say so. Actually, JDK1.4.1 does treat an empty file as a valid compilation
unit. You can even write like this:
It's also a valid compilation unit according to the definition.
"If an import statement is present, it must appear before any class or interface definitions."
Yes. you can see from the above definition that ImportDeclarations must appear before TypeDeclarations.