Java 8 Features – Unleashed

Java is the programming language used by millions of developers and numerous for their business solutions. With the Java 8 release, Java contributed in support for functional programming, enhancement of JavaScript engine, outstanding APIs for date time manipulation, new streaming API, etc. There are dozens of notable and valuable features in Java 8, but the most significant features are discussed.

Out of all features, some are very talked about (booming) amongst developers, while few are not talked about (quiet) features.

Booming Java 8 Features

Booming Java 8 Features

1. Lambda Expressions

As per Java developer’s perspective, Lambda expression is one of the significant add-on features to the language. This extended feature brought Java App Development to the forefront of functional programming, just like other functional JVM-based languages – Scala and Clojure. A lambda expression is a function used to create delegates or expression tree types. Using lambda expressions, developers can code local functions which can be passed as arguments or returned as the value of function calls as lambdas are integrated in core language libraries.  Below example shows snippet of with and without lambda expressions. It mainly represents the difference in function calling ways

//without lambda, Drawable implementation using anonymous class 
Drawable d=new Drawable(){ 
public void draw(){System.out.println("Drawing"+width);} 
//with lambda 
Drawable d2=()->{  

2. Concurrent Accumulators

In Java based solutions, it is a very common scenario to use numeric counters which are accessed by multiple threads. In earlier Java versions it was difficult to modify the counter values. Java 8 resolved this issue with its concurrent accumulator classes, where the value can be increased/ decreased effectively in a thread safe method. Some concurrent API enhancements are mentioned as follows:

  • ConcurrentHashMap – compute(), forEach(), forEachEntry(), forEachKey(), forEachValue(), merge(), reduce() and search() methods.
  • CompletableFuture – that may be explicitly completed (setting its value and status).
  • Executors newWorkStealingPool() – method to create a work-stealing thread pool using all available processors as its target parallelism level.

3. New Date/ Time API

Current native Java library API is complex to implement and execute, so Joda time is a boon for Java developers in such situation. But, with coming of Java 8, the pain is cured as Java 8 came up with its own new Data/Time API under java.time package. New API is designed keeping simplicity in mind and it is easily readable to human and machine time formats. i.e. Simplified and Specialized date/ time API for local and zonal time zones respectively.

4. Stream API

A stream, a new abstract layer, provides a set of elements of a particular type in a consecutive manner. A stream executes element on demand, it never stores the elements. Alike SQL statements, data can be processed in a declarative way by using stream also. It is similar to an iterator which allows a single run over a collection. It is the best feature for developers who work on Collections and Big Data. Running of streams can be either sequential (stream () method) or parallel (parallelstream() method). Parallel enhances power of multiple cores.

5. Nashorn

Nashorn is a JavaScript engine which enables developer to run the script on a JVM. Compare to Rhino, its performance is 2 to 10 times better as it uses invoke dynamic feature. It is also suitable for Node.js applications along with supporting actual Java libraries to be called by the JavaScript code executing on a server. JAVA 8 introduces a new command line tool, jjs, to run JavaScript codes at console.

Quiet Java 8 Features

1. Parallel Sorting

Just as to speed up counting, Concurrent Accumulator is utilized, to speed up sorting, Parallel Sorting is adapted. It automatically splits the collection into several parts and sorts them independently based on cores and grouped them back. Arrays.parallelSort(myArray); is used for parallel sorting.

2. Commanding OS Processes

Java 8 came up with 3 new features in Process class which helps for controlling OS processes:

  • destroyForcibly – finishes a process with a higher degree of success
  • isAlive – indicates if a process originated by code is alive or not.
  • waitFor() – specifies the waiting time for a process to finish.

3. Stamped Locks

Java 8 advances ReadWriteLock (implemented by ReentrantReadWriteLock) with boosting speed called StampedLock. It has an “optimistic” mode that arises a stamp that is returned by each locking operation to assist as a kind of admission ticket; each unlock operation requires to pass its correlating stamp. The process results in faster execution. In situation where readers are more than writers, use StampedLock to improvise performance.

4. Secure Random Generation

Java 8 added up a new method called SecureRandom.getInstanceStrong() to enhance security. It let JVM choose a secure provider. For several years, security was one of the discussed issues of JVM, but with Java 8 feature it is reduces the risk of attack.

5. Null Reference Template

Null Pointers being an older pattern, Java 8 introduced a new template – Optional. Similar to the concept of Scala and Haskell, this template is to explicitly state when either reference is passed to or return by function can be null. This template increases convenience and decreases the time of execution.

Java 8 – A Platform for Business Innovation

Business apps develop using Java 8 development are faster and easily navigating with extended features. IoT (Internet of Things), an emerging technology nowadays, is also supported in Java 8. Apart from this, it also provides business leveraging peculiarities like more productivity, less time-consuming code, modernized apps, supporting embedded technology and much more. All above this, it is integrated with JavaScript. In short, Java 8 app development amplify the business app providing users a solution having robust functionalities.

Upcoming Java Updates

It is expected that Java 9 is launching this year (2017). It is tittle-tattle that Java 9 is coming up with features like Java 9 REPL (JShell), Factory Methods for Immutable List, Set, Map, and Map.Entry, Private methods in Interfaces, Module System, Process API Improvements, Resources Improvement, CompletableFuture API, Reactive Streams, Diamond Operator for Anonymous Inner Class, Optional Class advancement, Stream API fixes, Enhanced @Deprecated annotation, HTTP 2 Client, Мulti-Resolution Image API and few other miscellaneous features. Expected change in the ecosystem is of Modularity. Modules created, affects all phases of development – Compiling, testing, packaging, deploying, running. Due to this, Java 9 launch is stalled. It’s a thought that Java 9 is designed keeping in mind the developer’s request and issues.

Vishal Shah

Vishal Shah has an extensive understanding of multiple application development frameworks and holds an upper hand with newer trends in order to strive and thrive in the dynamic market. He has nurtured his managerial growth in both technical and business aspects and gives his expertise through his blog posts.

Related Service

Know more about Java development services

Learn more

Want to Hire Skilled Developers?


    • Leave a message...