Loading published curriculum…

01 · Java foundations / LESSON 1 OF 102

Set up Java and run a program

Understand the runtime before adding a framework.

Before this lesson: No programming experience required. You need a computer and permission to install a JDK.

Understand the topic

Install a Java 21 JDK, Git, and an editor such as IntelliJ IDEA Community or VS Code. Check java -version and javac -version both report 21. The JDK contains development tools; the JVM executes bytecode. This course uses no preview features.

Save the source as Main.java. The public class name matches the filename. Compile with javac Main.java and run with java Main. A package is a namespace that later corresponds to folders below src/main/java.

EXAMPLE · JAVA

Main.java

public class Main {
    public static void main(String[] args) {
        System.out.println("My backend journey starts here.");
    }
}

What to expect

My backend journey starts here.

YOUR TURN

Put it into practice

  1. 01Print your name on a second line.
  2. 02Misspell println, inspect the compiler error, then fix it.
  3. 03Commit the source to Git and ignore *.class.

Pass a quiz or complete a lab to check today’s streak. Each lesson counts once per day, including when you review it later.

UNDER THE HOOD

Build the mental model

Think of the compiler as a translator and the JVM as the machine that follows the translated instructions. Your editor is replaceable; the build and runtime must work outside it.

  1. 01javac resolves names and checks types before producing bytecode. A syntax error prevents that translation; it is not an HTTP or runtime failure.
  2. 02java searches its classpath for the named class and invokes its entry point. Run from the directory containing Main.class, or provide the correct classpath.
  3. 03Keep one source of truth for the selected JDK in your shell and IDE. PATH order can cause javac and java to come from different installations.

A mistake worth avoiding

An IDE run button can hide a mismatched shell setup.

DEBUGGING ROOM

Something broke. Where do you look?

UnsupportedClassVersionError appears after copying a class file to another machine.

Before revealing the diagnosis, write down your first investigation step.

CHECK YOUR UNDERSTANDING

Which file is normally executed by the JVM after javac Main.java?

Choose one answer

BUILD IT YOURSELF

Build without an IDE

  1. 1.Compile Main.java in a clean directory.
  2. 2.Run java Main from that directory.
  3. 3.Move to its parent and run with an explicit -cp path.

Acceptance checklist

Lab completion is your self-report. Knowledge checks do not certify project quality.

RETRIEVE IT FROM MEMORY

Why can code compile on one JDK and fail on another runtime?

Revisit this lesson in three days after a successful check or lab.

Ready for the next step?

Explain JDK, JVM, source, bytecode, and main.

Reading is separate from passing a knowledge check or completing a lab.

Go deeper · official references