Packages and several files

One public class per file, folders as packages, and import between them.

Runs in Zerethon IDE · Java 25 Official Java documentation ↗
Main.java
import shapes.Geometry;

public class Main {
    public static void main(String[] args) {
        System.out.println(Geometry.area(3, 4));
    }
}
shapes/Geometry.java
package shapes;

public class Geometry {
    public static int area(int width, int height) {
        return width * height;
    }
}

Output

12
The file shapes/Geometry.java is in the folder shapes, so it declares package shapes;.
  • Every .java file of the project is compiled together on each run.
  • A file in the folder app/ declares package app;. An entry there (app/Main.java) runs as app.Main.
  • The whole Java standard library is available. Maven/Gradle dependencies and jars are not: nothing is downloaded.