iGET

Java Programming - MCQ Practice Questions

Java interviews and campus tests lean heavily on object oriented behaviour rather than API recall. This set covers inheritance and polymorphism, interfaces and abstract classes, the collections framework, exception handling, multithreading, string handling, and JVM basics such as garbage collection. Output based questions are included because they expose the gaps that theory questions hide.

951 questions | 100% Free

Q.861Easy

What is the result of this code?
UnaryOperator<Integer> square = x -> x * x;
System.out.println(square.apply(5));

Q.862Easy

Which of the following best describes a functional interface?

Q.863Easy

What will be the output of:
Supplier<String> greeting = () -> "Hello";
System.out.println(greeting.get());

Q.864Medium

Consider: Comparator<String> comp = (s1, s2) -> s2.compareTo(s1);
What does this lambda expression do?

Q.865Medium

Which lambda expression is equivalent to the method reference Integer::parseInt?

Q.866Hard

What is the correct way to chain lambda expressions using Function interface?
Function<Integer, Integer> f1 = x -> x * 2;
Function<Integer, Integer> f2 = x -> x + 5;
How to apply f1 first, then f2?

Q.867Medium

Analyze: What is the output?
BiConsumer<String, String> printer = (a, b) -> System.out.println(a + b);
printer.accept("Java", "8");

Q.868Easy

Which of the following is a valid functional interface that can be used with lambda expressions?

Q.869Medium

What is the return type of a lambda expression (x, y) -> x + y where x and y are integers?

Q.870Easy

Which annotation is used to mark an interface as a functional interface in Java?

Q.871Medium

Consider a lambda expression: (String s) -> s.length(). What is the correct functional interface for this?

Q.872Medium

What will happen if you try to access a local variable from an enclosing scope that is not final or effectively final in a lambda expression?

Q.873Easy

Which of the following lambda expressions is syntactically incorrect?

Q.874Easy

What is the purpose of a Predicate functional interface in Java?

Q.875Medium

Consider the code: List<String> names = Arrays.asList("Alice", "Bob"); names.forEach(name -> System.out.println(name)); What type of functional interface is used in forEach?

Q.876Medium

What is the output of: List<Integer> nums = Arrays.asList(1,2,3); nums.stream().filter(x -> x > 1).forEach(System.out::println);

Q.877Medium

Which lambda expression correctly implements a custom functional interface: public interface Math { int calculate(int a, int b); }

Q.878Easy

In a lambda expression, what does the arrow (->) operator represent?

Q.879Medium

Consider: Comparator<Integer> comp = (a, b) -> b - a; List<Integer> list = Arrays.asList(3,1,2); Collections.sort(list, comp); What is the result?

Q.880Medium

Which of the following correctly uses a method reference as an alternative to a lambda expression?