The process of converting a primitive data type into an object is known as ________.
- Boxing
- Casting
- Parsing
- Wrapping
The process of converting a primitive data type into an object is known as "boxing." Boxing involves creating an object (e.g., Integer, Double) from a primitive type (e.g., int, double). This is often required when using primitive types in contexts that expect objects, such as collections and generics.
What is the issue, if any, with the following statement: int[][] arr = new int[][5];?
- It declares a 2D array with a missing size for the first dimension.
- It declares a 2D array with a missing size for the second dimension.
- It declares a 2D array with a size of 5 for both dimensions.
- It declares a valid 2D array in Java.
The statement is incorrect because when declaring a 2D array, you need to specify the size of both dimensions. In this case, the size for the second dimension is missing (int[][5]). The correct syntax would be something like int[][] arr = new int[3][5];, where 3 is the number of rows, and 5 is the number of columns.
What is the role of Savepoint in JDBC transactions?
- It allows you to create a named point within a transaction where you can roll back to later
- It is a way to commit a transaction and make the changes permanent
- It is used to save the current state of a database before making any changes
- It is used to terminate a transaction prematurely
Savepoints in JDBC transactions allow you to create a named point within a transaction. This named point can be used to roll back the transaction to that specific point if needed, providing finer-grained control over transaction rollback. Options 2, 3, and 4 do not accurately describe the role of Savepoint in JDBC transactions.
Which of the following keywords is used to create a new object in Java?
- createObject
- new
- newInstance
- newObject
In Java, the new keyword is used to create a new object. When you want to instantiate a class and create an object, you use the new keyword followed by the class constructor. For example, ClassName obj = new ClassName();. The other options are not used to create objects in Java.
Consider a scenario where you are developing a menu-driven application. The user is presented with different options, and based on the user's selection, a specific action is performed. Which control structure would be the most appropriate to handle this?
- Do-while loop
- For loop
- Switch statement
- While loop
In this scenario, a switch statement would be the most appropriate control structure. It allows you to efficiently handle multiple options and execute specific code blocks based on the user's selection. Each case represents a different option, making the code more readable and maintainable compared to a series of if-else statements. The for, while, and do-while loops are used for iterative operations, not menu-driven options.
Which class should be used when a string is going to be modified frequently?
- StringArray
- StringBuffer
- StringBuilder
- StringModifier
When a string is going to be modified frequently in Java, the StringBuilder class should be used. This class provides a mutable sequence of characters and is more efficient for string manipulation operations compared to String or StringBuffer. The other options, StringBuffer, StringArray, and StringModifier, are not standard Java classes for string manipulation.
How can you create a bi-directional binding between two properties in JavaFX?
- By manually updating the properties.
- Using the addBinding() method.
- Using the bind() method.
- Using the bindBidirectional() method.
To create a bi-directional binding between two properties in JavaFX, you can use the bindBidirectional() method provided by the javafx.beans.property package. This method establishes a two-way connection between the properties, ensuring that changes in one property are automatically reflected in the other and vice versa. This is a powerful feature for maintaining consistency between related properties.
In a lambda expression, a pair of parentheses is used to define ________.
- Expressions
- Parameters
- Return Types
- Variables
In a lambda expression, a pair of parentheses is used to define the parameters that the lambda expression takes. These parameters can be used within the lambda body to perform operations and computations.
Which method is used to add an element to an ArrayList?
- add()
- append()
- insert()
- push()
The add() method is used to add an element to an ArrayList in Java. It appends the specified element to the end of the list. Other methods like insert(), append(), and push() are not used for adding elements to ArrayLists.
How does Java handle method overloading with autoboxing and varargs?
- Java allows method overloading, but it may lead to ambiguity.
- Java automatically selects the method based on the argument types.
- Java does not allow method overloading with autoboxing and varargs.
- The compiler throws an error due to ambiguity.
In Java, method overloading with autoboxing and varargs is allowed. However, it should be used with caution, as it can lead to ambiguity in certain cases. Java will automatically select the most specific method based on the argument types provided. This behavior allows you to use overloaded methods with autoboxing and varargs, but you should be aware of potential ambiguities.