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.1Hard

What will be the output of this nested lambda?
Function<Integer, Function<Integer, Integer>> add = x -> y -> x + y;
System.out.println(add.apply(3).apply(5));

Q.2Hard

What will happen if you try to compile this code?
BiFunction<String, String, String> concat = (a, b) -> a + b;
concat.apply("Java", "8", "Features");

Q.3Hard

What is the type inference mechanism in lambda expressions?

Q.4Hard

Consider a lambda that needs to throw a checked exception. Which approach is correct?

Q.5Hard

What is the time complexity of reducing a stream with a lambda expression using reduce()?

Q.6Hard

Consider: List<String> list = Arrays.asList("a", "b", "c"); list.stream().collect(Collectors.toMap(s -> s, s -> s.length())). What type is returned?

Q.7Hard

What issue can arise when using lambda expressions with flatMap() in nested streams?

Q.8Hard

Consider: Function<Integer, Function<Integer, Integer>> curry = x -> y -> x + y; What does curry.apply(5).apply(3) return?

Q.9Hard

What is the time complexity of reducing a stream with a stateful lambda operation?

Q.10Hard

Consider: Function<Integer, Function<Integer, Integer>> curried = a -> b -> a + b; What is this pattern called?

Q.11Hard

Consider: Stream.of(1, 2, 3).map(x -> { System.out.println(x); return x * 2; }).collect(Collectors.toList()); What will print?

Q.12Hard

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.13Hard

Consider a scenario where you need to sort a list of strings by length. Which lambda expression is most appropriate for Comparator?

Q.14Hard

What is the difference between a lambda expression and an anonymous inner class in Java?

Q.15Hard

In the context of exception handling with lambda expressions, what happens if a lambda body throws a checked exception?

Q.16Hard

Which of the following best demonstrates the use of Optional with lambda expressions for safe null handling?

Q.17Hard

What is the return type of a lambda expression used with IntStream.range(1, 5).map(x -> x * 2)?