Загрузка страницы

Java 8 || Java 8 new features Interview Questions ( Live Demo )

Java 8 || Java 8 new features interview questions ( Live Demo )

There are lots of new features which were added in Java 8. Here is the list of important features which are mostly asked as java 8 interview questions:

Lambda Expression
Stream API
Default methods in the interface
Functional Interface
Optional
Method references
Date API
Nashorn, JavaScript Engine

Main advantages of using Java 8?
More compact code
Less boiler plate code
More readable and reusable code
More testable code
Parallel operations

Interview question on java 8 Lambda expressions is a very commonly asked question :
Lambda expression is an anonymous function ( without name, return type and access modifier and having one lambda symbol )

Functional interfaces are those interfaces which can have only one abstract method .

It can have static method, default methods.

There are many functional interfaces already present in java such as eg : Comparable, Runnable
How lambda expression and functional interfaces are related?
Lambda expressions can only be applied to abstract method of functional interface.

As we know Functional interface is an interface with Exactly One Single Abstract method and can have multiple Static or default methods.

To create our own Functional interface, You can do following steps:
Create An interface
Annotate that with @FunctionalInterface.
Define exactly one Abstract method.
There is no restriction on number of static and default methods defined in such and interface.

Java can implicitly identify functional interface but still you can also annotate it with @FunctionalInterface . It just give you the security that in case if u by mistake add 2 abstract methods then Compiler will throw compile time error.

Method Reference :
EG : MethodReferenceDemo and FunctionalInterfaceDemo

Method reference is replacement of lambda expressions. It is used to refer method of Functional interface to an existing method. Mainly it is used for code reusability.

Functional Interface’s Abstract method can be mapped to specific existing method using double colon operator (::) . This is Method reference.

Hence Method reference is an alternative to Lambda expressions.

Whenever we have existing Implementation of Abstract method of our Functional interface then we can go for method reference. If no such method like testImplementation() is available then go for lambda expressions.

#JAVA8 #JAVA8InterviewQuestions #JAVAInterviewQuestions

Видео Java 8 || Java 8 new features Interview Questions ( Live Demo ) канала Code Decode
Показать
Комментарии отсутствуют
Введите заголовок:

Введите адрес ссылки:

Введите адрес видео с YouTube:

Зарегистрируйтесь или войдите с
Информация о видео
31 декабря 2020 г. 20:32:05
00:20:34
Яндекс.Метрика