Thursday, February 19, 2015

Exciting Features In Java 8 That Will Change How We Code?

5 features that we feel an absolute must for you to know about.

1.Lambda expressions.
2.Parallel operations.
3.Java + JavaScript :)
4.New date / time APIs.
5.Concurrent accumulators

1.Lambda expressions

Lambda expressions have taken the programming world by storm in the last few years. Most modern languages have adopted them as a fundamental part of functional programming. JVM based languages such as Scala, Groovy and Clojure have integrated them as key part of the language. And now, Java 8 is joining in on the fun.

2.Parallel operations.

Java introduced a key concept into the language of internal iteration. Essentially as developers we’re used to use loop operations as one of the most basic programming idioms, right up there with if and else.
This enable operations carried out on long arrays such as sorting, filtering and mapping to be carried out in parallel by the framework.

ConcurrentMap> byGender = roster.parallelStream().collect(Collectors.groupingByConcurrent(Person::getGender))

here roster this a collection and by using the parallelStream() we are getting the person object by the gender and populating the map with gender as key and resulted collection as value.

3.Java + JavaScript :)

Java 8 is introducing a completely new JVM JavaScript engine – Nashorn. This means that the next time you’re looking to integrate JS into your backend, instead of setting up a node.js instance, you can simply use the JVM to execute the code. The added bonus here is the ability to have seamless interoperability between your Java and JavaScript code in-process, without having to use various IPC/RPC methods to bridge the gap.

4.New date / time APIs.

Java 8 implemented its own new date / time API from scratch. The good news is that unlike Calendar.getInstance(), the new APIs were designed with simplicity in mind, and clear operations to operate on manipulated values in both human readable and machine time formats.


5.Concurrent accumulators

One of the most common scenarios in concurrent programming is updating of numeric counters accessed by multiple threads. There have been many idioms to do this over the years, starting from synchronized blocks,read/write locks to AtomicInteger(s).

With Java 8 this problem is solved at the framework level with new concurrent accumulator classes that enable you to very efficiently increase / decrease the value of a counter in a thread safe manner.

0 comments:

Post a Comment