Stop 01 · Java FoundationsTopics · 6/7

How Java Runs (Bytecode & JIT)

Part of the Java Roadmap

In short

Java starts like an interpreted language and then gets faster the longer it runs. Knowing why helps you understand warm-up time, performance tests and a classic interview question about the JIT.

The compiler produces platform-neutral bytecode, the JVM loads and verifies it, and the JIT compiler turns frequently used code into fast native machine code while the program runs.

The jaadu in a chef's cap reads a recipe card for one pot while stirring three other busy pots without looking.

Think of it like this

The new cook who learns the menu

On day one, a new cook reads every recipe card step by step. By the end of the week, the dal and rice that are ordered fifty times a day are cooked from memory, fast. The JVM first interprets bytecode line by line, then the JIT compiler memorises the busiest methods as fast native code.

Watch it happen

The journey of your code

Source .java
Bytecode .class
Load & verify
Interpret
JIT native code

1/5You write human-readable source code.

The big ideas

What you need to know

Bytecode is portable

The same .class file runs on any JVM. Only the JVM itself is specific to the OS and chip.

Hot code gets compiled

The JIT focuses on methods and loops that run many times. Rarely used code may stay interpreted.

Warm-up

Java programs often get faster after the first few seconds. That is why performance tests use a warm-up phase.

Garbage collector

The JVM also frees memory from objects you no longer use, so you never call free() yourself.

See it in code

Walk through the code

bash
1# Compile, then peek at the bytecode2javac Sum.java3javap -c Sum4 5# Output (simplified)6#   iload_1      // push a7#   iload_2      // push b8#   iadd         // add them9#   ireturn      // return the result10 11# Watch the JIT at work12java -XX:+PrintCompilation Sum

1/3javap -c disassembles Sum.class so you can read its bytecode.

javap shows the bytecode inside a class file. PrintCompilation lists methods as the JIT compiles them.

Save yourself the pain

Common mistakes

Oops

Saying Java is purely interpreted and therefore slow.

Do this instead

Modern JVMs JIT-compile hot code to native machine code. Long-running Java services are very fast.

Oops

Benchmarking by timing a method once with System.currentTimeMillis.

Do this instead

The first runs include warm-up. Use a tool like JMH, which warms up the JIT before measuring.

Your mission

Look under the hood

~15 min

Quick check

What does the JIT compiler do?

Go deeper

  1. 1Use javap -c on a compiled class to peek at its bytecode.
  2. 2Explain why the same .class file runs on Windows, macOS and Linux.
  3. 3Learn why a Java program often gets faster after it has been running for a while (JIT warm-up).

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge