How JEP 445 Simplifies Java’s Hello World for Beginners

JEP 445 proposes flexible main methods and anonymous main classes to lower Java’s entry barrier, allowing non‑public or non‑static mains, omitting String[] args, and simplifying the classic Hello World example, with usage instructions for JDK 21 preview mode.

Programmer DD
Programmer DD
Programmer DD
How JEP 445 Simplifies Java’s Hello World for Beginners

OpenJDK JEP 445 aims to simplify Java’s entry point by introducing flexible main methods and anonymous main classes, making the language more approachable for students and beginners.

The proposal’s author, Ron Pressler, notes that while Java excels at building large, complex applications, its traditional "Hello, World!" program is overly complicated for newcomers, requiring class declarations, public and static modifiers, and a String[] args parameter.

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

This code includes concepts such as class visibility, static context, and command‑line arguments that are unnecessary for a simple introductory example.

The proposal enhances the Java startup protocol with three key changes:

Allow the main method of the launched class to have public, protected, or package (default) access.

If a class lacks a static main method with a String[] parameter but provides a static main method without parameters, that method will be invoked.

If a class has no static main method but possesses a non‑private zero‑argument constructor and a non‑private instance main method, the class is instantiated and the appropriate main method is called, preferring one with a String[] parameter if present.

These changes permit omission of the String[] args parameter and allow main methods that are neither public nor static, enabling a much simpler "Hello, World!" program:

void main() {
    System.out.println("Hello, World!");
}

The proposal also introduces an anonymous Main class to implicitly declare the class, further reducing boilerplate:

void main() {
    // code here
}

This feature is a preview language feature and is disabled by default. To try it in JDK 21, enable preview mode when compiling and running:

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

For more details, see the full proposal at https://openjdk.org/jeps/445 .

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Javaanonymous classJEP 445beginner programmingflexible main
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

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.