All guides

Java Foundations: the primitives, runnable

Reference articles for the Java primitives, each explained and backed by a runnable brick: data modeling, then the memory model.

Field guide2 articles20 min read

These are the reference articles for the Java primitives. Every article pairs with one runnable brick in the java-foundations repo, and one command runs it. Where an article measures something, the number comes from that brick's recorded runs, with the machine named.

The list below is in publication order, and it's the only order there is. Each article carries one rule you can keep in your head, and the key ideas under the list collect them, one per article. More parts join as the bricks get written up.

In this guide

  1. Records, sealed interfaces, and exhaustive switch: one modeling primitiveRecords, sealed interfaces, and pattern matching are usually taught as three Java features. Together they form one modeling primitive that turns a fail-open security bug into a compile error.9 min read
  2. Java memory model: volatile, atomic, synchronized and final, measuredvolatile makes each read and each write visible, but it does not make hits++ one step. Three runnable JDK 27 experiments measure what volatile, AtomicInteger, synchronized and final each promise.11 min read

Key ideas

  1. Next time you reach for a record, ask whether it's actually one alternative of a closed set. If it is, seal the set and delete the default branch.
  2. One writer: volatile. New value from the old one: atomic. More than one line: synchronized.