New switch expressions, friendly NPEs and more

Image for post
Image for post
Photo by Yogesh Pedamkar on Unsplash

Java 14 is released on March 17th, 2020. Let’s take a look at what is inside, and what makes new Java different from the older versions. Here is an overview of the major updates:

  • Switch Expressions
  • Helpful NullPointerExceptions
  • Packaging Tool (Incubator)
  • Language preview features: Pattern Matching for instanceof, Records, Text Blocks
  • Garbage collection: ZGC on macOS and Windows, NUMA-Aware Memory Allocation for G1, Remove the Concurrent Mark Sweep (CMS) Garbage Collector, Deprecate the ParallelScavenge + SerialOld GC Combination,
  • Removal and deprecation: Deprecate the Solaris and SPARC Ports, Remove the Pack200 Tools and API
  • Other: Foreign-Memory Access API (Incubator), Non-Volatile Mapped Byte Buffers, JFR Event…


With many examples

Image for post
Image for post
Photo by Karim MANJRA on Unsplash

Java 14 is going to be released on March 17, 2020. The new version of Java contains an interesting update to the Java language: new switch expressions. Let’s see how the new switch expressions can be used, what kind of advantages they offer, and what can potentially go wrong. In the end, we’ll tackle a tricky question about switch expressions.

The Classic ‘Switch’ Statement

The current design of the switch statement in Java follows languages such as C and C++. It works only as a statement and supports fall-through semantics by default. Here’s an example of the classic switch statement with an enum:

You might have noticed many case and break statements in the example above. …


16 major enhancements, 2400 bug fixes, and more

Image for post
Image for post
Photo by Fab Lentz on Unsplash

Java 14 is going to be released on March 17, 2020. Besides ~2,400 bug fixes and small enhancements, the new version of Java contains 16 major enhancements, also called JEPs (Java Enhancement Proposals).

Let’s take a closer look at the major updates in Java 14: new switch expressions, better NullPointerExceptions, improvements in garbage collection, JFR event streaming, and more.

Image for post
Image for post
Image source: Author

Switch Expressions

This update to the Java language was already available in Java 12 and 13 but only as a preview language feature, which means it was not enabled by default. Finally, the new switch expressions are released in Java 14. …

About

Artem Smotrakov

I write about Java and security

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store