Chapter 1 · Java
Java: The Dream of Thinking Machines
Run this example
Edit and run the java example
Change the source and run it here. Use the output panel to compare your result with the expected highlights below.
Output
Run the code to see output here.
Java — Hotel Check-In Logic
This is the same Boolean check-in rule as the Examples tab, written in Java — the handbook's primary engineering stack.
Because the rule is a pure Boolean AND over fixed facts — no randomness, no learned weights — the Java output is identical to the Python output, character for character.
The program
public class HotelCheckinLogic {
record GuestState(String guestId, boolean paid, boolean bookingExists, boolean roomAvailable) {}
record Decision(boolean allow, List<String> failing) {}
static Decision decideCheckin(GuestState state) {
Map<String, Boolean> facts = new LinkedHashMap<>();
facts.put("paid", state.paid());
facts.put("booking_exists", state.bookingExists());
facts.put("room_available", state.roomAvailable());
boolean allow = facts.values().stream().allMatch(v -> v);
List<String> failing = new ArrayList<>();
for (var entry : facts.entrySet()) {
if (!entry.getValue()) failing.add(entry.getKey());
}
return new Decision(allow, failing);
}
// main(...) prints the table — see HotelCheckinLogic.java
}
The actual output
Verified output from java HotelCheckinLogic.java (identical to the Python run):
GUEST DECISION FAILING FACTS
-------------------------------------------------------
G-1 ALLOW CHECK-IN none
G-2 ESCALATE / DENY paid
G-3 ESCALATE / DENY room_available
G-4 ESCALATE / DENY booking_exists
G-5 ESCALATE / DENY paid, booking_exists, room_available
The rule never changes. Only the facts do.
That is the entire idea behind Boolean logic as a computing substrate.
The lesson carries over unchanged: a record and a LinkedHashMap replace a dataclass and a dict, but the shape of the reasoning — fixed facts, fixed rule, deterministic output — is exactly what Boole and, a century later, digital logic gates made possible.