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.881Easy

What is the correct syntax for a lambda expression with no parameters that returns a fixed value?

Q.882Easy

Given: Function<Integer, Integer> f = x -> x * 2; Integer result = f.apply(5); What is the value of result?

Q.883Medium

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

Q.884Hard

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

Q.885Hard

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

Q.886Hard

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

Q.887Hard

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

Q.888Easy

Which functional interface is used to create a lambda expression that takes two integers and returns a boolean value?

Q.889Easy

What will be the output of the following code?
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
numbers.stream().filter(n -> n % 2 == 0).forEach(System.out::println);

Q.890Medium

Which of the following lambda expressions is INVALID in Java?

Q.891Medium

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

Q.892Medium

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?

Q.893Hard

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

Q.894Easy

Which annotation is used to mark a class as a Spring Bean in the latest Spring Framework?

Q.895Easy

What is the primary purpose of Dependency Injection (DI) in Spring Framework?

Q.896Easy

Which of the following is NOT a valid Spring bean scope in Spring 5.x+?

Q.897Easy

What does @Autowired annotation do in Spring?

Q.898Easy

Which XML element is used to define a bean in Spring XML configuration?

Q.899Medium

A Spring application requires constructor-based dependency injection for a mandatory dependency. Which approach is best?

Q.900Medium

What is the default scope of a Spring Bean?