You are here
Home > java > Core Java >

Java Features After Java 8

Java Features After Java 8After Java 8, Java 9 has big changes & new features. Here in this section we will talk about Java Features After Java 8. If you are preparing for a Java developer interview, there are 100% chances that, you will find some questions about this topic. This article may work as a refresher for the interview.

You can learn about Java 8 Features from a separate article. We will update this section on a regular basis in case of a release of the new version. Let’s see Java Features After Java 8.

New In Java 9

Let’s start our topic ‘Java Features After Java 8’ with New Features in Java 9.

1) Java Platform Module System : Jigsaw Project
2) JShell Command Line Tool
3) Private Methods in Interfaces
4) Diamond Operator Extension
5) Improvements in Stream API
6) Introduction of  Factory Method of() for creating a Collection.
7) Small Modifications in Try-With-Resources
8) Мulti-Resolution Image API
9) HTTP 2 Client ( A new Client)
10) Platform and JVM Logging
11) Process API Updates
12) Multi-release JAR Files
13) @Deprecated Tag Changes
14) Stack Walking

New In Java 10 

1. Local Variable Type Inference : var x=10; allowed but var is not a keyword

var map= new HashMap<String,List<String>>(); is valid
var stream =List.stream(); is valid
var path = Paths.get(filename); is valid
var numbers= List.of(1, 4.5,”Java”); is valid

var s =null is not allowed.
var can’t be defined at class level, can’t be assigned to Lambda expression but can be defined inside lambda expression.

2. java.util.stream.Collectors has new method Collectors.unmodifiableList() to control list from modification. Similarly for Set & Map as well.

java.util.List, java.util.Map and java.util.Set each got a new static method copyOf(Collection). It returns the unmodifiable copy of the given Collection. An attempt to modify such a collection would result in java.lang.UnsupportedOperationException runtime exception.

3. Optional.orElseThrow() : 

java.util.Optionaljava.util.OptionalDoublejava.util.OptionalInt and java.util.OptionalLong, each got a new method orElseThrow() which doesn’t take any argument and throws NoSuchElementException if no value is present:

4. Garbage collector changes
5. Some methods deprecated.

Note: Java 10 was the last free Oracle JDK release that we could use commercially without a license. Starting with Java 11, there’s no free long-term support (LTS) from Oracle.

New In Java 11

Note that from Java 11 Oracle has updated the license term to use only for developing, testing, prototyping, demonstrate your application. You may not use the programs for data processing or any commercial, production or any internal business purposes.
Subscription plan was already in place on yearly or one time payment basis but they have given option of monthly subscription now.
In summary Java is free for personal & non-commercial use always.

Added Features:

1. Collection.toArray(IntFunction) default method : The java.util.Collection interface got a new default toArray() method which takes an IntFunction argument in order to make it easier to create an array of the right type from a collection.

2. Local-variable syntax for Lambda Parameters : Usage of var keyword in lambda parameters started from Java 11.

3. Some new methods to the String class: isBlank()lines()strip()stripLeading()stripTrailing(), and repeat(). Undoubtedly, these methods will minimize the amount of boilerplate code used in manipulation of string objects, and save developers from importing various libraries.

4. New File Methods : Files class got new static methods readString() and writeString() in order to read and write Strings from files.

5. The ‘not()’ Predicate Method : The Predicate Interface has got a static not() method to negate an existing predicate.

6. Running Java source File directly without compile :  Starting from Java 11, we don’t need to compile the Java source files with javac explicitly anymore. Instead, we can directly run the file using the java command.

Removed features :

1. Com.sun.awt.AWTUtilities class : it was deprecated since jdk8
2. appletViewer Launcher
3. Thread.destroy() & Thread.stop(Throwable)
4. Java EE & CORBA modules

New In Java 12

1. Switch-case Statement : multiple entries allowed as case input

String input=”Monday”;
switch(input) {
case “Monday”, "Tuesday”,”Wednesday”, “Thursday”, “Friday” ->System.out.println(“Week days”);
case “Saturday”, “Sunday” -> System.out.println(“Weekends”);
default -> System.out.println(“Invalid days”);
}

 

2. String literal : HTML code can also be included without any \n character.

String html= “<html>
<body>
<p>Hello World.</p>
</body>
</html>”;

3. String Class new Methods : indent() and transform()

indent() method is used to adjust the indentation of each line on the basis of the integer parameter passed to it. If the parameter is positive integer (greater than zero), new spaces will be inserted at the beginning of each line. On the other hand, if the parameter is negative integer (less than zero), it removes spaces from the begging of each line.

transform() accepts a single argument function as a parameter that will be applied to the string.

4. File mismatch() method : The nio.file.Files utility class has got a new mismatch() method in order to compare two files and find the position of the first mismatched byte in their contents.

5. Other Garbage Collector & Performance Improvements

New In Java 13 

In continuation to ‘Java Features After Java 8’, it’s time to talk about new features in Java 13.

1. Yield keyword in Switch-case Statement : If we use colon (:) operator, we need to use yield keyword as shown in below code snippet.

String input=”Monday”;
switch(input) {
case “Monday”, "Tuesday”,”Wednesday”, “Thursday”, “Friday” : yield System.out.println(“Week days”);
case “Saturday”, “Sunday” : yield System.out.println(“Weekends”);
default : yield System.out.println(“Invalid days”);
}

 

2. Text block : will be printed exactly as it is written: introduced with triple quote “”” . Now JSON format code can also be inserted without any special character.

String html= “””<html>
<body>
<p>Hello World.</p>
</body>
</html>”””;

3. Other performance related changes

New In Java 14

Please visit Java 14 Features

New In Java 15

Please visit Java 15 Features

New In Java 16

Vector API
Enable C++14 Language Features
Migrate from Mercurial to Git
Migrate to GitHub
Concurrent Thread-Stack Processing
Unix-Domain Socket Channels
Alpine Linux Port
Elastic Metaspace
Windows/AArch64 Port

New In Java 17

Restore Always-Strict Floating-Point Semantics
Enhanced Pseudo-Random Number Generators
New macOS Rendering Pipeline
macOS/AArch64 Port
Deprecate the Applet API for Removal
Strongly Encapsulate JDK Internals
Pattern Matching for switch

New In Java 18

UTF-8 by Default
Simple Web Server
Code Snippets in Java API Doc
Reimplement Core Reflection with Method Handles
Vector API
Internet-Address Resolution SPI
Foreign Function & Memory API
Pattern Matching for switch

We will extend our topic ‘Java Features After Java 8’ with further explanation of existing facts when necessary.

close

Leave a Reply

Top