adam bien's blog

"hello, world" Java 25 Script In 4 Lines 📎

Java 25 source-file mode turns a single file into an executable command. No compilation, no build tool, no .java extension. Here is how to create a zhello script:

  1. Create a file named zhello (no extension) with the shebang #!/usr/bin/env -S java --source 25
  2. Add an instance void main() method that calls IO.println("hello, world")
  3. Make it executable: chmod +x zhello
  4. Install it system-wide: sudo cp zhello /usr/local/bin/

The entire script:

#!/usr/bin/env -S java --source 25

void main() {
    IO.println("hello, world");
}