Implicit classes and instance main (3rd preview)
Delete the ceremony from a beginner's first program without changing the language underneath.
Open this lesson in the learning hubKey points
- A first Java program forces a beginner to meet
public,static,void,String[]before printing anything. - An implicit class lets a file with no class declaration hold methods directly.
- The main method can be an instance method, and can take no arguments at all.
- The compiler still creates a real class - this is syntax, not a new runtime model.
- By its third preview here it was clearly heading for final, which it reached in Java 25.
Example
// Java 23 preview (JEP 477) - the whole file would be:
//
// void main() {
// System.out.println("Hello");
// }
//
// Java 21 needs every word of this before a beginner can print anything:
public class Main {
public static void main(String[] args) {
System.out.println("Hello");
System.out.println("public - why does a beginner need visibility?");
System.out.println("static - why before objects are taught?");
System.out.println("String[] args - never used in lesson one");
}
}
Implicit classes shrink the on-ramp for learners without changing what the JVM runs.
This is a reading copy. The full lesson — with the visual explainer, the interactive lab and a Run button for the code — lives in the Java 23 Course course, and every lesson in it is listed on the Java 23 Course contents page.