A free, in-depth Java course

Java from First Principles

Thirty-nine lessons that take you from what is a program? to a tested, documented 2D game of your own design. Every idea is explained before it is used, every program shown has been through the real compiler, every output and error message on these pages is real, and every exercise comes with a checker you run yourself.

Start here

Part 2 · Objects arrives on 21 December 2026. Get notified.

Before you begin

  1. 0Start hereHow the course works, where files live, and how to get your exercises checked.

Part 1 · The core language

Values, decisions, repetition, methods, text and collections. You use a few ready-made kinds of object (strings, arrays, lists) but do not design your own yet, so you can see exactly what each line does.

  1. 1How Java runsSource code, the compiler, bytecode and the JVM. Every word of your first program, and how to read errors.
  2. 2Values, variables and typesPrimitive types, String, operators, integer division, casting, overflow, imprecise decimals and constants.
  3. 3DecisionsConditions, if and else, scope, logical operators and short-circuiting, the conditional operator, and both forms of switch.
  4. 4Loopswhile, do-while and for, break and continue, nested loops, and tracing a loop by hand.
  5. 5MethodsParameters, return values, the call stack, scope, pass-by-value, overloading and a first look at recursion.
  6. 6Strings in depthReferences, string methods, immutability, == versus equals, char, parsing numbers, StringBuilder, printf and null.
  7. 7Arrays and ArrayListArrays, for-each, imports, command-line arguments, varargs and tables, then growable lists and wrapper types such as Boolean.
  8. ACheckpoint project AA console tool that uses everything in Part 1.

Part 2 · Objects

What a class really is, how objects live in memory, how to make them protect their own rules and work together, and where static, final and packages fit in.

  1. 8Classes and objectsFields, instance methods, constructors, new, references and the heap, this and null, and keyboard input with Scanner as a first library object.
  2. 9Encapsulationprivate and public, getters and setters, protecting an object's rules, toString with @Override, and constructor chaining.
  3. 10Objects working togetherComposition and delegation, shared and owned objects, collections of your own objects, defensive copies, equals and hashCode.
  4. 11static and finalClass-level state, static methods, constants, final fields and immutable classes, and when static is the wrong tool.
  5. 12PackagesDirectories, import, compiling and running packaged code, name clashes, sub-packages and the unnamed package, and the full access-modifier table.
  6. BCheckpoint project BCityRide: a bike-hire system of cooperating classes in two packages, with a keyboard menu.

Part 3 · Type hierarchies

Sharing and varying behaviour across related classes, fixed sets of named values, and refusing and handling failure properly.

  1. 13Inheritanceextends and super, the order constructors run in, overriding and @Override, protected, the Object class, equals once subclasses exist, final, and when not to inherit.
  2. 14PolymorphismDeclared and runtime types, dynamic dispatch, casting, instanceof and getClass, and why a chain of instanceof tests is a warning sign.
  3. 15EnumsWhat an enum is underneath, name, ordinal, values and valueOf, switch on enums with the compiler's completeness check, and enums with fields, constructors and methods.
  4. 16Abstract classes and interfacesAbstract classes and methods, interfaces and implementing several, List against ArrayList, default and static methods, and choosing between the two.
  5. 17ExceptionsStack traces in full, try, catch and finally, throwing to refuse a bad value, checked against unchecked, throws, try-with-resources and your own exception classes.
  6. CCheckpoint project CMicroGrid: a simulation of a village's power supply, with an abstract class, an interface, enums and a checked exception, in two packages and seven milestones.

Part 4 · Collections and generics

Storing groups of things, writing code that works safely for many types, putting things in order, and passing behaviour as a value.

  1. 18The collections frameworkList, Set and Map as interfaces with several classes behind each, how hashing works, iterators and removing while looping, enum collections, unmodifiable collections, queues and stacks, and choosing between them.
  2. 19GenericsWhat the angle brackets are: generic classes, methods and interfaces, bounds, why a list of Integer is not a list of Number, wildcards, erasure and raw types, and reading the library's headers.
  3. 20OrderingComparable and natural order, writing compareTo safely and in agreement with equals, Comparator classes, combining and reversing orders, stable sorting, sorted sets and maps, and sorting what a map holds.
  4. 21Lambdas and functional interfacesAnonymous classes, lambda expressions and functional interfaces, callbacks and captured variables, method references, the library methods that take behaviour, and a short look at streams.

Part 5 · Designing software

Thinking about structure before writing code, and the standard solutions to recurring design problems.

  1. 22UMLReading and drawing class and sequence diagrams.
  2. 23Design principlesSOLID, composition over inheritance and design by contract.
  3. 24Patterns IFactory, Strategy and State.
  4. 25Patterns IIObserver, Decorator and Composite.

Part 6 · Professional tooling

The tools working programmers use to build, test, document and verify their code.

  1. 26Annotations and reflectionDefining annotations, inspecting and invoking through Class objects, and building a small framework.
  2. 27MavenInstalling it, project layout, pom.xml, dependencies and the build lifecycle.
  3. 28Unit testing with JUnitAssertions, the test lifecycle, testing exceptions and writing testable code.
  4. 29Coverage, Javadoc and CIJaCoCo, Javadoc, a README, and running tests automatically, with the Git needed for it.
  5. DCheckpoint project DAn integration project that uses everything so far, fully tested.

Part 7 · Building a game with JavaFX

A small tower-defence game, built step by step: design first, logic you can test, then graphics.

  1. 30Designing a game on paperThe game design document, picking an idea that suits OOP, and UML for the design.
  2. 31The logic core in plain JavaThe game loop, entities, rules, and win and lose conditions, all testable without graphics.
  3. 32JavaFX fundamentalsProject setup, Application, Stage, Scene, the scene graph and Canvas.
  4. 33The real-time loop and inputAnimationTimer, delta time, and keyboard and mouse state.
  5. 34Sprites, animation and assetsLoading images, sprite sheets and frame animation.
  6. 35Collisions and many entitiesBounding boxes, and creating and removing entities safely during a frame.
  7. 36Game architectureSeparating logic from drawing, screens, and a HUD driven by Observer.
  8. 37Patterns at workStrategy for behaviour, Factory for spawning, Decorator for upgrades and State for game flow.
  9. 38Finishing the gameTests, coverage, Javadoc, CI and the diagrams the project brief asks for.

Part 8 · Your own game

You design and build a game of your own, one milestone at a time.

  1. 39Your own gameThe brief, a design-document template, a UML checklist, a milestone plan and a self-review sheet.