Modern Java in Action • Nicolai Parlog • GOTO 2024

Explore modern Java features like records, sealed types, virtual threads, and pattern matching. Learn how to write more concise, safer, and scalable code with Java's latest capabilities.

Key takeaways
  • Records provide a concise way to create immutable data classes with automatically generated constructors, accessors, equals/hashCode methods

  • Sealed interfaces/classes restrict which types can implement/extend them, providing better type safety and pattern matching capabilities

  • Virtual threads enable high scalability by allowing many concurrent operations without using actual OS threads

  • Structured concurrency helps manage multiple concurrent tasks by organizing them in hierarchical task scopes that handle cleanup

  • HTTP client API (since JDK 11) provides a modern way to make HTTP requests with features like async operations and configurable timeouts

  • Pattern matching with switch expressions allows cleaner type-based control flow compared to instanceof checks

  • Modern Java features enable clear separation between domain model (using records) and operations (using sealed interfaces)

  • Simple file server and web server APIs are now included in the JDK for basic development needs

  • String templates and unmodifiable collections (via List.of, Set.of etc.) improve code readability and safety

  • Compact constructors in records allow validation while keeping the concise syntax