Skip to content

how-to-tutorials

46 Posts

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.