Bloom
Java Basics, day by day

Day 1 of 22 · ~10 min

What Java is, and your first program

Objective. Explain how Java runs, then write, compile, and run a program.

Why this matters. Everything you build rests on one loop: you write human-readable code, and Java turns it into something that runs anywhere. Get the loop working once and every later lesson fills it in.

How Java actually runs

Java is built around one promise: write once, run anywhere. You write .java source files in plain text. The compiler javac turns them into bytecode (.class files) — not machine code for your specific computer, but instructions for the JVM (Java Virtual Machine). A JVM exists for Windows, macOS, and Linux, and each one runs that same bytecode.

So the loop is: write → compile → run.

The write-compile-run loop: one source file, one bytecode file, any machine.

Your first program

Create a file named Hello.java:

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello, Java!");
    }
}

Reading it line by line:

Compile and run from a terminal in that folder:

javac Hello.java
java Hello
Output
Hello, Java!

Note it is java Hello, not java Hello.class — you name the class, not the file.

A class file is a recipe card and the JVM is the cook. You hand over the recipe's name, not the card's filename.

One modern aside: for a single file, java Hello.java also works — the JVM compiles it in memory. We teach the two-step loop because every real project uses it.

Try it

Check yourself

  1. 1. What does javac produce, and what actually runs that output?

  2. 2. Why must this file be named Hello.java?

  3. 3. Predict the problem: you run java Hello.class and get an error. Why, and what is the correct command?

My notes

Yours alone, kept in this browser.