Java Language—Program Structure
Source code of a Java program consists of one or more compilation units, each implemented as a file with extension “.java”.
Each compilation unit can contain:
- a package statement
- import statements
- class declarations and/or interface declarations.
In typical Java development environments, exactly one of the included class (or interface) declarations should be marked public. The file should be named after that class. e.g. if the public class is Foo, the file name should be “Foo.java”.