Home › Learn › Java

Java

40 lessons, 8 modules, Java running in your browser.

Start the course

Java is the language of Android, of most large company back ends, and of a lot of first-year computer science. This is a working Java, not a quiz about Java: every lesson has a short explanation, a task, and an editor, and Run hands your code to the real Java compiler, running inside your browser tab, then runs the result and checks it. Compile errors come back with the line number, the way they would from any Java tool.

The course goes from printing a line to interfaces, generics, streams, and exceptions, in the order the ideas build on each other. It ends in a project, a small library system, that is not started from nothing: one lesson in most modules builds one of its classes, saved in this browser as you go, and the project compiles them alongside your own code. Forty lessons of ten minutes or so each; you can stop and pick up later.

What you will learn

The final project

The course ends with Project: the library: a library system assembled from the classes you built. 10 of the lessons build a part of it, saved in this browser as you go, so the project is assembled from your own work rather than started from nothing.

  1. Policy (Variables and types) holds the loan length and the daily late fee the library charges.
  2. Fees (Methods) works out the late fee for a returned book, capped at ten dollars.
  3. Checksum (while loops) adds up the digits of a card number; a valid card sums to a multiple of ten.
  4. Search (Arrays) finds the position of a title in the catalog, or -1 when it is not there.
  5. Isbn (Characters) checks the check digit of an ISBN-10 before a book is accepted into the catalog.
  6. Book (Encapsulation) is a book in the catalog: title, author, ISBN, and whether it is on the shelf.
  7. Member (Records) is a library member: a name and a card number.
  8. Status (Enums) is the state of a book: available, on loan, or lost.
  9. Reports (Streams) counts the books in the catalog per author.
  10. LibraryException (Custom and checked exceptions) is what the library throws when a request cannot be honored: unknown book, book out, bad card.

Lessons

First steps

  1. Hello, worldPrint a line with System.out.println and see how the lessons check your work.
  2. Variables and typesDeclare a variable with a type, store a value, and use it.part: Policy
  3. Numbers and mathInteger and floating-point arithmetic, remainders, and the Math class.
  4. StringsJoin text, measure it, and pick characters out of it.
  5. Reading compile errorsLearn what the compiler is telling you by fixing three broken lines.

Decisions and methods

  1. Comparisons and booleansAsk questions about values and combine the answers.
  2. if and elseRun a block of code only when a condition holds.
  3. else if chainsPick one of several outcomes, in order.
  4. MethodsPackage code under a name, give it inputs, get a result back.part: Fees
  5. switchChoose among several fixed values without a chain of ifs.

Loops

  1. for loopsRepeat a block a counted number of times.
  2. while loopsRepeat until a condition stops holding.part: Checksum
  3. break and continueLeave a loop early, or skip one round.
  4. Nested loopsA loop inside a loop covers every combination.
  5. FizzBuzzThe classic loop-and-conditions exercise.

Arrays and lists

  1. ArraysA fixed-length row of values of one type.part: Search
  2. The for-each loopVisit every element without an index.
  3. ArrayListA list that grows and shrinks.
  4. SortingPut arrays and lists in order without disturbing the originals.
  5. HashMapLook values up by key instead of by position.

Strings and text

  1. String methodsSplit, search, cut, and replace text.
  2. CharactersWalk a string one char at a time.part: Isbn
  3. StringBuilderBuild long strings efficiently.
  4. Parsing numbersText to number and back, safely.
  5. Formatting textLine up columns and print money without a formatting library.

Objects

  1. Classes and objectsBundle data with the methods that work on it.
  2. Constructors and thisSet an object up when it is created.
  3. EncapsulationPrivate fields, getters, and a toString.part: Book
  4. RecordsA class that is only data, in one line.part: Member
  5. InheritanceBuild a class on top of another and override its behavior.

Interfaces, generics, and streams

  1. InterfacesA contract that different classes can fulfill.
  2. EnumsA type with a fixed set of named values.part: Status
  3. LambdasPass behavior as a value.
  4. GenericsClasses and methods that work for any type.
  5. StreamsFilter, map, and collect without writing the loop.part: Reports

Exceptions, and the project

  1. ExceptionsRefuse bad input loudly, and recover from failures.
  2. Custom and checked exceptionsDefine your own exception type and make callers deal with it.part: LibraryException
  3. OptionalA value that may be absent, without null.
  4. equals, hashCode, and ComparableMake your own classes compare, hash, and sort like built-in ones.
  5. Project: the libraryAssemble the classes you built along the way into a working library system.final project