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

What is the output of:
BiFunction<Integer, Integer, Integer> add = (a, b) -> a + b;
System.out.println(add.apply(5, 3));

Q.242Easy

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

Q.243Easy

Which of the following best describes a functional interface?

Q.244Easy

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

Q.245Easy

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

Q.246Easy

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

Q.247Easy

Which of the following lambda expressions is syntactically incorrect?

Q.248Easy

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

Q.249Easy

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

Q.250Easy

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

Q.251Easy

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

Q.252Easy

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

Q.253Easy

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

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

Q.255Easy

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

Q.256Easy

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

Q.257Easy

What does @Autowired annotation do in Spring?

Q.258Easy

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

Q.259Easy

In Spring Framework, what is the primary purpose of the @Autowired annotation?

Q.260Easy

Which of the following correctly describes the lifecycle of a singleton-scoped Spring bean?