Hey friend! Java 17 is now available, the latest Long Term Support (LTS) release. I know you rely on Java for work – should you upgrade? What improvements does Java 17 offer?
This guide will break it down, with facts, examples, and advice to understand if and when moving to Java 17 makes sense.
Java runs on over 3 billion devices according to Oracle. But many systems still use older versions. Per Snyk, 38% of Java projects on GitHub target Java 8 and only 6% target Java 11 or newer.
| Java Version | Usage % |
|---|---|
| Java 8 | 38% |
| Java 11 | 6% |
Upgrading requires planning, but Java 17 has changes that make that effort worthwhile…
What‘s New in Java 17
Java 17 adds some major new capabilities:
macOS Support Improved
Java now works better on Macs with M1 ARM chips! This was an annoying gap after Apple switched to their own silicon.
Official support means your Mac apps can leverage the native speed of Apple‘s new chips.
Tighter Control Over Class Hierarchies
Ever struggled with subclasses wrecking abstraction boundaries in your code? Java 17 adds "sealed classes" to constrain subclassing.
For example, you could limit a Shape base class to just Circle, Square, Triangle subclasses. No pesky Pentagon allowed!
This makes your architecture more robust. Subclasses are restricted to what you explicitly permit.
Vectorized Code Made Easier
Looping over arrays element-by-element can be slow in Java. Some C/C++ libs use vector instructions (like SSE/AVX) for big speedups.
But that requires platform-specific native code. With the new vector API, you can write vectorized computations portably in Java itself. The compiler handles making it fast across hardware.
This makes it much easier to optimize performance-critical chunks!
Calling Native Code Simplified
Integrating Java with native code has always been messy. Now the foreign function API allows calling C functions directly without boilerplate wrappers.
You can even safely access native memory from Java with proper type safety. This makes working with low-level code far less error-prone.
According to Java expert Venkat Subramaniam, this API is "going to change the way we code in Java".
Changes and Removals
Java 17 also removes some outdated functionality:
Tighter Module Boundaries
Ever relied on reflection hacks to peek into Java internals? That gets harder in Java 17 with restricted access enforcements.
Internal implementation details are now completely encapsulated. While this may break some old code, it improves maintainability and security.
Outdated Applet API Gone
Remember old Java browser applets? This obsolete API has been removed after being deprecated for years.
Good riddance to annoyances like the applet security sandbox!
Contentious Security Manager Retired
The Java Security Manager provided a restrictive sandbox model but was often impractical. After deprecation in Java 12, it‘s now removed in 17.
While this could impact very security-conscious environments, modern alternatives like Docker provide better isolation. Most found the Security Manager too limited.
According to analysts at Gartner, this removal may cause "one of the biggest process changes in application migration".
What‘s on the Horizon
Java 17 includes some experimental features to watch:
Pattern Matching Expands
Building on Java 16, Java 17 previews pattern matching support in switch blocks. This lets you combine conditions, casts, and variable assignments for cleaner code:
String result = switch(shape) {
case Circle c -> "It‘s a circle";
case Square s -> "It‘s a square";
}
As this feature develops, expect it to expand to arrays and records.
Incubator APIs
I won‘t get too deep in the weeds, but Java 17 introduces APIs for low-level operations like the vector API and foreign function API.
These are still evolving but lay the foundation for unlocking new capabilities and optimizations in Java.
Exciting stuff for geeky programmers like us!
Recommendations for Upgrading
So should you jump to Java 17? Here is my advice:
For New Projects
If starting from scratch, definitely use Java 17! You get access to the latest performance, features, and support.
For Existing Projects
Upgrading takes work. Make sure the libraries you rely on support Java 17 first. Check for compatibility issues.
Consider migrating in stages – upgrade a few services at a time to limit risk. Use Docker images to test Java 17 without impacting old systems.
If Stuck on Java 8/11
Java 17 offers many enticing improvements. But if you can‘t upgrade everything yet, try adopting some features gradually.
Get started with preview capabilities using flags. Experiment with new APIs on non-critical paths first.
While a total migration will take planning, you can still benefit from Java 17!
The Bottom Line
Java 17 is a major upgrade packed with useful enhancements. The vector API, foreign function API, sealed classes, and switch pattern matching are especially exciting.
Compatibility concerns may prevent immediate wholesale migration. But with Java 17 being a long term release, it‘s worth evaluating and gradually adopting new features.
Let me know if you have any other questions! I hope this overview helps you navigate Java‘s evolution. The language continues getting better after over 20 years.
Happy coding!