3 ms·
You can do this in Java 21, create this small Java file and run it immediately: class HelloWorld { public static void main(String[] args) {
by newsoftheday 10mo ago
You can do this in Java 21, create this small Java file and run it immediately:
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
java HelloWorld.java
Include the .java extension, you're running the file directly.
time java HelloWorld.java
Hello, World!
real 0m0.278s
user 0m0.613s
sys 0m0.066s
- oftenwrong 10mo agoYou can do better now: #!/usr/bin/env java --source 25 void main() { IO.println("Hello, World!"); } https://openjdk.org/jeps/330 https://openjdk.org/jeps/330 https://openjdk.org/jeps/458 https://openjdk.org/jeps/458 https://openjdk.org/jeps/512 https://openjdk.org/jeps/512 I often combine these approaches with https://get-coursier.io/ https://get-coursier.io/ when I need to fetch third-party dependencies.