With JEP 477, we're finally getting a shorter println method!
void main() { println("Hello, World!");
}
Checkout A N M Bazlur Rahman's latest infoQ item:
- Implicitly declared classes: Eliminates the need for explicit class declarations.
- Instance main methods: main methods can be instance methods and don’t need to be static or public.
The classic “Hello, World!” program can now be written more simply as:
void main() { println("Hello, World!");
}
or even using a field:
String greeting = "Hello, World!";
void main() {
System.out.println(greeting);
}
The JEP also introduces automatic imports from java.base module, reducing the need for explicit import statements. This is part of the ongoing effort to make Java more accessible and maintain its robustness for complex applications. The features are available in JDK 23 with the --enable-preview flag. The proposal is a continuation of the work from previous JEPs and is based on community feedback. It’s designed to help new programmers start with simpler code and gradually learn more complex features.