Looking at Java 21: Switch Pattern Matching

The switch control structure has quite an evolution lately since its inception. First, there were switch expressions (JEP 325, 354, 361). And now, we get pattern matching for switch statements and expressions!

Looking at Java 21: Scoped Values

Today we look at Scoped Values, another interesting preview feature that’s incubating since Java 20 (JEP 429). It’s a new way to store and share immutable data with a bounded lifetime within a thread and its child threads.

Looking at Java 21: Sequenced Collections

Dealing with Collections is improving with Java 21, as three new interfaces get retro-fitted right into the existing type hierarchies. These Sequenced Collections give us a uniform API to access the first and last elements, and process Collections in reverse.

Looking at Java 21: Simpler Main Methods and Unnamed Classes

Java’s known (and often criticized) for its vast amount of required boilerplate and ceremony for perceived mundane tasks, at least compared to other languages. Despite the “war on boilerplate” not being the primary goal of most new features, it’s often a side effect of new additions to the language, like Records. The preview JEP 445, however, is explicitly targeted to make the first introduction to Java a breeze: simpler main methods and unnamed classes.

Looking at Java 21: String Templates

Java’s String type is a ubiquitous type that’s used in every program out there. It’s so omnipresent, we often don’t think much about it, and take it as a given. However, over the years, it received many improvements, like better optimization possibilities and multi-line blocks. And now, another exciting improvement is coming that makes String safer and easier to use: String templates.

Featured on