Skip to content

java-tutorials

33 Posts

How to Implement Comparable and Comparator in Java 21

Sort a warehouse stock list by SKU, name, price and expiry date with Comparable and Comparator on Java 21, then prove the order with 28 runnable checks.

How to Use PriorityQueue and TreeMap in Java (Java 21)

Build a support-ticket desk in Java 21: a PriorityQueue that hands out the next ticket, a TreeMap that answers SLA deadline questions, and seven forced traps.

How to Use CompletableFuture for Async Programming in Java

Learn how to use Java's CompletableFuture for async programming — with real payment pipeline examples covering supplyAsync, thenCompose, thenCombine, error handling, and custom thread pools. Covers Java 8, 9, and 21.

How to Collect Stream Results in Java: Collectors Guide

Build a URL-shortener click report that uses groupingBy, partitioningBy, toMap, teeing and a custom Collector on Java 21, with 21 checks and the errors I hit.

How to Use Java Enums with Fields and Methods (Java 21)

Build a library loan desk in plain Java 21: an enum with fields, a lookup by code, per-constant behaviour, and a small state machine, all checked by 36 tests.

How to Use WatchService in Java to Watch a Directory

Build a folder watcher in Java 21 with WatchService. It copes with half-written files, duplicate events and overflow, and ships with 23 passing checks.