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
shapes/Geometry.java is in the folder shapes, so it declares package shapes;.
- Every
.javafile of the project is compiled together on each run. - A file in the folder
app/declarespackage app;. An entry there (app/Main.java) runs asapp.Main. - The whole Java standard library is available. Maven/Gradle dependencies and jars are not: nothing is downloaded.