iGET

Java Programming - MCQ Practice Questions

Practice free Java Programming multiple-choice questions with detailed answers and explanations. Perfect for competitive exam preparation.

958 questions | 100% Free

Q.181Hard

What output will this produce? java List<? super Integer> list = new ArrayList<Number>(); list.add(5); Integer val = (Integer) list.get(0);

Q.182Hard

Which Java feature was introduced specifically to support generics compilation?

Q.183Hard

A method processes collections where items need to be added back to the same collection type. Which wildcard approach ensures type safety for write operations?

Q.184Hard

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

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

What is the type inference mechanism in lambda expressions?

Q.187Hard

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

Q.188Hard

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

Q.189Hard

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

Q.190Hard

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

Q.191Hard

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

Q.192Hard

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

Q.193Hard

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

Q.194Hard

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

Q.195Hard

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

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

Q.197Hard

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

Q.198Hard

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

Q.199Hard

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

Q.200Hard

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