Wednesday, September 9, 2015

Java 8 new features

Lamda expressions: Provides anonymous function type

One issue with anonymous classes is that if the implementation of your anonymous class is very simple, such as an interface that contains only one method, then the syntax of anonymous classes may seem unwieldy and unclear. In these cases, you're usually trying to pass functionality as an argument to another method, such as what action should be taken when someone clicks a button. Lambda expressions enable you to do this, to treat functionality as method argument, or code as data.

doSomeThing (new DoStuff{
    public boolean isGood(int val){
       return val == 100;
}
})

changed to lamda expression

doSomeThing = answer -> answer == 100;

Simplified code

Improved usability of Generics


Annotations of Java types

doSomeThing(@notnull List lst)

Streams: A sequence of elements supporting sequential and parallel aggregate operation

The operations cane be series of intermediate followed by terminal operation.  Intermediate operations return a stream so we can chain multiple intermediate operations without using semicolons. Terminal operations are either void or return a non-stream result.

Default Methods (multiple inheritance)


Hashmap Performance improvement

They started using tree map instead of linked list and so the searching complexity changed from O(n) to O(log n) in worst case hash keys (all hashcodes are equal resulting all values in single bucket)