Two steps: compile, then run
A computer can't understand Java directly. So Java works in two steps:
- Compile – a tool called the compiler (
javac) checks your code for mistakes and turns it into bytecode, a simpler form of the instructions. - Run – the JVM (Java Virtual Machine) reads the bytecode and actually does what it says.
Think of it like this: The compiler is like a teacher who checks your homework for spelling mistakes before you hand it in. The JVM is like a translator who then reads your homework out loud in the computer's own language.
Write once, run anywhere
Windows, Mac, Linux and Android all have their own JVM. Because the bytecode is the same everywhere, the same Java program runs on all of them. This is Java's famous motto: “Write once, run anywhere.”
The words you will hear
| Word | Meaning |
|---|---|
| Source code | The Java text you write, saved in a file ending in .java |
Compiler (javac) | Checks your code and turns it into bytecode |
| Bytecode | The compiled program, saved in a .class file |
| JVM | The program that runs the bytecode |
| JDK | Java Development Kit: the compiler + JVM + tools you install to write Java |
Two kinds of errors
- Compile errors – found by the compiler before the program runs, like a missing
;. - Runtime errors – happen while the program is running, like dividing a number by zero.
Tip: In this course you don't need to install anything: the challenge pages have a compiler and a JVM that run inside your web browser. When you want to write Java on your own computer, install a JDK (for example from adoptium.net) and an editor such as IntelliJ IDEA or VS Code.