9 Big Things about Java 9

9 Big Things about Java 9

September 15, 2017

According to the latest Tiobe index of programming language popularity, Java tops the list.  No wonder there is so much buzz around the new Java 9 release, set for September 21, 2017.  Take a walk through with our expert.
 
  1. JSHELL

Many compiled languages include tools for statements interpretation. By using these REPL tools you can rapidly test code snippets without creating a project.

Take Scala, as an example. Compilation can be time consuming, but by using REPL, each statement is executed instantly! That’s great when you are getting started with the language. Each expression returns a value and type, which is valuable information to have.

On the other hand, in Java, we would need to create a test or main method that prints results and must be recompiled every time someone makes a change.

9 Big Things about Java 9 9 Big Things about Java 92. COLLECTIONS API FACTORY METHODS

The added static factory methods help create collections in variety of small cases.

9 Big Things about Java 9

This come to life due to static interface methods. Thus collections are immutable.

9 Big Things about Java 93. COMPACT  STRINGS

Java 9 provides new and improved strings which, in most cases, will reduce String memory consumption by half.

Instead of having a char[] array, String is now represented as a byte[] array. Depending on which characters it contains, it will use either UTF-16 or Latin-1 to produce either one or two bytes per character.

There is a also new field inside the String class–coder that indicates which variant is used. Unlike Compressed Strings, this feature is enabled by default. If necessary, as in a case where mainly UTF-16 Strings are used, it can be disabled by  -XX:-CompactStrings.

4. OPTIONAL

At last, Java9 adds an or() method to Optional API, which allows for the return of different chained optionals without calling isPresent() each time.

9 Big Things about Java 9

In addition, Java9 can create Stream out of Optional with no more than 1 element inside, which is a real advantage when «lazy» mapping is needed.

9 Big Things about Java 9

And, as the cherry on the cake, Java9 will have an ifPresentOrElse() method in Optional API.

9 Big Things about Java 95. COMPLETABLE FUTURE

This class was polished and several methods were added, but most notable is copy(). This method returns immutable copy for CompletableFuture.

9 Big Things about Java 9

But the coolest thing is that stopping an ancestor will affect the child!

9 Big Things about Java 9

Timeouts were also added to the API. Now it is possible to define how CF should finish after time runs out.

9 Big Things about Java 96. STREAMS

With the excellent additions of dropWhile() and takeWhile() to Stream API, there is now option to skip loop and use the stream iterate() method instead.

9 Big Things about Java 97. PROCESS HANDLE API

When starting Java9, there is now a straight and simple access to process handling.9 Big Things about Java 98. JAVA LANGUAGE ENHANCEMENT

Just in case if someone still uses it, «_» is no longer a legitimate identifier. In this case you should use « __» instead (but you don’t 😉 )

9 Big Things about Java 9

Private methods inside Interfaces.

9 Big Things about Java 9

Now with Java9 we are able to use final variables inside try-with-resources effectively.

9 Big Things about Java 99. STACK WALKER AND G1 AS DEFAULT GC

We can now use stack-trace without creating an Exception instance.  We consider this a big improvement.

9 Big Things about Java 9

Starting Java9 G1 will be our default GC. The “Garbage-first” garbage collector, aka G1, is a concurrent multi-threaded GC. It mostly works alongside the application threads much like the concurrent mark sweep GC, and is designed to offer shorter, more predictable pause times while still achieving high throughput. What makes G1 different is that instead of splitting the heap into 3 big regions, it splits it into a set of lots of equal-size. Certain subsets of regions are still assigned roles just like in the other GCs. The amount of live data in each region is tracked, and when a collection is triggered, the G1GC will clear the ones with the most “garbage” first, hence the name. By doing this, it attempts to free as much space as possible with each  collection.

 

Software Engineer, CoreValue

Tags

CoreValueJavaJava9

Share


Recent Articles

Get 100% Code Coverage for Salesforce Custom Metadata Based Decisions

January 18, 2018 | Bohdan Dovhan

How to obtain a full coverage for code which uses Custom Metadata for strategy-like decision implementation? Introduction Many applications use configuration data. Configuration data might be relevant to the entire organization, or a subset of user, or even different for each user. For the purposes of this article, we will focus only on global configuration […]

Logging of Exceptions in Salesforce

January 11, 2018 | Mykola Senyk

Unpredicted behaviour in a custom code. Can we eliminate it? The ability to customize your Salesforce org code is not just a “nice to have.”  It greatly increases the capability and flexibility of Salesforce. However, custom code can also be tricky to use. It would be great if we could detect unpredicted behavior in our […]

© Copyright - CoreValue 2018
Salesforce, Sales Cloud, and others are trademarks of salesforce.com, inc., and are used here with permission.
Used with permission from Microsoft.