This repository is a personal learning resource for me, covering the evolution of the Java language from version 8 to the latest Java 17. Explore new features, enhancements, and best practices, while I gain valuable insights into modern Java development.
From the readme, you can explore the evolution of the Java language from version 8 to the latest Java 17.
Below, you'll find links to various Java features and enhancements:
Java 9 introduced two methods for the List interface :
- List.of() allows you to create an immutable list of elements. This method cannot contains null values.
- In addition, List.copyOf() allows you to copy a collection of objects and return an immutable list as well. It's important to note that if you attempt to make a copy of an immutable list using List.copyOf(), it will create a reference to the same object. This method cannot contains null values.
Java 16 introduced toList() method directly on streams. This method returns a immutable list that can contain null values.
A sealed type in Java restricts which classes or interfaces can extend or implement it. It provides a controlled hierarchy, allowing you to specify a fixed set of permitted subtypes, which can enhance code security, maintainability, and ensure that all possible subtypes are known and handled within the codebase.
Java 12 introduced a new syntax for the switch statement and key word (yield), making it more concise and easier to read.
Java 14 introduced a new enhancement called "Pattern Matching for the instanceof operator" which simplifies the code when working with object types.
With the new syntax, you can create a variable within the if statement to increase readability :
Java introduced type inference since Java 10. They add the 'var' word (not a key word for backward compatibility) to initialize a variable.
Type inference doesn't work for class fields.
Record are introduce in Java to give a way to describe data. Records are a quick and concise because they automatically generates constructors, getter, equals and hash code methods. It’s important to note that records are immutable, so you can’t change their values after the initialization. And they cannot extends any class and cannot be extended too. Here is an example of a simple class called Player with 2 fields (approximately 65 lines), and a record of the same structure (approximately 10 lines).
In traditional Java code, multiline strings could be hard to write with lots of escape characters and concatenation.
With the introduction of text blocks in Java, working with multiline strings has become significantly more straightforward and readable.
Since Java 14, Java provides more informative details about the variable or expression that was null. This improvement facilitates quicker and more precise identification of the cause of a null reference, enhancing the debugging experience for developers