CoursesJVM internals for Kotlin and Android developers
Puzzle 0 · 1 of 5
Which program did you actually run?
Follow a source edit into the file the runtime reads.
All puzzles in this course
The problem
A class file stores a compiled type and its instructions. You change a constant from one to two. The next run still prints the old answer. Which file did that run consume?
See it
Scroll sideways to see the full diagram.
The source adds one.
Step 1 of 4The compiler translates the method.
Step 2 of 4The class file contains the translated method.
Step 3 of 4The launcher loads the class from out.
Step 4 of 4
The building block
A source file is the text you edit. The Java compiler reads that text and writes a class file containing instructions. The Java Virtual Machine (JVM) can execute those instructions. In this exercise the launcher looks for Bookmark in a directory named out. Separate the two operations on paper. Under compile, write the input and output filenames. Under launch, write the name of the program and the directory searched for its classes.
javac -d out Bookmark.java
java -cp out Bookmark
javap -classpath out -c Bookmark
The first command places the compiled classes in the directory named out. The second looks there for Bookmark and starts its main method. The third prints a readable listing of the instructions in the class. Find the helper named increment. You can inspect a compiled class even if the editor currently shows different source.
| Action | Addition in the editor | Addition in out | First printed line |
|---|---|---|---|
| Compile and launch the original | add one | add one | 7 8 |
| Edit only, then launch the existing class | add two | add one | 7 8 |
| Compile the edit into out and launch again | add two | add two | 7 9 |
Imagine you compile the fix into another directory called next, then launch using the same command as before. The build succeeds. The result still comes from out. To investigate a stale deployment, identify the artifact the launcher selected and inspect that artifact's instructions. A screenshot of the corrected source cannot establish what ran.
Try it
Optional local lab
Complete experiment 1 in the JVM source files. Record your prediction before running the program.
Check yourself
Sources
- Java 21 compiler guide — “compiles them into class files”
- Java 21 launcher guide
What you now know
The compiler writes instructions into a class file. Running an existing class reads that earlier output.
Answer every question above correctly to unlock the next puzzle.
Something wrong or unclear on this page? Tell me: a puzzle that didn't click is a bug in the puzzle.