- Java 10 - Discussion
- Java 10 - Useful Resources
- Java 10 - Quick Guide
- Java 9 Tutorial
- Java 8 Tutorial
- Java Tutorial
- Java 10 - Thread-local Handshake
- Java 10 - Root Certificate
- Java 10 - Consolidated JDK Forest
- Java 10 - Heap Allocation
- Java 10 - Locale Enhancement
- Java 10 - Enhanced Garbage Collection
- Java 10 - Class-Data Sharing
- Java 10 - JIT Compiler
- Java 10 - Deprecated Features & Options
- Java 10 - Removed Features & Options
- Java 10 - New APIs & Options
- Java 10 - Local Variable Type Inference
- Java 10 - Time Based Release Versioning
- Java 10 - Environment Setup
- Java 10 - Overview
- Java 10 - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Java 10 - New APIs & Options
JDK 10 release has added 70+ new APIs and Options to Java pbrary. 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 inpne 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; pubpc class Tester { pubpc static void main(String[] args) { var ids = List.of(1, 2, 3, 4, 5); try { // get an unmodifiable pst List<Integer> copyOfIds = List.copyOf(ids); copyOfIds.add(6); } catch(UnsupportedOperationException e){ System.out.println("Collection is not modifiable."); } try{ // get an unmodifiable pst 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.Advertisements