Java 25 (LTS) · Topic 4 of 4
Compact source files and instance main
Definition​
Compact source files (Java 25) let a small program be just a void main() method, with no class declaration and no public static. It removes the ceremony from a first program or a script.
Example code​
A whole program with no class around it
// file: Demo.java (no class, no "public static", no String[] args)
void main() {
String name = "Java 25";
System.out.println("Hello from " + name);
}
// Output:
// Hello from Java 25
Finished this page? Track your progress (saved only in your browser).