OS 003: Use Modern Java Constructs

OS-003 Remove usage of Google Guava Library

Date: 2020-01-01

Status

Implemented

Context

OS 003 head

JDK is released every six months to all Java developers. The latest approach is to release a long-term supported version every two years.

Better approaches support clean code, less verbose source code and reduce programming [5] [2]. These constructs shall be used in our modules as soon as they are released to the developers.

The advantage is better integration, always synchronized with the current release of the JDK and no incompatibilities. The drawback is that our clients have to use the current JDK released version.

The major advantage is that you are using the latest version you do not need to pay license fees for each server you have running. Older Oracle versions always require a support contract and associated fees. The other approach is to use an alternate distribution such as OpenJDK.

Decision

We use the current released JDK and all constructs provided in this JDK [1]. We use preview features and incubating functionality present in this JDK. The main advantages are

  1. Current JDK versions provide efficient and elegant implementation [3] [4]. See, for example, the record construct provided since JDK 14.

  2. The source code is legible and has fewer errors.

  3. Our developers are up-to-date with Java evolution and enjoy writing modern code.

JDK 18 and 19 give improvements in pattern matching and thread programming.

Consequences

  • Clients are forced to use the current JDK version.

  • Tooling is more brittle because a lot of tool maintainers are late to adapt the actual version of JDK.

Examples of New Features

  • The instanceof operator supports in conditional statement deconstruction.

  • The record construct simplifies data objects and encourages immutability.

  • The UncheckedIOException encourages the use of non-checked exceptions.

  • [1] tangly blog/2022/modernize-your-java-landscape/[Modernize your Java Landscape]

  • [2] tangly blog/2022/immutability-in-java/[Immutability in Java]

  • [3] tangly blog/2021/jdk-17/[JDK 17]

  • [4] tangly blog/2021/jdk-16/[JDK 16]

  • [5] tangly blog/2021/modern-java-development/[Modern Java Development]