java
command, eliminating the need for explicit compilation, ideal for quick testing or scripting in Java.Before Java 11:
Traditionally, running some Java source code involved multiple steps:
javac FooBar.java
, producing a .class
file containing the bytecode.java FooBar
.After Java 11:
You can now run a single Java file directly without explicit compilation:
args
parameter in the main
-method), and if so greets all the given arguments with the current date, otherwise just uses “world” as a default.public class SingleFileDemo { public static void main(String[] args) { if(args != null && args.length > 0) { for (String arg : args) { greet(arg); } } else { greet("world"); } } private static void greet(String name) { LocalDate today = LocalDate.now(); System.out.printf("Hello, %s! Today is %s %s!\n", name , today.getDayOfWeek(), today.format(DateTimeFormatter.ofPattern("d MMMM yyyy"))); } }
java
command, eliminating the need for explicit compilation. This feature enhances the ease of testing and scripting.