How Java Runtime Executes a Program
If you're here because you're confused whether Java
is a compiled-language
or an interpreted-language
, then you're not alone. Let's understand how execution of a Java program undergoes, then you can decide for yourself.
Unlike your compiled languages like C/C++
, Java functions in a different tone with a behavior analogous to amalgamation of both compilation and interpreted action.
A Java program, with .java
extension is first compiled into a bytecode
i.e. .class
file by the Java compiler.
If we have a Java file named World.java
, to compile it into a bytecode:
javac World.java
Now, we get a class file; World.class
and to execute the program, we simply:
java World
Here, the java
command starts the Java runtime environment and it can either compile or interpret the bytecode using the Java Interpreter or JIT (Just-In-Time) compiler.
The bytecode can be executed in multiple ways:
1. Java Interpreter
Java interpreter executes each bytecode instruction line by line as like any other interpreters, so the process is a bit gradual.
2. JIT Compilation
In order to overcome the performance limitations, we look for the frequently appearing code-blocks (often called hotspots
) and compile those bytecode directly to machine code for slight performance gain.
3. Ahead of Time Compilation
Instead of waiting till runtime, AOT shines by directly compiling the bytecode into the native machine code at build time. This significantly increases the performance of our application.
Remember these are the execution part of the Java Virtual Machine (JVM), the following flowchart best describes the overall process.

Shoutout to user displayName
from @StackOverflow for this brilliant visualization.