Skip to content

java-tutorials

33 Posts

How to Use flatMap in Java to Flatten Nested Lists

Flatten students, courses and assignments with flatMap, flatMapToInt, Optional.stream and mapMulti on Java 21. 22 checks, forced errors and the fixes included.

How to Use ProcessBuilder to Run Commands in Java 21

How to use ProcessBuilder in Java 21: run a command, read stdout and stderr, feed stdin, set a timeout and kill a stuck child, with 14 checks and 5 traps.

How to Create an Immutable Class in Java (Java 21)

Build an immutable Recipe class in Java 21: final class, final fields, defensive copies and with-ers, plus the leaks a final field alone lets through.

How to Implement the State Machine Pattern in Java

Build a parcel-tracking state machine in Java 21 with enums and a transition table, add a guard for failed deliveries, and prove the rules with 19 checks.