Layers of Logic

Java · early preview

Learn the language. Keep going into the runtime.

Start with the JVM and your first program. Finish with memory, garbage collection, locks, atomics, executors, and virtual threads. The order matters: each phase uses the model built before it.

Start with how Java runs
14 phases57 lessons235 exercises20 hours of reading
  1. I

    Phase I

    The Machine

    What Java is, and what is actually running your code.

    1. 1.1Why Java ExistsSee why Java was created and how one source file becomes instructions a computer can run.16 min
    2. 1.2JVM, JRE, JDK, and Your First ProgramInstall the tools, compile one Java file, and run it from the terminal.20 min
  2. II

    Phase II

    Data and Memory

    Trace a Java value from source literal to bits, arithmetic, conversion, and output.

    1. 2.1Variables, Types, Literals, KeywordsStore values in variables and choose a type that fits the data.22 min
    2. 2.2How Numbers Live in MemorySee how Java stores whole numbers and decimal approximations as bits.26 min
    3. 2.3Type Conversion, Promotion, CastingPredict when Java changes a numeric type and what information the conversion can lose.24 min
  3. III

    Phase III

    Logic and Flow

    Making a program compute, decide, and repeat.

    1. 3.1OperatorsUse operators to calculate values, compare them, combine conditions, and work with bits.20 min
    2. 3.2ConditionalsUse if and switch to make a program choose what to do.18 min
    3. 3.3Loops and Jump StatementsUse for, while, and do-while loops, and trace when each loop stops.17 min
  4. IV

    Phase IV

    Data in Rows

    Fixed-length indexed data, array references, traversal, aliasing, and copying.

    1. 4.1ArraysStore several values in an array, read and update elements, and copy arrays correctly.19 min
    2. 4.2How Arrays WorkSee how array indexing and bounds checks work, and why indexed access has a fixed cost.20 min
  5. V

    Phase V

    Methods

    Giving work a name, and the stack that makes it possible.

    1. 5.1Methods, Calls, Recursion, and OverloadingWrite and call methods, pass values, return results, and choose between overloaded methods.28 min
  6. VI

    Phase VI

    Objects

    Define reference types, construct valid objects, and trace identity, calls, and copying.

    1. 6.1Classes, Objects, and `new`Define a class and create objects that each hold their own field values.20 min
    2. 6.2Constructors, Chaining, `this`Use constructors to give every new object a valid starting state.20 min
    3. 6.3Objects in Memory: Size, Copying, PassingTrace references to explain shared objects, method arguments, copying, and object size.22 min
    4. 6.4`static` and `final`Use static for class-level data and final to prevent specific kinds of change.21 min
  7. VII

    Phase VII

    The Four Pillars

    Closing objects off, building on them, and letting them choose their own behaviour.

    1. 7.1Encapsulation, Inheritance, Packages, and `super`Protect an object's rules and move genuinely shared behaviour into a parent class.28 min
    2. 7.2Abstraction, Polymorphism, Abstract Classes, and InterfacesUse one parent type while each child object provides its own behaviour.30 min
    3. 7.3Wrapper Types, Autoboxing, and POJOsSee when Java converts between primitives and wrapper objects, and avoid equality and null errors.26 min
    4. 7.4Static Nested, Inner, Local, and Anonymous ClassesChoose a nested-class form from the data and enclosing object it needs to access.29 min
  8. VIII

    Phase VIII

    Identity and Contracts

    Input, immutability, equality, enums, and interface contracts.

    1. 8.1Java I/O: Streams, Scanner, BufferedReaderRead keyboard and file input with Scanner and BufferedReader, distinguish byte streams from character readers, and explain why buffering improves performance.19 min
    2. 8.2Immutable ClassesBuild an immutable class by controlling construction, reassignment, mutation, inheritance, and references to mutable data.17 min
    3. 8.3The Object Class: `equals`, `hashCode`, `toString`Override equals, hashCode, and toString correctly, and follow the equality contract required by hash-based collections.24 min
    4. 8.4EnumsDefine a fixed set of named values, attach fields and methods to them, and use exhaustive switch expressions safely.18 min
    5. 8.5Interface Methods and Functional InterfacesDistinguish abstract, default, static, private, marker, and functional interface features and choose each for a specific purpose.20 min
  9. IX

    Phase IX

    Text and Types

    String behaviour, text construction, generic types, and wildcards.

    1. 9.1Strings: The Pool and ImmutabilityExplain String immutability, literal pooling, object identity, and why text content must be compared with equals rather than ==.19 min
    2. 9.2String Methods and StringBuilderUse the String methods needed for search, slicing, cleanup, and comparison, then build changing text efficiently with StringBuilder.17 min
    3. 9.3GenericsDeclare generic classes and methods, apply type bounds, and explain how compile-time type checks replace unsafe Object casts.20 min
    4. 9.4Wildcards: `extends` and `super`Explain generic invariance and use unbounded, extends, and super wildcards without giving up type safety.18 min
  10. X

    Phase X

    The Collections Framework

    Different ways to store data, and when each one makes sense.

    1. 10.1The Collections FrameworkChoose List, Set, Queue, or Map from the operations, ordering, duplicate, and lookup behaviour your program requires.19 min
    2. 10.2Iterable and the IteratorImplement and use Iterable and Iterator, trace how for-each obtains elements, and remove elements without corrupting traversal.18 min
    3. 10.3The Collection InterfaceUse the core Collection operations, bulk methods, array conversion, and optional operations shared across collection types.16 min
    4. 10.4List: ArrayList, LinkedList, Vector, StackCompare ArrayList and LinkedList by operation cost, and recognise why the older Vector and Stack classes are usually replaced.19 min
    5. 10.5Set and Map: Inside HashMapUse Set and Map, trace a HashMap lookup through hashing and equality, and predict the effect of collisions and mutable keys.24 min
    6. 10.6Map Operations and Specialized MapsUse Map update and lookup methods, then choose among HashMap, LinkedHashMap, TreeMap, EnumMap, IdentityHashMap, and WeakHashMap.18 min
    7. 10.7Queue, Deque, and PriorityQueueUse Queue and Deque operations, distinguish FIFO from priority ordering, and trace how PriorityQueue stores a binary heap in an array.18 min
    8. 10.8Comparable, Comparator, and SortingDefine natural ordering with Comparable, supply alternative orderings with Comparator, and keep comparison consistent with equality where required.20 min
  11. XI

    Phase XI

    Functional Java

    Lambdas, method references, streams, collectors, and Optional.

    1. 11.1Lambdas and Functional InterfacesReplace small anonymous-class implementations with lambda expressions and match each lambda to a functional interface method.20 min
    2. 11.2Method References and the Four ShapesUse Function, Predicate, Supplier, and Consumer, then replace eligible lambdas with the four forms of method reference.21 min
    3. 11.3Streams, and When the Work HappensBuild a stream pipeline, distinguish intermediate from terminal operations, and predict how laziness and short-circuiting control execution.20 min
    4. 11.4Stream Operations and CollectorsChoose transformation, filtering, ordering, reduction, matching, and collection operations from the result your pipeline must produce.21 min
    5. 11.5OptionalRepresent an absent result explicitly, transform present values safely, and avoid Optional patterns that recreate null checks or hide errors.19 min
    6. 11.6Parallel and Primitive StreamsUse IntStream, LongStream, and DoubleStream to avoid boxing, then decide when parallel execution is safe and likely to help.20 min
  12. XII

    Phase XII

    When Things Go Wrong

    Diagnosing failures, reading stack traces, and designing exception handling.

    1. 12.1Exceptions, Errors, and the Stack TraceDistinguish normal returns from thrown failures, read a stack trace from the failure outward, and use try, catch, finally, and try-with-resources.20 min
    2. 12.2Checked, Unchecked, and Exceptions of Your OwnDistinguish checked exceptions, unchecked exceptions, and errors, then design custom exceptions that preserve useful causes and recovery choices.21 min
  13. XIII

    Phase XIII

    Memory and the Garbage Collector

    JVM memory areas, reachability, collection, and memory leaks.

    1. 13.1JVM Memory AreasPlace call frames, objects, class metadata, run-time constants, native work, and per-thread execution state in the JVM memory model.20 min
    2. 13.2Reachability and Garbage CollectionDetermine object reachability from garbage-collection roots, explain why cycles can be collected, and identify references that cause memory leaks.21 min
  14. XIV

    Phase XIV

    Concurrency

    Threads, shared state, synchronization, atomics, executors, and virtual threads.

    1. 14.1Processes and ThreadsDistinguish processes from threads, identify per-thread and shared state, and observe the background threads present in a Java program.19 min
    2. 14.2Creating Threads and Thread StatesCreate work with Runnable and Thread, start it correctly, and interpret all six Thread.State values.19 min
    3. 14.3Interruption and Cooperative CancellationRequest thread cancellation with interruption, handle InterruptedException without losing the request, and coordinate shutdown with join.19 min
    4. 14.4Race Conditions, Atomicity, and VisibilityReproduce lost updates, stale reads, and ordering surprises, then separate the atomicity and visibility guarantees each fix requires.22 min
    5. 14.5synchronized and Monitor LocksSelect the correct monitor, define a protected invariant, limit critical-section size, and prevent deadlock with consistent lock ordering.21 min
    6. 14.6wait, notify, and notifyAllCoordinate threads with a condition predicate, call wait while holding the monitor, and recheck the predicate after every wake-up.20 min
    7. 14.7Explicit Locks and ConditionsUse ReentrantLock, timed and interruptible acquisition, Condition queues, and ReadWriteLock only when their extra control is required.21 min
    8. 14.8Atomic Variables and Compare-and-SwapUse atomic variables for single-value updates, implement a compare-and-swap retry loop, and recognise when an invariant still requires a lock.20 min
    9. 14.9CAS Retry Loops and the ABA ProblemExplain failed compare-and-swap retries, measure repeated work under contention, and detect state that changed and later returned to the same value.19 min
    10. 14.10Executors, Thread Pools, and FuturesSubmit Runnable and Callable tasks, retrieve results and failures through Future, size a thread pool, and choose a bounded task queue.21 min
    11. 14.11CompletableFuture and Virtual ThreadsCompose asynchronous results without blocking, propagate failures through a pipeline, and use virtual threads for large numbers of blocking tasks.22 min