2 min read

Java Interview Questions (series) - Java Updates

Java Interview Questions (series)  - Java Updates

Intro

In a usual Java interview, there will be a moment where the interviewer will think:

Does this guy/girl really knows what means when saying that they want to use new technologies and don't really look forward to work with Java 8?

Or is it just a thing that they heard elsewhere and don't really know why and what new features have been added in the last (almost) 9 years.

💯  Even more, knowing what changed and the new features that appeared proves that you are interested in your field of work!

New features

❗️ Notes

1️⃣   LTS stands for Long Time Support version.

The support interval for an LTS version is usually 8 years.

For Java 8, though, because of its huge adoption, the support time was extended to at least 2030.

2️⃣  Preview feature - Features that are added for developers to play with, but are not production-ready. This means that they can be removed or made permanent in future releases.

🔵  Java 8 (LTS)

Java 8 was released in March 2014 and brought several new features and improvements to the language.

🔸 Streams API

🔸 Lambda expressions

🔸  Optional - Brings in a new way to handle null variables.


🔵  Java 9

Java 9 was released in September 2017 and brought a number of major changes to the language.

🔸  Modular System – Jigsaw Project - Provides a way to run applications on devices with low available memory. The JVM can run only with the required modules.

🔸  Interface Private Method - used to divide large default methods.

🔸  Immutable Set - Set.of()


🔵  Java 10

Java 10 was released on March 20, 2018.

Among improvements that arrived with it we can list:

🔸  Local Variable Type Inference - allows developers to use the var keyword to infer the type of a local variable.

🔸  Optional.orElseThrow() - NoSuchElementException thrown if no value is present.


🔵  Java 11 (LTS)

Java 11 was released in September 2018.  Along improvements, we can mention:

🔸  New String methods ( isBlank, lines, strip, etc.)

🔸  New File methods ( writeString, readString)

🔸  Collection.toArray()

🔸  Not Predicate

🔸  HTTP Client - Introduced in Java 9 as a preview feature. Became a standard feature in Java 11.


🔵  Java 12

Java 12 was released in March 2019 and brought new preview features.

🔸 New Switch syntax

boolean isBird = switch (animal) {
    case "PIDGEON", "PENGUIN", "EAGLE" -> true;
    case "DOG", "CAT" -> false;
    default -> throw new IllegalArgumentException("Don't know what a " + animal + " is.");
};

🔸 Text Blocks - A nicer way to write large text chunks.

    String text = """
                Text
                Block
            """;

🔵  Java 13

Java 13 was released in September 2019. This JDK brought in:

🔸 Updates to Switch Expressions

🔸 Updates to Text Blocks


🔵  Java 14

Java 14 was released in March 2020.

🔸 Records - new type of object designed for DTOs.

public record PersonData(String firstName, String lastName) {}

🔸 Specific NullPointerExceptions - From this version forward, you'll know which object was actually null.

public record PersonData(String firstName, String lastName) {}

...
PersonData personData = null;
personData.getFirstName(); // this line will throw a NullPointerException 

// Error message
// Cannot invoke "PersonData.getFirstName()" because the return value of "java.util.List.get(int)" is null

🔵  Java 15

Java 15 arrived in September 2020 and brought in:

🔸 Updates to Records

🔸 Sealed Classes


🔵  Java 16

Java 16 was released on March 2021. Important updates are

🔸 A new method added to Stream API -> .toList()

🔸 Updates to Records


🔵  Java 17 (LTS)

Java 17 was released in September 2021.

Along some other updates in some preview features, the most important update was the change in the release model.

Previously, LTS versions were coming 3 years apart, where now it was changed to 2.

That means that the next LTS version should be Java 21 which is planned to come about in September 2023.