Chapter 5 · Simulation

Java Compile and Run

← Chapter 5
Source code
    }
}
.class · bytecode
Terminal

Java Compile and Run

Goal: Follow the journey of a Java program step by step: source code (.java) → the javac compiler → bytecode (.class) → the JVM via the java command → console output. Learn to tell the kinds of errors apart (compile-time, run-time, logic).

How to use it

  1. Pick a ready-made program on the left. The body of main (the dashed area) and the file name are editable; ↺ Original code undoes your changes.
  2. Step ▶ starts the pipeline: the file is saved and javac runs. If there is an error, the terminal shows a message in the real javac format (file:line, description, ^ marker) and no .class is produced. If there is no error, the bytecode list appears; with the java command the JVM runs each statement, the matching bytecode instructions are highlighted, and the output is written to the terminal.
  3. ⇥ ↵ show makes tab and line-break characters visible (\t, \n, the println difference).
  4. Try it yourself: before compiling, predict the program's outcome (compile-time error / run-time error / logic error / no error) and the output of each print statement.

Limits

This is not a real compiler; it recognizes a small subset: one statement per line; System.out.println(…), System.out.print(…), int/String variable declarations and assignments; + - * / %, parentheses, and the escape sequences \n \t \" \' \\. The error messages and bytecode were verified against the output of JDK 21 javac/javap/java. On a line outside the subset the simulator shows a warning. The bytecode list is simplified (constant pool numbers are not shown).

Related slides: Chapter 5 · Getting Started with Java.