Skip to content

how-to-tutorials

46 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 ScheduledExecutorService for Periodic Tasks in Java

In financial systems built on Apache Kafka and Flink, background scheduling is everywhere: checking consumer lag every 30 seconds, expiring distributed locks after a payment SLA window, scheduledExecutorService is production-grade answer to all of this.

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 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 Sealed Classes and Interfaces in Java 21

Build a currency-rate feed in Java 21 where the compiler flags every switch you forgot to update. Sealed interfaces, records and sealed classes, step by step.

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.