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.

When converting byte streams to character streams, which class is useful to handle the conversion?

  • ByteStreamReader
  • ByteToCharConverterStream
  • InputStreamReader
  • InputStreamWriter
When converting byte streams to character streams, you should use the InputStreamWriter class. It's used to bridge from byte streams to character streams and handles character encoding. ByteStreamReader and ByteToCharConverterStream are not standard classes in Java. InputStreamReader is used for byte-to-character conversion but not for handling the entire conversion process.

Imagine you are developing a system where multiple transactions are handled concurrently. How would you manage to prevent dirty reads and ensure data consistency?

  • Encapsulating data access logic within stored procedures or functions to prevent direct access to data.
  • Implementing database isolation levels like READ_COMMITTED or SERIALIZABLE to control the visibility of data changes to different transactions.
  • Using synchronized methods in Java to lock the critical section of code to prevent concurrent access to the data.
  • Utilizing database transactions and employing concepts like ACID (Atomicity, Consistency, Isolation, Durability) to ensure data integrity.
In a multi-transactional system, it's crucial to manage data consistency and prevent dirty reads. Database isolation levels help in achieving this. READ_COMMITTED ensures that a transaction can't read uncommitted changes from other transactions. SERIALIZABLE provides the highest level of isolation, preventing concurrent access to the same data. It's essential to understand these concepts for maintaining data integrity.

When creating a custom exception, extending which class will make it a checked exception?

  • Error
  • Exception
  • RuntimeException
  • Throwable
When you extend the Exception class (or its subclasses), your custom exception becomes a checked exception in Java. Checked exceptions must be either caught or declared in the method signature where they are thrown.