Skip to content
Ameen Abozaid
BEG-007

How code runs

  • 5 Lessons
  • 57 min of reading
  • 1.5 h practice (estimate)
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

  1. Explain the difference between source code, bytecode, and machine code.
  2. Distinguish JDK, JRE, and JVM and say which one a developer needs.
  3. Compile a .java file with javac and run the resulting class with java from the terminal.
  4. Distinguish a compile-time error from a runtime error, given an example of each.

Lessons

  1. 01From text to execution: compilers and interpreters12 min read
  2. 02Java's approach: bytecode and the JVM11 min read
  3. 03JDK vs JRE vs JVM10 min read
  4. 04Compile and run from the terminal12 min read
  5. 05Demo: compile, run, break, and fix Hello World in the terminal12 min read

Lab and exercises

Lab

BEG-007-LAB1 · Hello from the terminal

Outcomes: 1–4 · Time: ~1.5 h

  1. Type the provided Hello program, compile it with javac, and run it with java.
  2. Look at the generated .class file.
  3. Introduce a syntax error and record the compile-time message.
  4. Introduce a division-by-zero error and record the runtime message.
  5. Run the same program in IntelliJ.

Acceptance: both messages captured and each classified correctly.

Exercises

IDOutcomeTask
BEG-007-EX011Put in order: machine code, source code, bytecode.
BEG-007-EX021Why can the same .class file run on Windows and Linux?
BEG-007-EX032Draw JDK, JRE, and JVM as nested boxes.
BEG-007-EX042Which one do you install to write Java, and why?
BEG-007-EX053Compile and run a program from the terminal; list the two commands.
BEG-007-EX063java Hello.class fails. Why, and what is the fix?
BEG-007-EX074Classify: 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.java then java Hello.
  • EX06 java expects the class name, not the file name. Use java 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.

  1. 1The CPU directly runs:O1
  2. 2javac turns .java into:O1
  3. 3A compiler translates:O1
  4. 4Which runs bytecode?O2
  5. 5Which includes the compiler?O2
  6. 6A developer should install the:O2
  7. 7To run class Hello you type:O3
  8. 8javac Hello.java requires:O3
  9. 9A missing semicolon is a:O4
  10. 10Dividing by zero while running is a:O4

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).

Type to search levels, phases, modules and lessons.