Cruising Along with Java
Modernize and Modularize with the Latest Features
by Venkat Subramaniam
Java is on a fast-paced development schedule that brings with it
improved design capabilities and enhancements for application security.
Learn about the changes to Java, from version 9 to 19, and apply new
features to build enterprise applications faster and with fewer errors.
Get up to speed on how to make your code concise, expressive, and less
error prone, and create better OO programs with the newest features.
Modularize and create asynchronous applications with ease and proper
error handling. This book contains twelve chapters that dive deep into
the features, using plenty of examples for you to practice along with.
Java is changing quickly—don’t be left behind. This book will keep you
up to date on the amazing capabilities of the Java language introduced
between versions 9 and 19. Whether you are using Java 8 or one of the
newer versions of Java, this book will serve as your practical guide to
explore and apply the features in these versions of Java.
Learn to properly use type inference and avoid its pitfalls. Use text
blocks to write elegant multiline strings and embed XML and JSON
documents in code. Design better OO code with records and sealed
classes, and along the way, learn proper ways to apply these new ideas.
Reduce verbosity and hidden errors in code using switch expressions and
pattern matching syntax. Take your upgrade journey further by
modularizing your Java code, to make it more secure and manage
dependencies clearly. Leverage those capabilities to more easily and
dynamically discover services. Learn to create highly performant and
resilient asynchronous applications, using the brand new virtual threads
(fibers) and structured concurrency.
Don’t tolerate clumsy old Java code; instead, benefit from the
significant changes to the language in versions 9 through 19.
What You Need
To make use of all the features in this book, you’ll need at least Java
19.
Resources
Releases:
- B6.0 2024/11/22
- B5.0 2024/11/08
- B4.0 2024/03/12
- B3.0 2023/11/28
Note: Contents and extracts of beta books will change as the book is developed.
Preface
- The Evolution of Java
excerpt
- Syntax Sugar
- Using Type Inference
- Type Inference and Java
- Generics and Type Witness
- Diamond Operator Enhancements
- Lambda Expressions Parameters Type Inference
- Local Variable Type Inference
- Using Type Inference with for and try
- var: Not a Type nor a Keyword
- Targeted Intersection Types
- Extent of Type Inference
- Mind the Inference
- Wrapping Up
- Reducing Clutter with Text Blocks
excerpt
- From Noisy to Nice
- Embedding Strings
- Smart Indentations
- Trailing Spaces and Special Escapes
- Creating XML Documents Using Text Blocks
- Creating JSON Output Using Text Blocks
- Wrapping Up
- Design Aid
- Programming with Records
- From Verbose to Succinct
- Components, Fields, Getters, and Metadata
- Extent of Immutability
- Built-in Methods
- Implementing Interfaces
- Restrictions for the Greater Good
- Considering a Custom Canonical Constructor?
- Preferring the Compact Constructor
- Creating a Custom Non-Canonical Constructor
- (Local) Records as Tuples
- Wrapping Up
- Designing with Sealed Classes and Interfaces
- Need For a Closed Hierarchy
- Using sealed
- Sealed Related Metadata
- Using the permits Clause
- Constraints On the Subclasses
- Wrapping Up
- Fluent Expressions
- Switching to Switch Expression
excerpt
- From Statements to Expressions
- Using Multiple Labels in a Case
- Cases with Non-Expressions
- Completeness of a switch Expression
- Wrapping Up
- Using Powerful Pattern Matching
- Pattern Matching with instanceof
- Using Type Matching
- Matching null
- Guarded Patterns
- Dominance Check
- Completeness Check
- Completeness Check and Sealed Classes/Interfaces
- Deciding to Use default or Not
- Destructuring Records when Pattern Matching
- Type Inference with Destructuring Records
- Unnamed Variables in Pattern Matching
- Wrapping Up
- Modularization
- Modularizing Your Java Applications
- Maven, Gradle, and Modularization
- Modules and the Benefits of Modularization
- Modularized Java
- Starting with a Legacy Application
- Perils of the Existing Design
- Modularizing the Space Station Application
- Architectural Constraints Promoted by Modules
- Wrapping Up
- Working with Modules
- Exploring the Module Metadata
- Managing Transitive Dependencies
- Targeted Linking Using jlink
- Wrapping Up
- Creating Plug-ins with ServiceLoader
- The Plug-in Architecture
- Defining a Specification Module
- Creating a Client Module
- Implementing A Plug-in
- Implementing Additional Plug-ins
- Reloading the Implementations
- Functional Style Iteration
- Wrapping Up
- Custom Functional Pipeline Steps
- Extending Functional Pipelines with Gatherers
- Why Do We Need Gatherers?
- Creating Custom Steps Using the gather() Method
- Using Built-in Gatherers
- Wrapping Up
- Creating Custom Gatherers
- The Machinery Behind the gather() Method
- Flavors of Gatherers
- Creating Sequential Stateless Gatherers
- Creating Sequential Stateful Gatherers
- Creating Parallel Stateless Gatherers
- Creating Parallel Stateful Gatherers
- Wrapping Up
Author
Dr. Venkat Subramaniam is an award-winning author, founder of Agile
Developer, Inc., and an instructional professor at the University of
Houston. He has trained and mentored thousands of software developers in
the US, Canada, Europe, and Asia, and is regularly invited to speak at
international conferences. He’s the (co)author of multiple books,
including the 2007 Jolt Productivity award winning book Practices of
an Agile
Developer.