Author name: admin

Which Java 9 feature allows developers to interactively evaluate code snippets?

Java MCQ: Which Java 9 feature allows developers to interactively evaluate code snippets? a) JavaFX b) JShell c) JConsole d) Javadoc Answer: b) JShell Explanation: JShell is a feature introduced in Java 9 that allows developers to interactively evaluate code snippets. JShell, also known as the REPL (Read-Eval-Print Loop) tool, provides an environment where developers […]

Which Java 9 feature allows developers to interactively evaluate code snippets? Read More »

What is the primary purpose of the Java Module System introduced in Java 9?

Java MCQ: What is the primary purpose of the Java Module System introduced in Java 9? a) To improve multithreading capabilities b) To encapsulate packages and improve code organization c) To replace the JDK d) To enhance the GUI framework Answer: b) To encapsulate packages and improve code organization Explanation: The primary purpose of the

What is the primary purpose of the Java Module System introduced in Java 9? Read More »

Which of the following best describes the purpose of the DateTimeFormatter class in Java 8?

Java MCQ: Which of the following best describes the purpose of the DateTimeFormatter class in Java 8? a) To convert a date-time object to a String and vice versa b) To manage time zones c) To parse legacy date formats d) To store time zone rules Answer: a) To convert a date-time object to a

Which of the following best describes the purpose of the DateTimeFormatter class in Java 8? Read More »

Which Stream API method is used to execute a terminal operation that does not produce a result but applies an action to each element?

Java MCQ: Which Stream API method is used to execute a terminal operation that does not produce a result but applies an action to each element? a) collect() b) reduce() c) forEach() d) map() Answer: c) forEach() Explanation: The forEach() method in the Stream API is used to execute a terminal operation that does not

Which Stream API method is used to execute a terminal operation that does not produce a result but applies an action to each element? Read More »

Which Java 8 feature allows interfaces to include methods with implementations?

Java MCQ: Which Java 8 feature allows interfaces to include methods with implementations? a) Functional interfaces b) Default methods c) Lambda expressions d) Stream API Answer: b) Default methods Explanation: Default methods in Java 8 allow interfaces to include methods with implementations. This feature was introduced to enable interface evolution without breaking existing implementations. A

Which Java 8 feature allows interfaces to include methods with implementations? Read More »

What is the main advantage of using lambda expressions in Java?

Java MCQ: What is the main advantage of using lambda expressions in Java? a) They improve runtime performance b) They reduce the amount of boilerplate code required for anonymous classes c) They enforce immutability in Java classes d) They allow for multiple inheritance Answer: b) They reduce the amount of boilerplate code required for anonymous

What is the main advantage of using lambda expressions in Java? Read More »

Which method in the Stream API is used to filter elements based on a predicate?

Java MCQ: Which method in the Stream API is used to filter elements based on a predicate? a) map() b) filter() c) collect() d) reduce() Answer: b) filter() Explanation: The filter() method in the Stream API is used to filter elements based on a predicate. A predicate is a functional interface that represents a boolean-valued

Which method in the Stream API is used to filter elements based on a predicate? Read More »

Which method in the Optional class is used to provide a default value if the Optional is empty?

Java MCQ: Which method in the Optional class is used to provide a default value if the Optional is empty? a) orElse() b) get() c) ifPresent() d) orElseThrow() Answer: a) orElse() Explanation: The orElse() method in the Optional class is used to provide a default value if the Optional is empty. This method returns the

Which method in the Optional class is used to provide a default value if the Optional is empty? Read More »

Which of the following statements is true about static methods in interfaces in Java 8?

Java MCQ: Which of the following statements is true about static methods in interfaces in Java 8? a) Static methods in interfaces can only be called on an instance of the interface b) Static methods in interfaces can be called without an instance of the interface c) Static methods in interfaces must be overridden in

Which of the following statements is true about static methods in interfaces in Java 8? Read More »

Which package in Java 8 provides the new Date and Time API?

Java MCQ: Which package in Java 8 provides the new Date and Time API? a) java.util.time b) java.date c) java.time d) java.timezone Answer: c) java.time Explanation: The java.time package in Java 8 provides the new Date and Time API. This API was introduced to address the shortcomings of the older java.util.Date and java.util.Calendar classes, which

Which package in Java 8 provides the new Date and Time API? Read More »

Which interface in Java 8 is annotated with @FunctionalInterface?

Java MCQ: Which interface in Java 8 is annotated with @FunctionalInterface? a) List b) Runnable c) Comparator d) Map Answer: b) Runnable Explanation: The Runnable interface in Java is annotated with @FunctionalInterface in Java 8. A functional interface is an interface that contains exactly one abstract method. These interfaces can be used as the assignment

Which interface in Java 8 is annotated with @FunctionalInterface? Read More »

Which feature introduced in Java 8 allows interfaces to have methods with implementations?

Java MCQ: Which feature introduced in Java 8 allows interfaces to have methods with implementations? a) Abstract methods b) Default methods c) Static methods d) Anonymous methods Answer: b) Default methods Explanation: Java 8 introduced default methods, which allow interfaces to have methods with implementations. This feature was added to enable the evolution of interfaces

Which feature introduced in Java 8 allows interfaces to have methods with implementations? Read More »

What is the primary purpose of Java Lambda Expressions?

Java MCQ: What is the primary purpose of Java Lambda Expressions? a) To define anonymous classes b) To enable functional programming by passing behavior as an argument c) To enhance exception handling d) To manage multithreading Answer: b) To enable functional programming by passing behavior as an argument Explanation: Java Lambda Expressions were introduced in

What is the primary purpose of Java Lambda Expressions? Read More »

Which of the following best describes atomic variables in Java?

Java MCQ: Which of the following best describes atomic variables in Java? a) Variables that are read and written atomically, ensuring thread safety without synchronization b) Variables that can be divided into smaller parts for parallel processing c) Variables that are synchronized using the synchronized keyword d) Variables that hold references to multiple objects simultaneously

Which of the following best describes atomic variables in Java? Read More »

Which class in Java provides a mechanism for creating reentrant locks?

Java MCQ: Which class in Java provides a mechanism for creating reentrant locks? a) ReentrantLock b) LockManager c) SynchronizedLock d) ThreadLock Answer: a) ReentrantLock Explanation: The ReentrantLock class in Java provides a mechanism for creating reentrant locks. It is part of the java.util.concurrent.locks package and is used as an alternative to the synchronized keyword for

Which class in Java provides a mechanism for creating reentrant locks? Read More »

Which interface in Java is used to define a task that returns a result and can be executed by an ExecutorService?

Java MCQ: Which interface in Java is used to define a task that returns a result and can be executed by an ExecutorService? a) Runnable b) Callable c) Executable d) Task Answer: b) Callable Explanation: The Callable interface in Java is used to define a task that returns a result and can be executed by

Which interface in Java is used to define a task that returns a result and can be executed by an ExecutorService? Read More »

Scroll to Top