Skip to content
AgileLogics
4 min read

How Java Code Runs: Compiling and the JVM

Prerequisites: Your first Java program

Running a Java program is a two-step process — the compiler translates source code into bytecode, and the JVM then runs that bytecode:

javac Main.java   # produces Main.class (bytecode)
java Main         # the JVM loads and runs Main.class

An IDE's "Run" button does both steps for you behind the scenes. The .class file is not tied to any one operating system or processor — only the JVM that runs it needs to match the machine.

Common mistakes

  • Running java Main.java and expecting a compile error to look the same as a runtime error — compile errors (like a missing semicolon) are reported by javac before anything runs at all; runtime errors (exceptions) happen while java is executing the bytecode.