Skip to content

Java Practice

Optional language. Java is not one of the languages this curriculum targets, so these exercises have no reference implementations yet and are excluded from ol verify build and from CI. They are kept because the exercises are worth doing, and every ol command works on them by name.

Toolchain: mise, with a .mise.toml pin. On a chezmoi-managed machine it comes from the install_alt_langs flag, which is off by default.

macOS ships /usr/bin/java as a stub that exists and only prints “Unable to locate a Java Runtime”, so check with javac -version, not command -v javac.

Master JVM internals, generics, concurrency, and modern Java features.

ConceptDetails
Memory ModelJVM GC (G1/ZGC), heap/stack, escape analysis, value types (Valhalla preview)
Type SystemStrong static, generics (type erasure), sealed classes, records
Error HandlingChecked + unchecked exceptions, Optional, try-with-resources
ConcurrencyVirtual threads (21+), CompletableFuture, java.util.concurrent, structured concurrency
Buildgradle or maven, jshell for REPL
StandardJava 21+ LTS
  • Records for immutable data transfer objects
  • Sealed interfaces + pattern matching (switch expressions)
  • Virtual threads over thread pools for I/O-bound work
  • Stream API for functional collection processing
  • Try-with-resources for AutoCloseable cleanup
  • Optional instead of null returns
  • var for local variable type inference
Terminal window
practice/bin/ol list build java # which of these have references yet
practice/bin/ol start build java 01 # clone it stubbed into .scratchpad/
practice/bin/ol check build java 01 # run it; exit code is the verdict
practice/bin/ol diff build java 01 # your attempt against the reference

Exercises are ordered by concept, not by difficulty, so pick by the stars rather than by the number. An exercise listed below with no reference yet is a row in this table and nothing more; see the practice path for how the harness works.

#ExerciseConceptsDifficulty
01ArrayList<T> from scratchGenerics, type erasure, Iterable⭐⭐
03Virtual thread HTTP serverVirtual threads, ServerSocket, structured concurrency⭐⭐⭐
04Dependency injection (mini-Spring)Reflection, annotations, Proxy⭐⭐⭐⭐
05Stream collector libraryCollector interface, Spliterator, parallel streams⭐⭐⭐
06Event sourcing frameworkRecords, sealed interfaces, pattern matching⭐⭐⭐⭐
07Garbage collector simulatorMemory model, reference types, mark-sweep⭐⭐⭐⭐
08Bytecode interpreter (subset)ClassFile format, operand stack, JVM internals⭐⭐⭐⭐⭐
09Reactive streams publisherFlow API, backpressure, SubmissionPublisher⭐⭐⭐⭐
10Annotation processorjavax.annotation.processing, code generation⭐⭐⭐⭐

Exercise 02 (concurrent hash map) is consolidated into the course modules ds.02 and ds.05 (Systems Data Structures); the row had no reference.