Industrial manufacturing
Industrial Internet of Things | Industrial materials | Equipment Maintenance and Repair | Industrial programming |
home  MfgRobots >> Industrial manufacturing >  >> Industrial programming >> Java

Java 10: 70+ New APIs & Features Explained

JDK 10 release has added 70+ new APIs and Options to Java library. Following are some of the important enhancements introduced.

Optional.orElseThrow() Method

A new method orElseThrow() is available in java.util.Optional class which is now a preferred alternative for get() method.

APIs to create Unmodifiable Collections

A new method copyOf() is available in List, Set and Map interfaces which can create new collection instances from existing one. Collector class has new methods toUnmodifiableList(), toUnmodifiableSet(), and toUnmodifiableMap() to get elements of a stream into an unmodifiable collection.

Disable JRE Last Usage Tracking

A new flag is introduced jdk.disableLastUsageTracking which disables JRE last usage tracking for a running VM.

Hashed Password

The plain text passwords available in the jmxremote.password file are now being over-written with their SHA3-512 hash by the JMX agent.

javadoc Support for Multiple Stylesheets

A new option is available to javadoc command as --add-stylesheet. This option supports use of multiple stylesheets in generated documentation.

javadoc Support for Overridding methods

A new option is available to javadoc command as --overridden-methods=value. As many classes override inherited methods but do not change the specification. The --overridden-methods=value option allows to group these methods with other inherited methods, instead of documenting them again separately.

javadoc Support for Summary

A new inline tag, {@summary ...}, is available to specify the text to be used as the summary of the API description. By default, the summary of an API description is inferred from the first sentence.

Example

Following Program shows the use of some of the new APIs in JAVA 10.

import java.util.List;
import java.util.stream.Collectors;

public class Tester {
   public static void main(String[] args) {
      var ids = List.of(1, 2, 3, 4, 5); 
      try {
         // get an unmodifiable list
         List<Integer> copyOfIds = List.copyOf(ids);
         copyOfIds.add(6);	
      } catch(UnsupportedOperationException e){
         System.out.println("Collection is not modifiable.");
      }
      try{
         // get an unmodifiable list
         List<Integer> evenNumbers = ids.stream()
            .filter(i -> i % 2 == 0)
            .collect(Collectors.toUnmodifiableList());;
         evenNumbers.add(6);	
      }catch(UnsupportedOperationException e){
         System.out.println("Collection is not modifiable.");
      }
   }
}

Output

It will print the following output.

Collection is not modifiable.
Collection is not modifiable.

Java

  1. Master Java Operators: Types, Syntax, & Practical Examples
  2. Mastering Java's super Keyword: Advanced Usage & Practical Examples
  3. Mastering Java Interfaces: Concepts, Implementation, and Best Practices
  4. Java List Interface: Overview, Implementations, and Key Methods
  5. Master Java Autoboxing and Unboxing: Practical Examples and Best Practices
  6. Java 10: Key Deprecated APIs, Features, and Options Removed
  7. JDK 10 Deprecations: Key APIs, Features & Options Removed
  8. Java 9 Collection Factory Methods: Simplify Immutable List, Set & Map Creation
  9. Java 8: Introducing the Robust New Date/Time API
  10. Arduino Alternatives: Top Microcontroller Boards to Try