The Java Textbook

Java, all the way down

Every code sample on this site compiles and runs in your browser. Every idea that usually gets waved at — what the JVM actually does, why generics forget their types, what a stream is really doing — comes with a program you can change, and problems that check your answer by running it.

Start at the beginning Jump to problems

10 chapters · 10 written · 2 problems

Three ways to read this

New to programming

Read the early parts in order. They assume nothing: no JDK installed, no terminal experience, no maths beyond arithmetic.

Begin →

You know another language

Skim the first part, then slow down where Java stops behaving like what you already know: references and equality, checked exceptions, and generics that are erased before they run.

Skip ahead →

You want the problems

The problem bank is filterable by topic and difficulty, and each problem compiles and tests your submission. Your progress is saved in this browser.

Open the bank →

Contents

    1. 1.1 Primitives
    1. 2.1 Boolean expressions
    2. 2.2 Loops
    1. 3.1 Writing a class
    1. 4.1 Arrays
    2. 4.2 ArrayList
    3. 4.3 2-D arrays
    4. 4.4 Search and sort
    5. 4.5 Recursion
  1. Part 5

    the-exam

    1. 5.1 Free response