eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – LJB – NPI EA (cat = Core Java)
announcement - icon

Code your way through and build up a solid, practical foundation of Java:

>> Learn Java Basics

Partner – LambdaTest – NPI EA (cat= Testing)
announcement - icon

Distributed systems often come with complex challenges such as service-to-service communication, state management, asynchronous messaging, security, and more.

Dapr (Distributed Application Runtime) provides a set of APIs and building blocks to address these challenges, abstracting away infrastructure so we can focus on business logic.

In this tutorial, we'll focus on Dapr's pub/sub API for message brokering. Using its Spring Boot integration, we'll simplify the creation of a loosely coupled, portable, and easily testable pub/sub messaging system:

>> Flexible Pub/Sub Messaging With Spring Boot and Dapr

1. Overview

Java 20, released on the 21st of March 2023, is the latest short-term incremental release built on Java 19 as of today. It consists of the seven important JDK Enhancement Proposals (JEPs) mentioned in JEP 2.0. The JEP process is used to evaluate proposals for enhancements to the JDK. The majority of the updates in Java 20 are improvements or enhancements to the features introduced in earlier releases.

Moreover, Oracle JDK 20 isn’t a long-term support release. Therefore it will receive updates until the release of Java 21.

In this article, we’ll explore some of these new features.

2. Scoped Values (JEP 429)

A large number of Java applications have components or modules that need to share data among themselves. Often, these modules are thread based, so we must protect the data they share from any change.

We’ve been using variables of the type ThreadLocal to allow components to share data.

But it has some consequences:

  • A ThreadLocal variable is mutable. The ThreadLocal API allows access to both get() and set() methods of its variable type.
  • We may face memory leak issues since the value of the ThreadLocal variables is retained until we explicitly call the remove() method on it or the thread exits. Thus, there’s no binding to the lifetime of these per-thread variables.
  • They may lead to excessive memory footprints in case of using large numbers of threads. This is because the child threads can inherit the ThreadLocal variables of parent threads, thus allocating memory for every ThreadLocal variable.

To overcome these problems of ThreadLocal variables, Java 20 has introduced scoped values for sharing data within and across threads.

Scoped values provide a simple, immutable, and inheritable data-sharing option, specifically in situations where we’re working with a large number of threads.

A ScopedValue is an immutable value that is available for reading for a bounded period of execution by a thread. Since it’s immutable, it allows safe and easy data-sharing for a limited period of thread execution. Also, we need not pass the values as method arguments.

We can use the where() method of the class ScopedValue to set the value of a variable for the bounded period of thread execution. Moreover, once we get the data using the get() method, we cannot access it again.

Once the run() method of a thread finishes execution, the scoped value reverts to the unbound state. We can use the get() method to read the value of a scoped-value variable inside a thread.

3. Record Patterns (JEP 432)

JDK 19 had already introduced Record Patterns as a preview feature.

Java 20 delivers an improved and refined version of record patterns. Let’s see some of the improvements in this release:

  • Added support for type inference of arguments of generic record patterns.
  • Added support for record patterns to be usable in the header of an enhanced for loop.
  • Removed support for named record patterns, where we could provide an optional identifier to the record patterns that we can use to refer to the record pattern.

This release essentially aims to express more improved, composable data queries with pattern matching while not changing the syntax or semantics of type patterns.

4. Pattern Matching for Switch (JEP 433)

Java 20 provides a refined version of pattern matching for switch expressions and statements, specifically about the grammar used in switch expressions. It was first delivered in Java 17, followed by some improvements in Java 18 and 19, thus expanding the usability and applicability of switch statements and expressions.

The main changes in this release include:

  • Using a switch expression or a pattern over an enum class now throws a MatchException. Earlier, we used to get an IncompatibleClassChangeError if no switch label was applied at run time.
  • There are improvements in the grammar for switch labels.
  • They have added support for type-inference of arguments for generic record patterns in switch expressions and statements, along with the other constructs that support patterns.

5. Foreign Function and Memory API (JEP 434)

Java 20 incorporates the improvements and refinements to the Foreign Function and Memory (FFM) API that were introduced in the previous Java versions. This is a second preview API.

The Foreign Function and Memory API allow Java developers to access code from outside the JVM and manage memory out of the heap (i.e., memory not managed by the JVM). The FFM API aims to provide a safe, improved, and pure Java-based substitute to Java Native Interface (JNI).

It includes the following refinements:

  • The MemorySegment and MemoryAddress abstractions are unified. This means that we can actually determine the range of memory addresses associated with a segment from its spatial bounds.
  • They’ve also facilitated the use of pattern matching in switch expressions and statements by enhancing the sealed MemoryLayout hierarchy.
  • Moreover, they’ve split the MemorySession into Arena and SegmentScope to facilitate sharing segments across maintenance boundaries.

6. Virtual Threads (JEP 436)

Virtual threads were first proposed as a preview feature in JEP 425 and delivered in Java 19. Java 20 proposes the second preview aiming to gather more feedback and improvement suggestions after the use.

Virtual threads are lightweight threads that reduce the effort of writing, maintaining, and observing high-throughput concurrent applications. Thus, it makes it easy to debug and troubleshoot the server applications with existing JDK tools. This could be useful in the scaling of server applications.

However, we should note that the traditional Thread implementation still exists, and it doesn’t aim to replace the basic concurrency model of Java.

Below are a few of the minor changes since the first preview:

7. Structured Concurrency (JEP 437)

Structured Concurrency was proposed by JEP 428 and delivered in JDK 19  as an incubating API. This JEP proposes to re-incubate the API without much changes in JDK 20. Thus it allows time for more feedback.

The goal is to simplify multithreaded programming by introducing an API for structured concurrency. It improves reliability by grouping multiple threads doing similar tasks into a single unit of work. As a result, there’s improved error handling and thread cancellations. Additionally, it promotes an improved way of concurrent programming aiming to protect from common risks arising from thread cancellation.

However, there’s one change in this re-incubated API. We get an updated StructuredTaskScope that supports the inheritance of scoped values by threads created in a task scope. Thus, we can now conveniently share immutable data across multiple threads.

8. Vector API (JEP 438)

The Vector API was first proposed by JEP 338 and integrated into JDK 16 as an incubating API. This release (fifth incubator) is a follow-up of multiple rounds of incubations and integrations into all the previous Java versions.

The Vector API is used to express vector computations within Java on supported CPU architectures. A vector computation is actually a sequence of operations on vectors. The Vector API aims to provide a means of vector computations that are more optimal than traditional scalar computations.

This release doesn’t introduce any change to the API compared to Java 19. However, it includes a few bug fixes and performance enhancements.

Finally, development in the Vector API is closely aligned with Project Valhalla since it aims to adapt Project Valhalla’s enhancements in the future.

9. Conclusion

Java 20 incrementally builds on several features of past releases, including record patterns, pattern matching for switch expressions, FFM, virtual threads, and more. It also adds a new incubating feature like scoped values and some enhancements on re-incubating features like structured concurrency and Vector API.

In this article, we discussed some of the features and changes introduced as part of the incremental Java 20 release. The complete list of changes in Java 20 is in the JDK release notes.

Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

eBook Jackson – NPI EA – 3 (cat = Jackson)