"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:
- Create a file named
zhello(no extension) with the shebang#!/usr/bin/env -S java --source 25 - Add an instance
void main()method that callsIO.println("hello, world") - Make it executable:
chmod +x zhello - 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");
}