JAVA-8 Interview Ques

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

JAVA-8

1. java 8 new features?


1. Functional Interface:
Each functional interface has a single
abstract method, called the functional method,
implementation can be provided using the
lambda expressions.
2. Lambda Expressions:
It is a feature derived from functional
programming.
It is a function that does not belong to
any class.
3. Optional:
Instead of using null values Optional class is used for
representing Optional values.
4. Stream API
5. Spliterator
6. Method References
7. New Date and Time API.

2. Stream API?
Stream API is the new feature of Java 8. It is used to process or
compute the data.
It provides Functional-Style programming.

3 What is Lambda Expression?


Lambda expressions are the method without name i.e Anonymous method.
In other words, Lambda expression is a function that can be passed
around and referenced as an object.
A lambda expression consists of three parts :
a. Parameter List
b. Lambda symbol ->
c. Expression
(Parameter List) ->{expression;}

5 What is the Optional class in java?


Java SE 8 introduces a new class in the util package i.e
java.util.Optional.
It is used to avoid NullPointerException.

6. Spliterator?
Spliterator is introduced in JDK 1.8
Spliterator is used for Stream API
Spliterator can be used for iterating the Stream elements in
parallel or sequential order.

7. method reference in java 8?


Method reference is represented by using the double colon operator
"::".
syntax of method reference :
Object :: nameOfTheMethod
According to Oracle docs, Method references are
compact, easy-to-read lambda expressions for methods
that already have a name.

8.New Date and Time API?


*drawbacks of old date-time API.
Not thread safe − java.util.Date (package)
Poor design
Difficult time zone handling
to overcome those drawbacks
*java 8 introduces a new date-time API under the java.time(package).
Local − Simplified date-time API with no complexity of timezone
handling.
Zoned − Specialized date-time API to deal with various
timezones.

You might also like