How code runs
On this page 8 topics
Overview
Topics
- Source code, compilation, bytecode, execution, runtime errors
- Java compiler, JVM, JRE, JDK
Learn first
57 min of reading · 1.5 h of practice (estimate)
Learning outcomes
- Explain the difference between source code, bytecode, and machine code.
- Distinguish JDK, JRE, and JVM and say which one a developer needs.
- Compile a
.javafile withjavacand run the resulting class withjavafrom the terminal. - Distinguish a compile-time error from a runtime error, given an example of each.
Lessons
Lab and exercises
Lab
BEG-007-LAB1 · Hello from the terminal
Outcomes: 1–4 · Time: ~1.5 h
- Type the provided Hello program, compile it with
javac, and run it withjava. - Look at the generated
.classfile. - Introduce a syntax error and record the compile-time message.
- Introduce a division-by-zero error and record the runtime message.
- Run the same program in IntelliJ.
Acceptance: both messages captured and each classified correctly.
Exercises
| ID | Outcome | Task |
|---|---|---|
| BEG-007-EX01 | 1 | Put in order: machine code, source code, bytecode. |
| BEG-007-EX02 | 1 | Why can the same .class file run on Windows and Linux? |
| BEG-007-EX03 | 2 | Draw JDK, JRE, and JVM as nested boxes. |
| BEG-007-EX04 | 2 | Which one do you install to write Java, and why? |
| BEG-007-EX05 | 3 | Compile and run a program from the terminal; list the two commands. |
| BEG-007-EX06 | 3 | java Hello.class fails. Why, and what is the fix? |
| BEG-007-EX07 | 4 | Classify: a missing semicolon; dividing by zero; a typo in a variable name. |
Show solutions
- EX01 Source code → bytecode → machine code.
- EX02 Each OS has a JVM that runs the same bytecode.
- EX03 JVM inside JRE inside JDK.
- EX04 The JDK, because it includes the compiler.
- EX05
javac Hello.javathenjava Hello. - EX06
javaexpects the class name, not the file name. Usejava Hello. - EX07 Compile-time; runtime; compile-time.
Quiz
Outcomes: O1 source/bytecode/machine code · O2 JDK/JRE/JVM · O3 compile and run · O4 error kinds.
A self-check for you: nothing is graded, saved or sent anywhere. Choose an answer, then check it. You can try again as often as you like.
Practical part
Explain the compile/run pipeline aloud while demonstrating it: write, javac, show .class, java. Pass: all four steps and the name of each file involved.
Common mistakes
Class name not matching file name; running java Hello.class; confusing "it compiled" with "it works".
Assessment
Explain the compile/run pipeline aloud while demonstrating it.
Career relevance
Basis for build tools (BEG-054) and JVM internals (MID-001).