Part II — Modern Java Language

This part covers the language constructs and type system features that represent modern Java, focusing on clarity, safety, and expressiveness while avoiding legacy constructs.

What You'll Learn

Explore the language features that define contemporary Java development: records for immutable data structures, sealed types for controlled inheritance hierarchies, and pattern matching for expressive, type-safe code that's both elegant and performant.

Chapters in This Part

Chapter 3. Syntax and Type System

Transition from legacy Java syntax to modern language features that improve clarity and safety. Master type inference with var, explore enhanced switch expressions that go beyond simple value matching, and leverage text blocks and string templates for readable, maintainable code.

Chapter 4. Classes, Records, and Sealed Types

Revolutionize your design patterns with records—boilerplate-free immutable data carriers—and sealed types that define exhaustive, controlled inheritance hierarchies. See real-world examples of order management systems, pricing tiers, and Spring service integration that showcase the elegance of modern modeling.

Chapter 5. Pattern Matching

Embrace pattern matching to write more expressive and type-safe code. Combine instanceof patterns with switch expressions to eliminate casts and reduce defensive coding, making your logic more declarative and easier to understand at a glance.

Chapter 6. Collections and Streams

Master modern collection APIs and the Streams framework for functional, declarative data processing. Learn performance-conscious stream operations, understand when to use collectors, and explore the latest utility methods that simplify common tasks.

Chapter 7. Exceptions and Error Handling

Handle errors in the modern era with structured, readable exception handling strategies. Understand sealed exceptions, custom exception types, and patterns that distinguish between recoverable and non-recoverable errors cleanly.