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 edit

First 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:

  1. What Java Is & Running Code — what a program is, the compile-then-run loop (javac and the JVM), why public static void main looks the way it does, and println — the command that lets a program talk back.
  2. 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.
  3. Numbers & Arithmetic — the operators, why integer division truncates, and why an int can silently wrap past its range to a negative number.
  4. Strings, the Basics — building and reshaping text, why a String can never be changed, and the ==-vs-.equals trap that comparing text is full of.
  5. Input & Output — formatted output with printf, reading typed input with Scanner, 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:

  1. The mechanism — what the compiler and the JVM are actually doing.
  2. A concrete bite — a specific, runnable failure (often a real compiler error), shown so the trap is visible.
  3. The earned rule — the decision heuristic, now justified rather than asserted, plus its cost.
Mark as readBook versionfd26460