The ________ statement can be used to prematurely exit a loop based on a particular condition.

  • Break Statement
  • Continue Statement
  • Exit Statement
  • Return Statement
In Java, the "break" statement is used to prematurely exit a loop based on a particular condition. It is commonly used in "for" and "while" loops to exit the loop when a specific condition is met. The other options (2 to 4) have different purposes and are not used for exiting loops.

The ______ method of the Future interface is used to check if the task is done or not.

  • checkDone()
  • hasCompleted()
  • isDone()
  • taskStatus()
In Java, the isDone() method of the Future interface is used to check if a task submitted to a ExecutorService is completed or not. It returns true if the task is done; otherwise, it returns false.

The ________ Interface extends Collection and declares the behavior of containers

  • Iterable
  • List
  • Map
  • Queue
The List interface extends the Collection interface in Java. It is used to represent ordered collections of elements, allowing duplicates and providing various methods to manipulate the list. The other options do not extend Collection.

To prevent fall-through in a switch case, the ________ keyword is used after each case block.

  • break
  • continue
  • exit
  • return
To prevent fall-through in a switch case in Java, you use the break keyword after each case block. This ensures that once a case is matched and executed, the control exits the switch statement and doesn't fall through to subsequent cases.

Which of the following keywords is used to manually throw an exception in Java?

  • catch
  • throw
  • throws
  • try
In Java, the throw keyword is used to manually throw an exception. It allows you to create custom exceptions or raise predefined exceptions when certain conditions are met. This is a fundamental part of Java's exception handling mechanism.

What is the primary advantage of using an ExecutorService to manage threads?

  • Automatic garbage collection
  • Better control over thread creation and reuse
  • Greater parallelism and multi-threading control
  • Simplicity in managing threads
The primary advantage of using an ExecutorService to manage threads is better control over thread creation and reuse. It provides a higher-level abstraction for managing thread execution, which can lead to more efficient and scalable applications. The other options do not accurately describe the primary advantage of using an ExecutorService.

________ is the class in Java that provides methods to get details of a URL and manipulate them.

  • URIDetails
  • URL
  • URLDetails
  • URLManipulator
The correct answer is "URL." In Java, the URL class provides methods to get details of a URL and manipulate them. You can use URL class methods to retrieve various components of a URL, such as the protocol, host, port, path, and more. It is a fundamental class for working with URLs in Java.

The ________ method of Connection interface sets the changes made since the previous commit/rollback permanent.

  • commit()
  • persistChanges()
  • saveChanges()
  • updateChanges()
The commit() method of the Connection interface in JDBC is used to make the changes made since the previous commit or rollback permanent. It effectively saves the changes to the database. Other options are not valid methods for this purpose.

A loop that contains another loop is known as a ________ loop.

  • double
  • enclosing
  • inner
  • nested
In Java, a loop that contains another loop is called a "nested loop." Nested loops are used when you need to perform repetitive tasks within repetitive tasks. The inner loop is executed multiple times for each iteration of the outer loop. This nesting can be done with various loop types like for, while, or do-while.

How does autoboxing and unboxing affect performance, especially in collections that deal with primitive data types?

  • Autoboxing and unboxing have no impact on performance.
  • Autoboxing and unboxing can significantly degrade performance.
  • Autoboxing improves performance, while unboxing degrades it.
  • Autoboxing and unboxing have negligible performance impact.
Autoboxing (converting a primitive type to its corresponding wrapper type) and unboxing (converting a wrapper type to its corresponding primitive type) can have a significant impact on performance, especially in collections that deal with primitive data types (e.g., ArrayList). Each autoboxing and unboxing operation involves creating or extracting wrapper objects, which consumes memory and introduces overhead. This can lead to performance degradation in scenarios where these operations are frequent, such as large collections or loops. It's important to be aware of this when designing applications to avoid unnecessary autoboxing and unboxing.