4 ms·
Java SE 11 (Sep 2018) introduced the ability to run source files directly. So instead of the old `javac Main.java && java Main`, you can do `java Main.java`. ht
by nayuki 1y ago
Java SE 11 (Sep 2018) introduced the ability to run source files directly. So instead of the old `javac Main.java && java Main`, you can do `java Main.java`. https://openjdk.org/projects/jdk/11/ https://openjdk.org/projects/jdk/11/ , https://openjdk.org/jeps/330 https://openjdk.org/jeps/330
- rpozarickij 1y agoFurthermore, there's ongoing work ([0] and related JEPs) to allow running single Java files without an enclosing class and the static main method: void main() { System.out.println("Hello, World!"); } This is currently (as of JDK 24) under preview, so such a file needs to be run with "--enable-preview". E.g. $ java --enable-preview HelloWorld.java Hello, World! [0] https://openjdk.org/jeps/445 https://openjdk.org/jeps/445
- msgilligan 1y agoWith the latest EA release (EA 24) of JDK 25 [1], you no longer need the `--enable-preview`. You can also simplify the println to: void main() { IO.println("Hello, World!"); } JEP 445 has been followed by JEP 512 which contained minor improvements and finalizes the feature [2]. If you want to use 3rd-party libraries, I highly recommend trying JBang [3]. [1] https://jdk.java.net/25/release-notes https://jdk.java.net/25/release-notes [2] https://openjdk.org/jeps/512 https://openjdk.org/jeps/512 [3] https://www.jbang.dev https://www.jbang.dev
- ptx 1y agoHmmm... Disappointing that the static methods are no longer imported as of JEP 512. I thought that was the whole point of the new IO class. If we can't write "println" we might as well just write "System.out.println".