Pages

java8 features

Java 8 features

Below are new features that are introduced in Java 8 :
  1. Lambda expression
  2. Functional Interface
  3. Default Methods and static methods
  4. Predefined Functional interfaces (Predicate, Functional, Consumer, supplier, etc.,.)
  5. Double colon operator(::), Method reference, constructor reference
  6. Streams
  7. Date and Time API
  8. Optional class
  9. nashorn JavaScript engine
  10. StringJoiner
  11. 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.