What will happen if the overriding method is static in the superclass?
- It will lead to a compile-time error.
- The static method in the subclass will hide the static method in the superclass.
- The static method in the subclass will override the static method in the superclass.
- The static method in the superclass will hide the static method in the subclass.
When a method is declared as static in both the superclass and the subclass, it does not represent method overriding but method hiding. In such cases, the static method in the subclass will hide (not override) the static method in the superclass. The choice of which method to invoke depends on the reference type. If you call the method on the superclass reference, the superclass method is invoked; if you call it on the subclass reference, the subclass method is invoked.
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.
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.
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.