First Steps
First Steps: Overview
Chapter 1 of the Java book, for readers with zero programming background. In five lessons you go from "what is a program?" to a working interactive program. You'll compile and run code, meet values and the eight primitives, learn arithmetic and its traps, work with text, and handle input and output. Every example is compiled and run, and every compiler error is real.
Suggest an editFirst Steps: Overview
Welcome to Chapter 1, the very beginning. It assumes you've never programmed before, in any language. By the end of these five lessons, you'll have written, compiled, and run real Java: doing arithmetic, building text, reading what a person types, and printing answers back. Along the way, you'll meet the idea that runs through the whole book — that Java checks your program twice, once when the compiler reads it and again when the JVM runs it — and you'll learn to read both kinds of message.
There are five lessons, in this order:
- What Java Is & Running Code — what a program is, the compile-then-run loop (
javacand the JVM), whypublic static void mainlooks the way it does, andprintln— the command that lets a program talk back. - Variables & Primitive Types — naming values so you can reuse them, static typing, and the eight built-in kinds of value: whole numbers, decimals, true/false, and single characters.
- Numbers & Arithmetic — the operators, why integer division truncates, and why an
intcan silently wrap past its range to a negative number. - Strings, the Basics — building and reshaping text, why a String can never be changed, and the
==-vs-.equalstrap that comparing text is full of. - Input & Output — formatted output with
printf, reading typed input withScanner, turning text into numbers, and writing a first interactive program.
Every code block with a ▶ Run button is live — click it, change the code, and run it again. The fastest way to learn in this chapter is to perturb working examples: change a number, swap a word, break something on purpose, and see what the compiler or the JVM says. You can't harm anything. The worst that can happen is an error message — and reading error messages is itself a skill these lessons build.
📘 How to read the Intuition boxes. Each one is built in three moves:
- The mechanism — what the compiler and the JVM are actually doing.
- A concrete bite — a specific, runnable failure (often a real compiler error), shown so the trap is visible.
- The earned rule — the decision heuristic, now justified rather than asserted, plus its cost.