Java follows a unique execution model where source code is first compiled into bytecode and then executed by the Java Virtual Machine (JVM). This design makes Java platform-independent and highly portable.
When a Java program is compiled using javac, it does not produce machine-specific code. Instead, it generates bytecode, which is an intermediate, platform-neutral format. The JVM then interprets or compiles this bytecode into native machine instructions.
// Simple Java program to demonstrate bytecode generation
class HelloJVM {
public static void main(String[] args) {
System.out.println("Hello JVM");
}
}
The javac HelloJVM.java command converts the source file into HelloJVM.class containing bytecode. The JVM loads this bytecode, verifies it, and executes it line by line or via JIT compilation.
Click the buttons below to visualize how code travels through the system.
// JVM execution flow overview
Source Code (.java)
↓
Compiler (javac)
↓
Bytecode (.class)
↓
Class Loader
↓
Bytecode Verifier
↓
Interpreter / JIT
↓
Native Machine Code
javac.javap -c to inspect generated bytecode.