Here are some simple improvements that Java 25 brings to your everyday code.
Hello World simplified
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}void main() {
IO.println("Hello, World!");
}If I'm counting well, we go down from 89 characters to 40 characters, That's less than half of the code. Additionally the code is more intuitive to understand. This feature is called compact source files. The above improvement usesa launchable main method. The method automatically resides in a top level class in the unnamed packageA new Input/Output class
Less imports
void main() {
List<String> ducklings = List.of("Huey", "Dewey", "Louis");
IO.print("Hello " + ducklings);
}
We're all used to not having to import java.lang.String because Java automatically imports java.lang.*.Java now automatically imports the java.base module.Importing a module implies importing all public top level classes and interfaces in packages exported by that module.The top level packages are defined in the module definitions, which exist since Java 9.One of the packages exported by the java.base is java.util.*. Hence we do not needimport java.util.List;for the code above to run anymore.Additionally a program can now import modules without having to be a module itself, making modules more accessible to developers who never dabbled with them themselves.You import modules (here java.util.desktop) usingimport module java.util.desktop;