IntelliJ IDEA
 
Get IntelliJ IDEA

Run shebang scripts

Last modified: 11 November 2024

Starting with version 11, Java provides a way to run self-contained scripts without the need to compile them (https://openjdk.java.net/jeps/330). Furthermore, on Linux and macOS, you can create scripts in Java by specifying the JDK in the first line of the file.

This is called the shebang mechanism. Shebang support in Java comes in handy when you need to write an executable script, but you don't want to install a compiler or use a scripting language like bash.