Modern Java in Action by Nicolai Parlog

Explore modern Java's powerful features: records, sealed types, virtual threads, pattern matching, HTTP client & more. Learn practical tips for building clean, scalable apps.

Key takeaways
  • Modern Java applications can leverage records for clean domain modeling and data representation, with built-in immutability and generated methods like equals/hashCode

  • Sealed interfaces allow defining strict type hierarchies and controlling which implementations are permitted, helping with exhaustive pattern matching

  • Virtual threads enable high scalability for I/O operations without managing thread pools manually - they’re lightweight and managed by the JVM

  • The modern HTTP client (added in JDK 11) provides a clean API for making HTTP requests with features like immutable builders and body handlers

  • Pattern matching with instanceof and switch expressions allows cleaner handling of different types and destructuring of data

  • Records support constructor chaining and validation through compact constructors while maintaining immutability

  • The module system improves encapsulation and dependency management, though requires some initial learning curve

  • Structured concurrency APIs help manage parallel task execution with proper parent-child thread relationships

  • Preview features (like structured task scope) allow early access to upcoming Java features for experimentation

  • The jwebserver and jpackage tools enable quick local development and native application packaging without external dependencies