โ— Shell
clean mode source โ†—

Single-file execution

Code Comparison

$ javac HelloWorld.java
$ java HelloWorld
// Two steps every time
$ java HelloWorld.java
// Compiles and runs in one step
// Also works with shebangs:
#!/usr/bin/java --source 25

Why the modern way wins

โšก

One command

java File.java compiles and runs in one step.

๐Ÿ“

Script-like

Add a shebang line to make .java files executable scripts.

๐ŸŽ“

Learning-friendly

Newcomers run code immediately without learning build tools.

Old Approach

Two-Step Compile

Modern Approach

Direct Launch

JDK Support

Single-file execution

Available

Widely available since JDK 11 (Sept 2018)

How it works

The Java launcher can compile and run a single source file in one command. Combined with shebang support on Unix, Java files can work as scripts. No separate compilation step needed.

Related Documentation