Skip to the workspace
Pebellslearn by building
Java Basics  ›  Lesson

From Source File to Running Program

Lifecycle of a Program 12 minJava source is compiled by javac into platform-neutral bytecode, which the Java Virtual Machine loads, verifies and runs.

Set up Java and run your first file

Install a JDK (Java Development Kit), which includes both a compiler and the Java runtime. Compile a source file, then run the resulting class.

Already set up? Continue to the lesson

New to coding? Meet the tools and find the terminal
JDK
Development tools including javac and the Java runtime. A runtime-only download is insufficient for compilation.
javac
Compiles a .java file to .class bytecode.
Java Virtual Machine
Runs the compiled bytecode on your operating system.

A terminal is a window for commands. Its shell interprets those commands. PATH is the list of folders the shell searches for programs. An editor extension adds editing help; it usually does not install the language itself.

In VS Code, open your project folder, then choose View → Terminal. Type at the cursor in the Terminal panel, not in Output, the source file, or the browser address bar. Our command blocks omit prompt symbols such as $ and >; do not add them.

Official VS Code screenshot: the Terminal tab is selected below the editor, with the PowerShell shell name at the right and a command prompt at the left.
Find the Terminal tab and shell name. Open full-size screenshot (new tab).

The dropdown next to the plus button selects a shell. Choose the shell named in your operating-system instructions below. Available choices depend on what you installed.

Official VS Code screenshot: the arrow beside the terminal plus button opens a list containing PowerShell, Command Prompt, Git Bash and Ubuntu WSL.
Official documentation screenshots by Microsoft, VS Code terminal guide, CC BY 3.0 US. Unmodified; your version may look different.

Choose a system to see its installation steps. A computer is needed for these local setup instructions.

Official documentation and illustrated guides

Instructions reviewed 2026-10-27. Use the linked installer page for current versions and supported operating systems.

Continue to the lesson

java / From Source File to Running Program

Explore each scene at your own pace.

01 · The rule

The rule

From Source File to Running Program

Java source is compiled by javac into platform-neutral bytecode, which the Java Virtual Machine loads, verifies and runs.

Trace a source file through javac, bytecode and the JVM.

Brew Bar, a small café, wants a program that takes coffee orders. Before we write a single line of it, it helps to know what happens between typing Java and seeing it run. Most confusing beginner errors make sense once you know which stage raised them.

The rule

You write source, javac makes bytecode, and the JVM runs it.

A Java program passes through three stages.

  1. Source. You write human-readable code in a file ending in .java, such as Cafe.java.
  2. Compile. The compiler, javac, checks the whole file for grammar and type mistakes. If it finds none, it writes Cafe.class. That file holds bytecode: compact instructions for an imaginary machine, not for your real processor.
  3. Run. The command java Cafe starts the Java Virtual Machine (JVM). The JVM loads the class, checks that the bytecode is safe, and executes it.
javac Cafe.java     # creates Cafe.class
java Cafe           # the JVM runs the bytecode

For a quick experiment, modern Java also accepts java Cafe.java. It compiles in memory and runs straight away, without leaving a .class file behind. It is the same pipeline, only shorter to type.

Because bytecode targets the JVM rather than a particular chip, the same Cafe.class runs on Windows, macOS or Linux, as long as a JVM is installed. The JVM starts by interpreting bytecode. When it notices a method running again and again, its JIT (just-in-time) compiler translates that method into native machine code, which is why long-running Java programs get faster after a warm-up.

You install all of this as the JDK (Java Development Kit), which contains javac, the JVM and the standard library.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.