Compile & Run in Java

From the Java cheat sheet · Getting Started · verified Jul 2026

Compile & Run

Compile to bytecode, run, or launch a single file directly.

java
// Quick Reference
javac Main.java   // compile -> Main.class
java Main         // run the class (no .class extension)
java Main.java    // compile + run a single file in one step
💡 java Main runs a compiled class; java Main.java compiles and runs in one shot.
⚡ jshell is a built-in REPL for testing snippets without a full program.
📌 Bytecode (.class) runs on any JVM - "write once, run anywhere".
🟢 Use Javadoc /** */ comments to document public APIs for tooling.
clicompile

Continue with Java

Save the full cheat sheet or work through every related task.

More Java tasks

Back to the full Java cheat sheet