Below are new features that are introduced in Java 8 :
- Lambda expression
- Functional Interface
- Default Methods and static methods
- Predefined Functional interfaces (Predicate, Functional, Consumer, supplier, etc.,.)
- Double colon operator(::), Method reference, constructor reference
- Streams
- Date and Time API
- Optional class
- nashorn JavaScript engine
- StringJoiner
- Collectors class etc.,.
Lambda expression::
- It is an anonymous function i.e., a lambda expression is Nameless, without return type, without modifiers.
- It brings the benefits of functional programming into Java.
- Lambda expression can implement an interface that contains a Single Abstract Method(SAM.)
- Click here for details
Functional Interface::
- Interface which contains SAM(Single Abstract Method) is called Functional Interface
- It also contains Any number of default methods and static methods
- In order to invoke lambda expression, we require a Functional Interface.
Default Methods:
- Until Java 1.7, Every method present inside the interface is always public and abstract
- In Java 1.8V, default methods and static methods are allowed
- In Java 1.9V, private methods are allowed
Static Methods:
- From Java 1.8, the interface can contain static methods.
- We should call static methods in the interface by using its interface name only.
- static methods in an interface are by default not available to implementation classes. So we have to call by using interface name only.
No comments:
Post a Comment
Please comment below to feedback or ask questions.