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.41Medium

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

Q.42Medium

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.43Medium

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.44Medium

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

Q.45Medium

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

Q.46Medium

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.47Medium

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

Q.48Medium

Which stream operation uses a lambda expression to transform elements from one type to another?

Q.49Medium

Which of the following lambda expressions is INVALID in Java?

Q.50Medium

A stream processes a list of strings and applies a lambda to convert them to uppercase. Which intermediate operation should be used?

Q.51Medium

Consider the following code:
List<String> fruits = Arrays.asList("apple", "banana", "cherry");
fruits.removeIf(s -> s.length() > 5);

What will be the contents of 'fruits' list after execution?