Java 8 New Features
Java 8 New Features:
1. Java Programming Language
- Lambda Expressions
- Default Methods & Static methods in Interface
- Repeating Annotations
- Type Annotations
- Method Parameter Reflection
- Method Reference
- Improved Type inference.
2. Collections:
- Stream package
- Hash Map performance improvement with key collisions.
3. Date-Time Package
4. Nashorn Javascript Engine
5. java.util.*
- PARALLEL Arrays
- Unsigned Arithmetic Support
6. New JDBC 4.2 API
7. Java DB 10.10
8. java.util.concurrent
- ConcurrentHashMap to support aggregate Operations
- atomic package to support scalable
- ForkJoinPool to support Common Pool.
- StampedLock to provide capability-based lock with 3 modes for controlling read/write access.
Default and Static methods in interface:
- Before Java8 it was not possible to add new functionality to the existing interface without forcing all the implementation classes to create an implementation of new methods
- It was forced to implement new methods to the existing implementation classes
Static in interface:
Static methods are available only inside the interface, it can’t be overridden by implementation classes.
e.g:
interface A{
static String newMethod(){
return “new java8”;
}
}
outside calling: A.newMethod();
Default in interface:
These are accessible through instance of the implementation classes and can be overridden
e.g.:
default String getMethod(){
return “new methods”;
}
Method References:
It’s used for shorter and more readable alternative
For Static Methods:
list.stream().anyMatch(A::newMethod);
For Instance Methods:
A a = new A();
list.stream().anyMatch(a::getMethod);
other examples
list.stream().filter(String::isEmpty).count();
Stream<User> stream = list.stream().map(User::new);
Repeatable annotations:
Prior to Java8, to have a repeated annotation, will have to group them in a container annotation
@Manufactures({
@Manufacturer(name =”BMW”),
@Manufacturer(name = “Range Rover”)})
public class Car{
//code goes in here
}
With java8 we can do that without container annotations
@Manufacturer(name = “BMW”)
@Manufacturer(name= “Range Rover”)
public class Car{
//code goes in here
}
Java compiles this time around takes responsibility for wrapping two annotations into a container
Reference
https://github.com/winterbe/java8-tutorial
Comments
Post a Comment