Today’s the first day of Java 21’s availability! It’s been six months since Java 20 was released, so it’s time for another fresh wave of Java features.
Exploring Java Records In A Jakarta EE Context
This article explores the adoption of Java Records in a Jakarta EE application as a data transfer and projection object.
It’s Java 20 Release Day! Here’s What’s New
In this article, we will take you on a tour through all JEPs that come with this release and give you a brief introduction of each one of them.
How to Best Use Java Records as DTOs in Spring Boot 3
Explore how to best use compact Java Records as Data Transfer Objects (DTOs) for database and API calls in Spring Boot 3 with Hibernate 6 as the persistence provider.
Foojay Podcast #5: OpenJDK 19 Discussion Panel
It’s September 20th, OpenJDK 19 has been released. In this podcast, we discuss the new features and the changes that this release brings.
What Can We Expect In OpenJDK 19?
Although the Java 19 release is coming in September (2022-09-20), we already know what will happen in that release!
Avoid Multithreading Bugs Using Immutable Java 16 Records
In a multi-threaded Java application, any thread can change the state of an object.
The Java memory model in Java language specification specifies when exactly updates made by one thread are going to be visible to other threads.
This is one of the biggest problems professional Java developers deal with every day.
Java records are immutable. An object is considered immutable if its state cannot change after it is constructed. The immutable nature of records eliminates problems of its usage in a multithreaded environment.
Java 16 and IntelliJ IDEA
If you are still working with Java 8, you might have mixed feelings about the news of the release of Java 16. However, you’ll see these numbers are going to increment at a much faster and predictable rate with Java’s six-month release cadence.
I’m personally excited about Java 16! It adds Records and Pattern Matching for instanceof as standard language features with Sealed classes continuing to be a preview feature (in the second preview).
Fun fact – Records was voted the most popular Java 16 language feature by 1158 developers in this Twitter poll, with Pattern Matching for instanceof second.
In this blog post, I will limit coverage of Java 16 to its language features, why you need them, and how you can start using them in IntelliJ IDEA. You can use this link for a comprehensive list of the new Java 16 features. Let’s get started.
Java 16 Records: Data Carrier Classes
Professional Java developers need immutable data carrier-classes for communication with databases and web Services. We need to write a lot of boilerplate code to create a simple data carrier-class, we typically implement constructor, accessors, equals(), hashCode(), and toString(). This process is repetitive and error-prone. Developers also complain “Java is too verbose”.
Record classes provide a way to model data in Java. An example of data is a row in a database table. This feature simplifies coding, makes Java code more concise and readable, increasing productivity for professional Java developers. Java14 introduced Records as a preview feature, Java15 brings in some updates as a second preview, and Java16 makes it a final feature, no changes will be needed for Records after this.
Spring Boot and Java 16 Records
On March 16th, 2021, Java 16 was GA. With this new release, tons of new exciting features are added. Check out the highlights here on Foojay to know more about these changes.
In this article, we’ll focus on Java Records, defined in JEP 395. Records were first introduced in JDK 14 as a preview feature, proposed by JEP 359, and with JDK 15 they remained in preview with JEP 384. However, with JDK 16, Records are now no longer in preview: they’re an official part of the Java language now.
I have picked Records because they are definitely the most favored feature added in Java 16, according to this Twitter poll by Java Champion Mala Gupta.
Highlights of New JEPs in Java 16
The JDK Enhancement Proposal (or JEP) is a community process for collecting proposals for enhancements to the OpenJDK.
Java 16, released today, incorporated the JEPs listed here.
And, on foojay.io, you’ll find a long list of all the fixes that made it into the release!