Fundamentals 5 min read

Simplifying Java Entry Point with JEP 445: Flexible Main Method and Anonymous Main Class

OpenJDK's JEP 445 introduces a flexible main method and anonymous main classes to reduce boilerplate, making Java's entry point simpler and more beginner‑friendly while preserving full language capabilities for advanced development.

IT Services Circle
IT Services Circle
IT Services Circle
Simplifying Java Entry Point with JEP 445: Flexible Main Method and Anonymous Main Class

OpenJDK JEP 445 proposes to simplify the Java entry point by introducing a flexible main method and anonymous main classes, aiming to make the language more approachable for beginners.

The traditional Hello, World program requires a public class, a public static main method with a String[] args parameter, and several modifiers that are unnecessary for simple scripts.

public static void main(String[] args) {
    System.out.println("Hello, World!");
}

Ron Pressler argues that this boilerplate is too complex for novices, pointing out that class declarations, access modifiers, and unused parameters add confusion.

The proposal enhances the launch protocol in three ways:

Allow the main method to have public , protected , or package access.

If a static main without String[] exists, invoke it.

If no static main exists, but the class has a non‑private zero‑argument constructor and an instance main , instantiate the class and call the instance main , preferring the version with String[] if present.

Consequently, the String[] args parameter and the public / static modifiers can be omitted, allowing a minimal hello world:

void main()

An anonymous main class can also be used to implicitly declare the class:

void main()

To try the preview feature in JDK 21, compile and run with the following commands:

javac --release 21 --enable-preview Main.java
java --enable-preview Main
# or
java --source 21 --enable-preview Main.java

Further details are available in the JEP 445 specification at https://openjdk.org/jeps/445.

JavaMain methodprogramming educationJEP 445preview features
IT Services Circle
Written by

IT Services Circle

Delivering cutting-edge internet insights and practical learning resources. We're a passionate and principled IT media platform.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.