Features in Java-8
- Interface Enhancement
- Functional Interface
- Lambda Expression
- Stream API
- Date & Time API
a. Introduction of default methods - Supports backward compatibility
1. default method is available inside the implementing class
2. there can be more than 1 default method in interface
3. default method helps in bringing backward compatibility
b. Introduction of static method
1. static method is not available inside the implementing class
2. there can be more than 1 static method in interface
3. static method helps in bringing backward compatibility
4. we cannot override static method
5. Java 8 onwards main method can be part of interface
c. Functional Interface
- An interface having one and only one abstract method is a functional
- Runnable interface had only 1 abstract method called run() - ex. functional interface
- Comparable interface had only 1 abstract method called compareTo() - ex. functional interface
- Functional interface can have any number of default and static method but only 1 abstract method thats why it is also called as SAM interface
d. Lambda expression
- OOP -> Programming paradigm should adhere to Classes, Objects, Encapsulation, Inheritance, Polymorphirm, Abstraction
- Functional programming - Here implementation of same functionality can be done in clear and concise manner.
- Code will be less, implementation will compact
e. Predicates
- Are predefined functional interfaces
- Return boolean value
f. Double colon operator => can be used as an alternative to Lambda expression
- method reference - instance and static method
- constructor reference
g. Streams - java.util.stream
- Helps to operate on collection object
- distinct function removed duplicate and returns unique list
- skip functions skips the specified number of elements from starting
- peek function helps in debugging to see what is happening after a particular operation on the stream
h. Java-8: Date Time API
- In java 7 we had Date, Calender, Timestamp, they were not efficient, it was present in java.util package
- In Java 8 a new Date Time API was introduced which is also called as Joda Time Api in a new package called java.time
If you want to implement all Java8 concepts in practical handson based approach than checkout my popular udemy course:
https://www.udemy.com/course/practical-java-8-mastery-course/?couponCode=1DCCF8309E7BB06E4C42
Top comments (0)