Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: DSA in Java
Stage 5: Specialization

Part 01 / Topic 5 of 7

Source → bytecode → JVM

Recap of section 1: Java compiles, then runs. Three things happen between saving your file and seeing output:

Hello.java  ──javac──▶  Hello.class  ──java──▶  JVM runs it
(source)                (bytecode)             (your output)
  1. Compile: javac turns your source code into bytecode — simple instructions for an imaginary computer, not for your actual CPU. Bytecode is saved in a .class file (one per class).
  2. Run: java starts the JVM, which reads the bytecode and either interprets it step by step, or — for code that runs many times — compiles hot parts straight to your CPU's real machine code (the JIT, Just-In-Time compiler) for speed.
  3. Same bytecode everywhere: that .class file runs on any machine with a JVM — Windows, macOS, Linux — unchanged. "Write once, run anywhere" means this one step, not that every Java feature behaves identically everywhere.

This is unlike Python (interpreted, mostly) and unlike C (compiled straight to your CPU's machine code, no portable middle format).

Real-world example: look inside the .class file javac made, with javap (the class file disassembler, also part of the JDK):

$ javap -c Hello.class
Compiled from "Hello.java"
public class Hello {
  public Hello();
    Code:
       0: aload_0
       1: invokespecial #1                  // Method java/lang/Object."<init>":()V
       4: return

  public static void main(java.lang.String[]);
    Code:
       0: getstatic     #7                  // Field java/lang/System.out:Ljava/io/PrintStream;
       3: ldc           #13                 // String Hello, World!
       5: invokevirtual #15                 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
       8: getstatic     #7                  // Field java/lang/System.out:Ljava/io/PrintStream;
      11: ldc           #21                 // String Welcome to Java Step by Step
      13: invokevirtual #15                 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
      16: return
}

You never wrote a constructor, but javac always adds a default one (public Hello();) if you don't. Each System.out.println(...) becomes three steps: get the System.out object (getstatic), load the text constant (ldc), call println on it (invokevirtual). This is the same shape you will see in every Java program you ever write, just repeated more times.

Word Meaning
Source code The .java file you write
Bytecode Low-level instructions javac produces from your source
.class file A file that stores one class's bytecode
JVM The engine that runs bytecode
JIT Part of the JVM that turns hot bytecode into real machine code while running

🔍 Going deeper: javap -c output (opcodes like getstatic, invokevirtual) is a JDK detail, not something the Java language guarantees — it can change between JDK versions, same as CPython's bytecode. You never write or edit it by hand; it exists so tools (and curious learners) can see what javac actually produced.

Done here? The practice set for Part 1 — including the solutions — is on the part page.

Search the guide