June 28th, 2024

Migrating from Java 8 to Java 17 II: Notable API Changes Since Java 8

The article details API changes in Java versions 9 to 17, emphasizing improvements for Java 8 migrations. Changes include null handling, performance enhancements, string improvements, switch expressions, record classes, and utility additions for developer productivity and code readability.

Read original articleLink Icon
Migrating from Java 8 to Java 17 II: Notable API Changes Since Java 8

The article discusses notable API changes in Java versions from 9 to 17, highlighting improvements for developers migrating from Java 8. Java 9 introduced Objects.requireNonNullElse for null value handling and convenient collection factory methods. Java 10 focused on performance enhancements and introduced Local-Variable Type Inference (var) and unmodifiable collection creation methods. Java 11 brought String and InputStream enhancements, including repeat() for strings and readNBytes() for controlled InputStream reading. Java 12 enabled running single-file source-code programs and introduced switch expressions. Java 14 standardized switch expressions with a new arrow syntax. Java 15 introduced Text Blocks and formatted methods for cleaner string handling. Java 16 introduced record classes to simplify data carrier classes and pattern matching for instanceof. Java 17 added utilities for hexadecimal binary data representation and ZoneId.ofOffset() for creating Zone IDs directly from offsets. These changes aim to enhance developer productivity and code readability across Java versions.

Related

The Prototype's Language

The Prototype's Language

The evolution of programming languages in payments technology sector is discussed, highlighting the shift from COBOL to Java and now to Python for its speed and adaptability. Language choice impacts developers and work quality.

Moving to Java 17 or how I learned to stop worrying and love NoSuchMethodError

Moving to Java 17 or how I learned to stop worrying and love NoSuchMethodError

Icon Solutions upgraded to Java 17 in IPF 2024.1 for Spring 6 and Spring Boot 3 compatibility. Challenges included plugin and dependency adjustments, emphasizing centralized management and code cleanliness post-upgrade for smoother transitions.

Huawei unveils its own programming language the "Cangjie"

Huawei unveils its own programming language the "Cangjie"

Huawei introduces "Cangjie" programming language at HDC 2024. Promises security, intelligence, and performance. To integrate with HarmonyOS for user-friendly development. Features AgentDSL, supports various styles, type inference, generics, pattern matching. Lightweight, scalable with new garbage collection for improved performance. Developers to explore benefits post-launch.

Interface Upgrades in Go (2014)

Interface Upgrades in Go (2014)

The article delves into Go's interface upgrades, showcasing their role in encapsulation and decoupling. It emphasizes optimizing performance through wider interface casting, with examples from io and net/http libraries. It warns about complexities and advises cautious usage.

JEP 401: Value Classes and Objects (Preview)

JEP 401: Value Classes and Objects (Preview)

JEP 401 introduces value classes and objects in Java, focusing on optimizing memory efficiency by distinguishing objects solely by their field values, not identity. This feature enhances performance for simple domain values.

Link Icon 4 comments
By @hn_throwaway_99 - 4 months
This is slightly random, but I couldn't help but "laugh in Java" when the very first feature shown, `Objects.requireNonNullElse`, is given with an example and text that states "This method helps streamline handling null values, removing the need for verbose null checks ." Except the version that uses `Objects.requireNonNullElse` is longer than the one that uses the ternary operator!

What is it with Java deciding "Why use 2 characters when 40 will do?" Is it to much to ask for a ?? or ?: operator?

By @sltkr - 4 months
I'm surprised by how verbose some of these new APIs are, like:

    Objects.requireNonNullElse(str, "default")
or even worse, if you need the right-hand side to be evaluated lazily:

    Objects.requireNonNullElseGet(str, () -> "default")
while Javascript's null-coalescing operator allows writing this so much simpler:

    str ?? "default"

    str ?? getDefault()
(And not to mention the fact that the null-coalescing operator can also be used for conditional assignment, for which Java has no option at all!)
By @RadiozRadioz - 4 months
I'm curious how often people upgrade their versions. What's your motivation for upgrading?

Personally I learned Java 7 when it was the latest, then stuck with it since. I'd prefer to continue on with the same thing, there's more depth than one person can learn anyway, than add more things.

These things look nice, but they're mainly add-on bits. The core language is still the same. Though streams are a bit more special.

By @zmmmmm - 4 months
This is such a paltry list for 9 version steps. It does not include things like the module system which are the biggest pain points in my experience.

Honestly I would not recommend anybody migrate from 8 to 17 anyway. 8 to 11 or 8 to 21 are much better choices, depending on your appetite for migration pain.