From source code to running program¶
☕ Java 17 · How Java Works Under the Hood · 1/3
Three steps, every time¶
Every Java program follows the same journey:
| Step | Tool | Input → output |
|---|---|---|
| 1. Write | your editor | Movie.java — source code, plain text |
| 2. Compile | javac |
Movie.java → Movie.class — bytecode |
| 3. Run | java (the JVM) |
executes Movie.class |
Bytecode is a middle language. It is no longer human-readable source code, but it is not machine code either. The JVM (Java Virtual Machine) turns it into instructions for the machine it runs on.
Write once, run anywhere¶
Bytecode doesn't depend on the operating system. The same Movie.class runs unchanged on Windows, macOS or Linux, as long as a JVM is installed. That's the promise Java made in 1995, and it still holds: you compile once, and the JVM of each machine does the rest.
The tools in the JDK¶
The JDK (Java Development Kit) is the toolbox you install to write Java. Four of its tools come up early:
| Tool | Role | Example |
|---|---|---|
javac |
compiler: .java → .class |
javac Movie.java |
java |
launcher: starts the JVM and runs a class | java Movie |
jar |
packager: bundles .class files into one .jar archive |
jar cf app.jar *.class |
javadoc |
generates HTML documentation from code comments | javadoc Movie.java |
To start, you only need two: javac to compile, java to run. The other tools come in later, when a project grows.
Two details that matter from day one¶
javactakes a file name, with its extension:javac Movie.java.javatakes a class name, without any extension:java Movie, neverjava Movie.class.
Java is also case-sensitive everywhere: Movie, movie and MOVIE are three different names.
Now that the journey is clear, let's look at the JDK itself and which version to install.