Java 8 Interview question for an Experience and fresher this 15 question can be asked in any of the aptitude java 8 interview questions.
These Java 8 interview questions are asked in many Java interviews this can help you to boats your knowledge. As you know Java 8 is a big update in Java World. Practice this java 8 interview question will help to easily crack an interview in java. 
java 8 interview questions
Java 8 interview questions


1) Which of the following functional interface represents a function that accepts an int valued argument and produces a double valued result.
A- IntToDoubleFunction
B- IntToLongfunction
C- IntUnaryOperator
D- LongBinaryOperator

OUTPUT:

2) Which of the following functional interface represents a predicate (Boolean valued function) of one long valued argument.
A-longConsumer
B-LongFunction
C-LongPredicate
D-LongSupplier

OUTPUT:

3) What is the Purpose of sorted method of stream in java 8?
A-lterate each element of stream in the provided sort order.
B-Map each element to its corresponding result.
C-Eliminate elements based on a criteria.
D-Used to sort the system.

OUTPUT:

4) Using lambda expression, you can refer to the final variable or effectively final variable (which is assigned only once)
A-No, there is nothing like effectively final in java.
B- Yes.
C-Yes, the only the final variable can be referred.
D- No, neither final nor effectively final can be referred.

OUTPUT:

5)Stream support aggregate operations like filter, map, limit, reduce, find, and match
A-False
B-True

OUTPUT:

6)Which of the following is correct about default methods in java 8?
A-an interface can have a default implementation
B-An interface can also have status helper methods
C-Both of the above
D-None of the above

OUTPUT:

7) Class Optional orElse() methods return the value if present otherwise returns the default value passed

A-false, no such method
B-true
C-false, it returns back a null value
D-false, it throws null pointer exception if called

OUTPUT:

8) Which of the following is correct about Java 8 lambda expression?

A - Lambda expressions are used primarily to define inline implementation of a functional interface.
B - Lambda expression eliminates the need for an anonymous class and gives a very simple yet powerful functional programming capability to Java.
C - Both of the above.
D - None of the above.

OUTPUT:

9)Which of the following is correct about streams in java 8?

A-Intermediate operations function Is to take input, process them, and return output to the target.
B-collect () method is a terminal operation which is normally present at the end of the pipelining operation to mark the end of the stream.
C-Both of the above
D-None of the above

OUTPUT:

10)Java util date is thread-safe, thus developers do not have to deal with concurrency issues while using date.

A-True
B-False

OUTPUT:

11)How will you call a Default method of an Interface in a class ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public interface  DefaultInterface {
  default void show() {
    System.out.println("Calling a DefaultMethod");
   }
}
 
//different Class
public class Test implements DefaultInterface {
 public void show() {
  //your code
 }
 
 public static void main(String[] args) {
  new Test().show();
 }
}

A-super.show();
B-DefaultInterface.show();
C-DefaultInterface.super.show();
D-No Way to Called default from Class

OUTPUT:

12)The following code is completed?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@FunctionalInterface
public interface Consumer<T> {
   public  void consumer(T parameter);
}
 
 
 class Integerconsumer implements Consumer<Integer> {
 
 @Override
 public void consumer(Integer parameter) {
  // TODO Auto-generated method stub
   
 }
 
}

A-Yes
B-No, function interfaces can have only one method
C- No, we can't have method implementation in interfaces
D-No, default is not a java keyword

OUTPUT:

13) Consider the below code:
1
2
3
4
5
6
7
8
9
10
11
@FunctionalInterface
public interface Consumer<T> {
   public  void consumer(T parameter);
}
 
public class Integerconsumer implements FunctionInterface<Integer> {
 @Override
 public void consumer(Integer parameter) {
 
 }
}

A-Gives compile-time error, T is undefined
B-Gives compile-time error, can't assign an Integer to T
C-Runtime error, ClassCastException
D-Compiles Successfully

OUTPUT:

14) Consider the below code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int days = 0;
String month = "Dec";
switch (month) {
case "Jan":
case "Mar":
case "May":
case "July":
case "Aug":
case "Oct":
case "Dec":
 days = 31;
 break;
case "Feb":
 days = 28;
 break;
default:
 days = 30;
}

A-Compile time error, String can't be part of a switch
B-Compile time error, "Jan" is undefined
C-Compiles successfully

OUTPUT:

15) Consider the below code:
1
2
3
4
5
6
7
class parent {
 Void dosomething() {
 
  // …
 
 }
}

A-Code Compiles
B-Compile time Error
C-Runtime Error

OUTPUT:

Hope you Learn From this Java 8 Interview Question. 

Post a Comment

أحدث أقدم