What’s new in Java

A glimpse into the world of Spring Boot 3, Spring 6, and Java 17+

– by Brayden Prestwich –

With constant updates happening in the tech world, it can be hard to keep up and keep track of all the latest improvements software faces. Today, I’m here to share new insight and offer a look into the specific world of Spring Boot 3, Spring 6, and Java 17+.

My study of these technologies first began when I discovered Bryan Hansen’s insightful Pluralsight Course. If you’re like me, and want a more in depth analysis of the change, I recommend watching his course. This blog however is to provide a quick overview of the changes, why you should pay attention to them, and a tips for upgrading your existing apps.

Why should I care?

Before we really jump in, I do want to acknowledge a pertinent question that may have crossed your mind: “Why should we care?” It’s a legitimate question and the previous changes lately in both Spring and Java often seemed like surface-level adaptations in response to emerging technologies like Kotlin. However, allow me to present a counterargument.

Spring 6 and Spring Boot 3’s exclusive support for Java 17 signifies a pivotal shift. Those seemingly minor updates from Java 8 to 17 have collectively transformed Java for the better. What’s more, they’re quickly becoming interview essentials for innovative teams adopting Spring 6 and Spring Boot 3. Embracing these changes is not just prudent; it’s also remarkably accessible. A few hours of study or even a viewing of the Pluralsight Course mentioned earlier, equips you to effortlessly harness these enhancements as they become mainstream. It is also important to note that Java 21, a new LTS version, was also recently released on September 19, 2023. While we won’t be covering Java 21 much in this blog, you can learn more about its features in our informative Java 21 Webinar.

What’s new in Java?

Many teams I’ve encountered tend to stick with Java 11 or Java 8, both of which are LTS (long-term support) versions and excellent choices for production applications. However, Java has seen a slew of new features added in recent years, making it worthwhile to consider an upgrade.

Here is a short list of the new things in Java 17 you should know about:

  • Records: Records are a new type of class designed to be lightweight and easy to use. They provide a concise way to represent data, and can be used to improve the performance and readability of your code. Records are immutable by default, which can help to improve the safety and security of your code.
  • Sealed classes: Sealed classes are a new way to restrict the subclassing of a class. This can be used to improve the safety and security of your code. Sealed classes can be used to create a hierarchy of classes where only certain classes are allowed to extend or implement a particular class. This can help to prevent unauthorized extensions, which can lead to security vulnerabilities.
  • Switch expressions: Switch expressions are a new way to write switch statements. They are more concise and expressive than traditional switch statements, and they can be used to improve the readability of your code. Switch expressions also allow you to assign values to variables directly within switch cases, which can make the code more concise and eliminate the need for break statements.
  • Pattern matching for switch statements: Pattern matching for switch statements is a new preview feature in Java 17. It allows you to match against patterns in switch statements, which can be used to improve the readability and safety of your code. Pattern matching can be used to simplify complex conditional logic and make your code more concise and expressive.
  • Foreign Function and Memory API (incubator): The Foreign Function and Memory API is a new API that allows Java applications to access code from outside the JVM. This can be used to improve the performance of your applications by offloading tasks to native code. The Foreign Function and Memory API is still in the early stages of development, but it has the potential to significantly improve the performance of Java applications.
In addition to these new features, Java 17 also includes a number of other improvements, such as:
  • Improved performance
  • Improved security
  • Improved stability

If you are considering upgrading to Java 17, I recommend that you read the Release Notes to learn more about the new features and improvements. You can also find a number of tutorials and articles online that can help you get started.

What’s New in Spring Boot 3 and Spring 6

Spring Boot 3 brings a host of exciting updates and improvements to enhance your development experience. Here’s a closer look at some of the key features:

  • Java 17 baseline: Spring 6 is based on Java 17, which is the latest LTS version of Java. This means that Spring 6 will be supported for at least 8 years, which gives you peace of mind when building your applications.
  • Improved performance: Spring Boot 3 has been optimized for performance, with improvements in areas such as startup time, memory usage, and garbage collection.
  • Support for Jakarta EE 10: Spring 6 and Spring Boot 3, don’t just support Jakarta EE 10, they were designed with Jakarta EE 10 in mind. This is one of the bigger changes that you will likely have to make to your existing projects to get them upgraded and inline with where the industry is heading.
  • AOT (Ahead-of-Time) compilation: Spring 6 provides built-in support for AOT compilation, which can significantly improve the startup time and memory consumption of your applications. AOT compilation is a process that converts Java bytecode into machine code, which can be executed directly by the operating system. This can be a major advantage for applications that need to start up quickly or that need to be very memory efficient.
  • Support for GraalVM native images: Spring Boot 3 now supports GraalVM native images, which can be used to create native executables of your Spring Boot applications.
  • Improved observability:  Spring 6 and Spring boot 3 provides built-in support for Micrometer and Micrometer Tracing, which are open source libraries for collecting and exporting metrics and traces from your applications. This makes it easier to monitor and troubleshoot your applications.
  • ProblemDetails API: Spring 6 introduces the ProblemDetails API, which is a standard way to represent errors in HTTP APIs. This can be helpful for improving the interoperability of your applications and for making it easier for users to understand and troubleshoot errors.
  • Improved Security: Security is a top priority, and Spring 6 and Spring Boot 3 introduces improvements to ensure your applications remain resilient against evolving threats.
  • Improved Documentation: Clear and comprehensive documentation is crucial for any framework, and Spring and Spring Boot continues to refine and expand its documentation to provide developers with the resources they need.
  • Improved Testing Support: Testing is a fundamental part of the development process, and Spring 6 and  Spring Boot 3 enhances testing support to help you write robust and reliable tests for your applications.

Tips for upgrading your app

Use Spring Boot’s new Migration Tool and follow the readme instructions carefully – it is pretty helpful. Also make sure you don’t have your application running on 8080 as that is the port the migration tool will run on.

In Spring Boot 3, you don’t need to include Jakarta.servlet as a separate dependency; it’s automatically included. If you encounter an error related to this, it’s likely because some of your dependencies are still using the older javax package instead of Jakarta. Notably, Springfox, commonly used for Swagger, is an example of this. Unfortunately, there isn’t currently a compatible version of Springfox for Spring Boot 3, and it’s unlikely to receive updates.

To continue using Swagger, I recommend transitioning to Spring Docs, which is a good choice regardless. To do this, simply remove your Springfox configuration and dependencies and replace them with Spring Docs. View Documenting a Spring REST API Using OpenAPI 3.0 to find a step by step easy implementation guide.

If you encounter dependency errors, it’s possible that the new spring boot migrator might have overlooked some of the dependencies you need to upgrade. If you see errors related to a specific dependency, consider researching the version it requires to function seamlessly with Spring Boot 3, before digging in too deep on the error.

We’ve covered a lot about what is new in Java, so now it’s your turn to dive in and explore on your own! If you have any questions, thoughts, or insights to share, please reach out to our team via our Contact Us Page or on any of our Social Media Channels, we’d love to hear from you. Remember, the world of tech is ever-evolving, and staying updated is the key to success. Until next time, happy coding!