A hands-on, topic-by-topic walkthrough of the Java programming language
(targeting Java 21 LTS ). Every topic is a runnable .java file with theory
in the top Javadoc and worked examples in main(). The expected console output
is also included as comments inside each main() so you can verify your run.
Project SDK: JDK 21 — set in .idea/misc.xml. Files under
src/Phase9_ModernJavaAndModules/ModernJava and several others use
Java 21 features (pattern matching for switch, record patterns, sequenced
collections, virtual threads, …).
Each section below links straight to the source file(s) in this repository.
Learning Phases at a Glance Work through the phases in order. Within a phase, files are self-contained —
read them in the order they appear.
Phase Theme Sections 0 Setup & First Programs Hello world, JVM/JDK/JRE, Input / Output 1 Core Language Types, variables, operators, control flow, enums 2 Methods, Arrays, Strings The everyday building blocks 3 Object Orientation Classes, interfaces, nested classes 4 Errors & Type Safety Exceptions, Optional, Generics, Annotations 5 Collections, Lambdas & Streams Data structures + functional pipelines 6 Runtime, Memory, Regex, Reflection Below the surface 7 Concurrency Threads, synchronization, virtual threads 8 Practical APIs File I/O, Date & Time, HTTP Client 9 Modern Java & Modules Java 10 → 21 features, JPMS
Estimated pace if you read one phase per week: 9 weeks. Bear down on the
projects (Banking, Employee, Face Detection, Snake Game) as you reach them —
they're where the concepts click.
Phase 0 — Setup & First Programs Get a JDK installed, understand what the JDK / JRE / JVM are, write your
first main(), and figure out how Java reads and writes the console.
Identifiers, keywords, types, variables, operators, control flow, enums.
Master this and every later phase becomes easier.
Phase 2 — Methods, Arrays, Strings The bread-and-butter library types and the keyword you'll use the most.
Strings are immutable; arrays are fixed-size; methods are how you organise
behaviour.
# Topic Source 1 Introduction (declare, init, iterate, defaults, pitfalls) ArrayIntroduction.java 2 Multi-Dimensional Arrays (2D, 3D, deepToString) MultiDimensionalArrays.java 3 Jagged Arrays (varying row lengths, Pascal's triangle) JaggedArrays.java 4 java.util.Arrays utility class (sort, search, copy, fill, equals, stream)ArraysClass.java 5 Final Arrays (reference vs contents, immutability patterns) FinalArrays.java
# Topic Source 1 Introduction (pool, intern, char[] bridge, compact strings) StringIntroduction.java 2 Why Strings are Immutable (pool, threads, security, hash caching) StringImmutability.java 3 String Concatenation (+, concat, join, StringJoiner, perf trap) StringConcatenation.java 4 String Methods (every important method by category) StringMethods.java 5 StringBuffer Class (synchronized, full method reference) StringBufferClass.java 6 StringBuilder Class (non-synchronized, full method reference) StringBuilderClass.java 7 String vs StringBuffer vs StringBuilder (table + benchmark) StringVsBufferVsBuilder.java 8 Modern Features — Java 11/12/15/21 (strip, repeat, lines, transform, text blocks, case String s when …) ModernStringFeatures.java
Phase 3 — Object Orientation Java's organising paradigm — classes, objects, and the four pillars
(abstraction, encapsulation, inheritance, polymorphism). Then interfaces,
the second pillar of abstraction, and nested classes that finish the
picture.
# Topic Source 1 Interfaces — full tour (abstract / default / static / private members, multiple impl, interface inheritance) InterfaceIntro.java 2 Class vs Interface (side-by-side, real-world JDK pattern) ClassVsInterface.java · longer version 3 Functional Interface (SAM, @FunctionalInterface, java.util.function, composition, lambdas, comparators) FunctionalInterfaceDemo.java 4 Nested Interface (inside class, inside interface, private nested) NestedInterface.java 5 Marker Interface (Serializable, custom marker, annotation alternative, generic upper bound) MarkerInterface.java 6 Sealed Interfaces — Java 17+ (permits, non-sealed, exhaustive switch) SealedInterfaceDemo.java 7 Project: Employee Management System Employee (sealed) · FullTimeEmployee · PartTimeEmployee · Contractor · Intern · Promotable · Auditable (marker) · EmployeeFilter (functional) · EmployeeRepository · Runner: EmployeeApp.java
Phase 4 — Errors & Type Safety Mechanisms for handling things going wrong, making "absent values" explicit
in the type system, parameterising types safely, and decorating code with
metadata that tools can read.
# Topic Source 1 Introduction (hierarchy, checked vs unchecked, stack trace) ExceptionIntroduction.java 2 Try-Catch Block (single / multiple / multi-catch / nested / finally) TryCatchBlock.java 3 final, finally, finalize — three confusable keywordsFinalFinallyFinalize.java 4 throw and throws — raise vs declare, propagation, re-throwThrowAndThrows.java 5 Custom Exceptions (checked + unchecked, carrying extra data) CustomException.java 6 Chained Exceptions (getCause, initCause, suppressed vs cause) ChainedException.java 7 Null Pointer Exceptions (six causes, helpful NPE Java 14+, Optional) NullPointerExceptions.java 8 Exception Handling with Method Overriding (the throws rule) ExceptionInOverriding.java 9 Try-with-resources — Java 7+ / 9+ (AutoCloseable, suppressed exceptions) TryWithResources.java 10 Best Practices (top-10 dos & don'ts with code) ExceptionBestPractices.java
# Topic Source 1 Optional<T> (creation, transforms, anti-patterns, primitive variants)OptionalDemo.java
# Topic Source 1 Introduction (before/after, type parameter conventions) GenericsIntroduction.java 2 Generic Classes (single + multi-param, inheritance, diamond) GenericClasses.java 3 Generic Methods (type inference, method-level type params) GenericMethods.java 4 Generic Interfaces (Comparable, Function, custom contracts) GenericInterfaces.java 5 Bounded Type Parameters (<T extends X>, multi-bound &) BoundedTypeParameters.java 6 Wildcards (?, ? extends, ? super) Wildcards.java 7 PECS Principle (Producer Extends, Consumer Super) PecsPrinciple.java 8 Type Erasure (runtime behaviour, bridge methods, reflection) TypeErasure.java 9 Generic Restrictions (no primitives / no new T() / no generic arrays / no parameterised instanceof) GenericRestrictions.java 10 Recursive Type Bounds (<T extends Comparable<T>>, self-typed builders, Enum<E extends Enum<E>>) RecursiveTypeBounds.java 11 Heap Pollution + @SafeVarargs HeapPollutionAndSafeVarargs.java 12 Modern Generics — Java 7 → 21 (diamond, var, generic records, sealed generic interfaces, generic record patterns in switch ) ModernGenerics.java
# Topic Source 1 Introduction (the four families, retention levels) AnnotationsIntroduction.java 2 Built-In Annotations (@Override, @Deprecated, @SuppressWarnings, @FunctionalInterface, @SafeVarargs) BuiltInAnnotations.java 3 Custom Annotations (@Retention, @Target, @Repeatable, @Inherited, type-use) CustomAnnotations.java 4 Runtime Annotations (reading via reflection, mini AOP) RuntimeAnnotations.java
Phase 5 — Collections, Lambdas & Streams Pick the right container, then transform data declaratively with lambdas
and the Stream API.
4. Queue / Deque Implementations 6. Utility & Supporting Classes 7. Concurrency Collections Lambda Expressions and Streams Topic Source Sequential vs Parallel (when each helps, side-effect trap, splittability) SequentialVsParallel.java Infinite Streams (iterate/generate/limit/takeWhile) InfiniteStreams.java Primitive Streams (IntStream/LongStream/DoubleStream, boxing perf) PrimitiveStreams.java Stream vs Collection (side-by-side, crossing back and forth) StreamVsCollection.java File I/O via streams (Files.lines/list/walk, append, write) StreamFileIO.java Modern Streams — Java 9 → 21 (takeWhile/dropWhile, iterate(3-arg), mapMulti, toList, teeing, sequenced collections) ModernStreams.java
Phase 6 — Runtime, Memory, Regex, Reflection What the JVM actually does with your code, how to manipulate text with
patterns, and how to inspect and dispatch dynamically.
# Topic Source 1 Java Memory Management (overview, heap inspection, default GC) MemoryManagementIntro.java 2 How Java Objects Are Stored in Memory (header, fields, padding, references, compressed oops) ObjectsInMemory.java 3 Types of Memory Areas (Method Area / Heap / Stack / PC / Native, generations) JvmMemoryAreas.java 4 Stack vs Heap (side-by-side, pass-by-value, escape analysis) StackVsHeap.java 5 Garbage Collection (reachability, mark/sweep, generations, weak/soft refs, Cleaner) GarbageCollection.java 6 Types of JVM Garbage Collectors (Serial / Parallel / G1 / ZGC / Shenandoah / Epsilon) GarbageCollectors.java 7 Memory Leaks (5 patterns + fixes) MemoryLeaks.java 8 Modern Memory Features — Java 9 → 21 (Compact Strings, Cleaner, direct buffers, virtual threads, Generational ZGC ) ModernMemoryFeatures.java
# Topic Source 1 Introduction (Pattern + Matcher, escapes, matches vs find vs lookingAt) RegexIntroduction.java 2 Matcher Class (every important method, named groups, replaceAll, region, results) MatcherClass.java 3 Character Class (custom sets, predefined \d/\w/\s, POSIX, Unicode) CharacterClass.java 4 Quantifiers (*+?{n,m}, greedy vs reluctant vs possessive, backtracking) Quantifiers.java 5 Metacharacters & Anchors (^$\b\A\z\G, Pattern.quote) MetacharactersAndAnchors.java 6 Groups & Backreferences ((…)(?:…)(?<name>…)\1${name}) GroupsAndBackreferences.java 7 Lookahead & Lookbehind ((?=…)(?!…)(?<=…)(?<!…), password rules) LookaroundAssertions.java 8 Flags (CASE_INSENSITIVE, MULTILINE, DOTALL, COMMENTS, UNICODE_CHARACTER_CLASS, scoped (?i:…)) RegexFlags.java 9 Modern Features — Java 8/9/11/21 (splitAsStream, asPredicate, Matcher.results, replaceAll(Function), pattern-matching switch on String) ModernRegexFeatures.java 10 Real-World Examples (email, phone, URL, IPv4, password, ISO date, hex color, slug, CSV) RegexExamples.java
Multiple threads of execution inside one JVM — concurrent and parallel
work, the synchronization primitives that keep shared state sane, and the
Java 21 virtual-thread world.
3. Correctness (synchronization, JMM, atomics) 5. Executors and high-level concurrency 7. Java 21 — modern concurrency The APIs you'll actually reach for in business apps: reading and writing
files, handling dates and times, and talking to HTTP services.
# Topic Source 1 Introduction (java.io vs java.nio.file, which class for what) FileIOIntroduction.java 2 Byte Streams (InputStream / OutputStream, File* impls) ByteStreams.java 3 Character Streams (Reader / Writer, charset traps, bridges) CharacterStreams.java 4 Buffered Streams (Buffered*, readLine, lines()) BufferedStreams.java 5 Data Streams (DataInput/OutputStream for primitives) DataStreams.java 6 Object Streams (Java serialization in/out) ObjectStreams.java 7 Path and Files (the modern API)FilesAndPaths.java 8 Walking the file system (list/walk/find/lines) FilesWalkAndList.java 9 FileChannel (random access, memory mapping, locks)FileChannelDemo.java 10 WatchService (observe FS changes)WatchServiceDemo.java 11 Modern File I/O — Java 11+ (readString, writeString, mismatch) ModernFileIO.java
Phase 9 — Modern Java & Modules Language and library features that landed between Java 8 and Java 21, and
the module system added in Java 9. By the end of this phase you can read
any modern Java codebase fluently.
Java Platform Module System (JPMS) This is a plain-Java project — no Maven, no Gradle. From the repo root:
# Compile one file
javac src/Phase0_SetupAndFirstPrograms/Introduction/Introduction.java
# Run it (use the fully qualified class name including the package)cd src
java Phase0_SetupAndFirstPrograms.Introduction.IntroductionOr from your IDE: right-click any .java file containing a main() and choose
Run .
Single-file mode (Java 11+) java src/Phase0_SetupAndFirstPrograms/Introduction/Introduction.java How Each File Is Structured Every .java file is self-contained:
A theory block at the top (Javadoc style) — read this first. A main() method with concrete, runnable examples grouped into numbered sections. Expected output captured inline as comments where useful. Most folders also have one <Topic>.README.md per file with the same theory in
markdown form — handy for browsing on GitHub without opening the source.
Phase Suggested duration Capstone 0–1 Week 1 — 2 Week 2 — 3 Week 3 Banking App , Employee App 4 Week 4 — 5 Weeks 5–6 Face Detection 6 Week 7 — 7 Weeks 8–9 Snake Game 8 Week 10 — 9 Week 11 —
Happy hacking!