Java for the Real World
University teaches Java with toy examples: Car extends Vehicle, Animal -> Dog, Box<T>. They are easy to draw on a whiteboard and useless everywhere else, and some quietly teach habits you then have to unlearn on the job. This book re-teaches the standard syllabus with examples from software people actually ship: a payment gateway for interfaces, notification types for polymorphism, a Repository<T, ID> for generics, an HTTP retry for exceptions. Each chapter names why the textbook example misled you and shows what an experienced engineer writes instead. Plain Java 21, no framework, every chapter a runnable Maven module. Co-authored with Ata Turhan.
Coming Soon
What you'll learn
When inheritance actually earns its place, and why composition is the tool to reach for first
Interfaces as seams: the most important word in real Java, shown on a payment gateway
Polymorphism that ends the if/instanceof chain instead of demonstrating a zoo
Generics, bounded types, and wildcards (PECS) without the Box<T> jargon
The equals/hashCode contract, and the broken version that silently loses HashMap lookups
null and Optional: the billion-dollar mistake and how to model absence honestly
Records, sealed types, and pattern matching as a sum type the compiler checks
Exceptions: throw deep, catch once at the boundary, and how to read a stack trace
Lambdas and streams, and the loops that still read better than a pipeline
Dependency injection by hand, so you feel the work a container automates
Testing with JUnit 5 from zero, and reading a failing test
Why shared mutable state bites, and confinement, atomics, and locks that fix it
Table of Contents
29 chapters · one concept per chapter
- 01 Classes & Objects: What "State" Actually Means
- 02 Encapsulation Beyond Getters and Setters
- 03 Inheritance: The Tool You Were Told to Reach For First
- 04 Composition: The Tool You Should Reach For First
- 05 Interfaces: The Most Important Word in Real Java
- 06 Abstract Class vs Interface: How Seniors Choose
- 07 Polymorphism: Dispatch Without if/instanceof Chains
- 08 Enums: More Than a List of Constants
- 09 static: The Keyword That Hides a Design Smell
- 10 Generics: Not a Box<T> Trick
- 11 Bounded Types and Wildcards: PECS Without the Jargon
- 12 Collections: Picking the Right One
- 13 equals and hashCode: The Contract That Breaks HashMap
- 14 Comparable vs Comparator: Sorting Like You Mean It
- 15 null and Optional: The Billion-Dollar Mistake and the Fix
- 16 Immutability and final
- 17 Records: Data Classes Done Right
- 18 Sealed Types: Closed Sets the Compiler Enforces
- 19 Pattern Matching: The End of instanceof Chains
- 20 Exceptions: When to Throw, When Never to Swallow
- 21 Reading a Stack Trace
- 22 Lambdas and Functional Interfaces
- 23 Streams: Powerful, and Where They Go Wrong
- 24 java.time: Dates Without the Calendar Pain
- 25 Package Structure and Naming: Where Code Actually Goes
- 26 Dependency Injection by Hand: What Spring Does for You
- 27 Testing: What's Worth Testing, and Reading a Failing Test
- 28 Concurrency, Gently: Why Shared Mutable State Bites
- 29 Where to Go Next: The Bridge to Modern Java and the Spring Series