The Java SE 9 feature release includes both enhancements in Java SE 9 API or Technology additions and changes in JDK 9. A Java Programmer interested in Oracle Certified Associate, Java SE 9 Programmer (OCAJP 9) and Oracle Certified Professional, Java SE 9 Programmer (OCPJP 9) Java 9 Certifications must know the following features and enhancements.
Keep watching MyExamCloud Java Certification page about latest books, mock exams, practice tests for Java 9 OCAJP and OCPJP Certifications.
Java 9 is an amazing new version of Java. This object-oriented programming language is still number one among others and you need to get more improvements from time to time. These improvements will allow you to take your apps to the next level right away. We will talk a little about Java 9 and what this new version of Java has in store for you. We will let you know about Java 9 module system, REPL which is used to test Java Constructs, Try with resources improvements, Process API changes, Factory methods in collections, Stream API changes, and much more. So read on if you want to know more.
Java 9 Module System
Oracle realized that Monolithic Jars had a lot of limitations when it comes to developing Java-based apps. So, the tech titan has developed something called Module System to solve this issue right away. You will also find 92 modules in the JDK 9 but this might also turn out to be different in the final release.
Example:
module com.myexamcloud.test {}
module com.myexamcloud.user {}
module com.myexamcloud.admin {}
module com.myexamcloud.mentor {}
module com.myexamcloud.author {}
module com.myexamcloud.affiliate {}
Try With Resources Improvement
Java SE 7 used a construct to handle exception called Try-With-Resources and this exception managed resources in an automatic fashion. Oracle wanted to improve the readability and verbosity to this methods in the new version of Java. You can also find many tutorials online to find out more about this.
Before Java 9
1. |
void methodBeforeJava9() throws IOException {
|
2. |
BufferedReader myReader1 = new BufferedReader(new FileReader(“customers.txt”));
|
3. |
try (BufferedReader myReader2 = myReader1) {
|
4. |
System.out.println(myReader2.readLine());
|
5. |
}
|
6. | } |
After Java 9
1. |
void methodAfterJava9() throws IOException {
|
2. |
BufferedReader myReader1 = new BufferedReader(new FileReader(“customers.txt”));
|
3. |
try (myReader1) {
|
4. |
System.out.println(reader1.readLine());
|
5. |
}
|
6. | } |
Java 9 REPL
The Java 9 REPL is a very useful feature in the latest version of Java you can use to test and execute Java Constructs. And you will do this very easily. You can also download this features from Oracle`s website.
>jshell
| Welcome to JShell — Version 9-ea
| For an introduction type: /help intro
jshell> int num = 100
num ==> 100
jshell> System.out.println(“num value = ” + num )
num value = 100
Process API Improvements
Process API is coming with many improvements. You will find it easier to manage and control any OS process thanks to some new methods and classes that Oracle has added up here. You can also find some tutorial online that will allow you to learn more about this interesting part of this.
Example:
ProcessHandle currentProcess = ProcessHandle.current();
|
System.out.println(” Process Id: = “ + currentProcess.getPid()); |
Factory Methods for Map, Map.Entry, Immutable List, and Set
You can now use many factory methods to quickly create any kind of Set, Map.Entry objects, Set, and Immutable List. You will use these utility methods to create non-empty or empty Collection objects. Oracle used a verbose and tedious approach in the famous Collections.unmodifiableXXX methods. But now you will see that Oracle has overcome these shortcomings by adding up some utility methods to Map, Set and List interfaces.
List emptyTestList = List.of();
|
List testList = List.of(“Java 8”,“Java 7”,“Java 9”); |
Map emptyMap = Map.of(); |
Map myMap = Map.of(1, “Java”, 2, “C++”, 3, “Python”); |
Private methods in Interfaces
Oracle has been concerned about the re-usability features and redundant code in Java 8, and they have solved the problem in Java SE 9 by introducing private methods in the new interfaces.
1. |
public interface Customer {
|
2. |
private Double currentBalance() {
|
3. |
// Method implementation goes here.
|
4. |
}
|
5. |
private static void displayCustomerInfo() {
|
6. |
// Method implementation goes here.
|
7. |
}
|
8. | } |
Stream API Improvements
You will also find out that Oracle has added 4 methods to the important java.util.Stream interface. These are also default methods because Steam is just an interface. dropWhile and takeWhile are two of the most important methods that you will find here. You should now a lot of about these methods if you have to deal with any Functions programming language.
Stream.of(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
|
.takeWhile(i -> i < 10)
|
.forEach(System.out::println);
|
Reactive Streams
You will use the Reactive Streams API in this new Java SE 9 because Oracle has included it here. You will be using the Java language to implement Parallel, Asynchronous, and Scalable applications. Reactive programing is truly an important approach to develop many applications today because they offer a lot of beautiful benefits.
Following APIs are introduced in Java SE 9 to develop Reactive Streams.
java.util.concurrent.Flow.Processor
java.util.concurrent.Flow.Publisher
java.util.concurrent.Flow.Subscriber
java.util.concurrent.Flow
CompletableFuture API Improvements
You will see that CompletableFuture API has many improvements that will allow you to solve many problems right away. You will enjoy better sub-classing and some utility methods. You will be using delayedExecutor() to return an important new Executor so that you can submit a task to the important default executor.
Executor exe = CompletableFuture.delayedExecutor(20L, TimeUnit.SECONDS);
Diamond Operator for the Anonymous Inner Class
Oracle has removed a lot of limitations in the use of the famous Diamond operator with the important Anonymous Inner Class. They have done this in the Java 9 and you will truly reap the benefits in no time.
1. |
public List getCustomer(String id) {
|
2. |
// Code to get Customer details
|
3. |
return new List(customer) {};
|
4. | } |
Here we are using just “List” without specifying the type parameter.
Optional Class Improvements
The java.util.Optional class has many useful new methods that you will love using right away. You can use any stream() to work on any Optional object here. If you have a value in the Optional object, you can use a stream() method to return an important sequential Stream with this value.
Stream<Optional> cust = getCustomer(id)
Stream custStream = cust.flatMap(Optional::stream)
Enhanced @Deprecated annotation
Oracle has enhanced the important @Deprecated annotation so that you can get more information on deprecated API. You will also manage to analyze data about static usage by using a tool to do this with deprecated APIs. Since and ForRemoval are the two methods added to serve this information.
Multi-Resolution Image API
Oracle has worked hard to release the important multi-Resolution Image API. T here is an important interface in this API which is called MultiResolutionImage. You will manage to encapsulate a lot of images with different widths and heights in this interface over time.
HTTP 2 Client
Oracle released HTTP 2 Client API to support both WebSocket features and HTTP/2 protocol. HTTP client will replace the famous HttpURLConnection API right away. Oracle will work hard to release the famous HTTP 2 Client API right under “java.net.http” package. It will give you the support you need for both HTTP/2 and HTTP/1.1 protocols.
Other miscellaneous Java 9 Features
You can also use many APIs in Java 9 including the important Stack-walking API. You will get access to a lot of stack trace information when you harness the power of this API right away.