Unit 6: Collections and Java Database Programming - Practice Quiz

CSE310 — Programming In Java 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is the primary advantage of using generics (e.g., ArrayList<String>) in Java Collections?

Creating a collection by using generics Easy
A. To make the collection automatically sorted.
B. To increase the runtime speed of the collection.
C. To allow collections to store primitive types like int directly.
D. To provide compile-time type safety and avoid ClassCastException.

2 Which of the following is the correct syntax to create an ArrayList that can only hold Integer objects?

Creating a collection by using generics Easy
A. ArrayList<int> list = new ArrayList<int>();
B. ArrayList<Integer> list = new ArrayList<>();
C. ArrayList list = new ArrayList<Integer>();
D. ArrayList(Integer) list = new ArrayList();

3 Which method is used to retrieve an element from an ArrayList at a specific index?

Implementing an ArrayList Easy
A. get(int index)
B. retrieve(int index)
C. element(int index)
D. fetch(int index)

4 Which statement about ArrayList is true?

Implementing an ArrayList Easy
A. Its size is fixed after creation.
B. It automatically sorts its elements.
C. It maintains the insertion order of elements.
D. It cannot contain duplicate elements.

5 What is the defining characteristic of a TreeSet?

Implementing TreeSet using Comparable and Comparator interfaces Easy
A. It stores key-value pairs.
B. It stores elements in the order they were inserted.
C. It allows multiple null elements.
D. It stores elements in a sorted order.

6 To enable natural sorting for a custom object in a TreeSet, which interface should the object's class implement?

Implementing TreeSet using Comparable and Comparator interfaces Easy
A. Comparator
B. Comparable
C. Orderable
D. Sortable

7 When would you use a Comparator instead of Comparable with a TreeSet?

Implementing TreeSet using Comparable and Comparator interfaces Easy
A. When the elements are primitive types.
B. When you want to define a custom sorting logic without modifying the element's class.
C. When you want to prevent sorting entirely.
D. When you want to store elements in insertion order.

8 A HashMap in Java is used to store data as:

Implementing a HashMap Easy
A. A set of unique, sorted elements
B. Key-value pairs
C. A stack of elements
D. A list of ordered elements

9 Which method is used to add or update an entry in a HashMap?

Implementing a HashMap Easy
A. add(K key, V value)
B. put(K key, V value)
C. set(K key, V value)
D. insert(K key, V value)

10 What does 'Deque' stand for?

Implementing a Deque Easy
A. Double Ended Queue
B. Default Queue
C. Data Entry Queue
D. Dynamic Execution Queue

11 Which of the following methods can be used to add an element to the end of a Deque?

Implementing a Deque Easy
A. push()
B. peek()
C. addLast()
D. addFirst()

12 What does JDBC stand for?

Introduction to JDBC Easy
A. Java Database Commands
B. Java Database Connectivity
C. Joint Database Connection
D. Java Data Binding and Control

13 What is the primary role of the java.sql.Connection interface in JDBC?

Introduction to JDBC Easy
A. To execute a SQL query.
B. To define the database URL.
C. To hold the results of a query.
D. To represent a session with a specific database.

14 What is the function of a JDBC Driver?

JDBC Drivers Easy
A. To create the database schema automatically.
B. To write the SQL queries for the programmer.
C. To translate JDBC API calls into the specific protocol of a database.
D. To manage the Java Virtual Machine (JVM).

15 Which class is commonly used to load a JDBC driver and establish a connection to a database?

JDBC Drivers Easy
A. SQLConnector
B. DriverManager
C. DriverLoader
D. ConnectionManager

16 In database terminology, what does the 'R' in CRUD stand for?

CRUD operation Using JDBC Easy
A. Remove
B. Read
C. Replace
D. Register

17 Which SQL statement corresponds to the 'Create' operation in CRUD?

CRUD operation Using JDBC Easy
A. UPDATE
B. SELECT
C. INSERT
D. CREATE TABLE

18 After executing a SELECT query in JDBC, which object is used to iterate through the returned rows?

CRUD operation Using JDBC Easy
A. ResultSet
B. Statement
C. Connection
D. RowSet

19 Which of the following is an example of a non-conventional or NoSQL database?

Connecting to non-conventional Databases Easy
A. Oracle Database
B. PostgreSQL
C. MongoDB
D. MySQL

20 How do Java applications typically connect to a NoSQL database like Redis or MongoDB?

Connecting to non-conventional Databases Easy
A. Using a specific Java driver provided by the database vendor.
B. Using a JDBC-ODBC bridge.
C. Using the standard Type 4 JDBC driver for all databases.
D. Java applications cannot connect to NoSQL databases.

21 Consider the following method. Which of the following method calls will result in a compile-time error?

JAVA
public static void processElements(List<? extends Number> list) {
    // method body
}

Creating a collection by using generics Medium
A. processElements(new ArrayList<Integer>());
B. processElements(new ArrayList<Double>());
C. processElements(new ArrayList<Number>());
D. processElements(new ArrayList<Object>());

22 What is the primary issue with the following code snippet?

JAVA
List<String> stringList = new ArrayList<>();
List<Object> objectList = stringList; // Line 2
objectList.add(123);
String s = stringList.get(0);

Creating a collection by using generics Medium
A. It will throw a ClassCastException when stringList.get(0) is called.
B. The code runs without any errors and s will hold the string "123".
C. It will throw an ArrayStoreException at runtime.
D. It will cause a compile-time error at Line 2.

23 What will be the output of the following code snippet?

JAVA
import java.util.ArrayList;
import java.util.List;

public class Test {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("A");
        list.add("B");
        list.add("C");
        list.add(1, "D");
        list.remove("B");
        System.out.println(list);
    }
}

Implementing an ArrayList Medium
A. [A, D, C]
B. [A, D, B, C]
C. An IndexOutOfBoundsException is thrown.
D. [D, A, C]

24 Which statement best describes the performance characteristics of adding an element to the beginning of a large ArrayList versus a large LinkedList?

Implementing an ArrayList Medium
A. ArrayList is faster because it avoids the overhead of node object creation.
B. LinkedList is faster because it only requires updating a few node references.
C. ArrayList is faster because it uses a contiguous block of memory.
D. Both have similar performance, approximately O(1).

25 Given the Employee class below, what is the result of executing the main method? The Employee class does not implement Comparable.

JAVA
class Employee {
    private int id;
    public Employee(int id) { this.id = id; }
}

public class TestSet {
    public static void main(String[] args) {
        Set<Employee> employees = new TreeSet<>();
        employees.add(new Employee(101));
        employees.add(new Employee(102));
        System.out.println(employees.size());
    }
}

Implementing TreeSet using Comparable and Comparator interfaces Medium
A. The code compiles and prints 2.
B. The code fails to compile because Employee is not Comparable.
C. The code compiles and prints 0.
D. The code compiles but throws a ClassCastException at runtime.

26 What is the output of the following code?

JAVA
import java.util.*;

class Product {
    String name;
    double price;
    Product(String name, double price) {
        this.name = name;
        this.price = price;
    }
    @Override
    public String toString() { return name; }
}

public class TestSort {
    public static void main(String[] args) {
        Comparator<Product> priceComparator = (p1, p2) -> Double.compare(p2.price, p1.price);
        Set<Product> products = new TreeSet<>(priceComparator);
        products.add(new Product("Laptop", 1200.0));
        products.add(new Product("Mouse", 25.0));
        products.add(new Product("Keyboard", 75.0));
        System.out.println(products);
    }
}

Implementing TreeSet using Comparable and Comparator interfaces Medium
A. The code will throw a ClassCastException.
B. [Mouse, Keyboard, Laptop]
C. [Laptop, Keyboard, Mouse]
D. [Laptop, Mouse, Keyboard]

27 Consider a Person class that implements Comparable by comparing ages. What happens if you add two different Person objects with the same age to a TreeSet<Person>?

JAVA
// Assume Person class with name and age fields
// and compareTo implemented as:
public int compareTo(Person other) {
    return Integer.compare(this.age, other.age);
}

// In main method:
Set<Person> personSet = new TreeSet<>();
personSet.add(new Person("Alice", 30));
personSet.add(new Person("Bob", 30));

Implementing TreeSet using Comparable and Comparator interfaces Medium
A. Only the first object ("Alice", 30) is added to the set.
B. Both objects are added to the set successfully.
C. A RuntimeException is thrown because of the duplicate age.
D. The behavior is undefined and depends on the JVM.

28 What will be printed to the console when the following code is executed?

JAVA
import java.util.HashMap;
import java.util.Map;

public class MapTest {
    public static void main(String[] args) {
        Map<String, Integer> map = new HashMap<>();
        map.put("A", 1);
        map.put("B", 2);
        Integer oldValue = map.put("A", 3);
        map.put(null, 4);
        map.put("C", null);

        System.out.println(oldValue + "," + map.size());
    }
}

Implementing a HashMap Medium
A. 3,5
B. 1,4
C. 1,5
D. null,5

29 You have a custom class Student that you want to use as a key in a HashMap. If you only override the equals() method but not the hashCode() method, what is the most likely consequence?

JAVA
// Assume Student class has id and name
// and equals() is correctly overridden based on id.
// hashCode() is NOT overridden.
Map<Student, String> grades = new HashMap<>();
Student s1 = new Student(1, "Alice");
Student s2 = new Student(1, "Alice"); // s1.equals(s2) is true
grades.put(s1, "A");
System.out.println(grades.get(s2));

Implementing a HashMap Medium
A. The program will most likely print null.
B. The program will fail to compile.
C. The program will throw a RuntimeException.
D. The program will print "A".

30 What is the output of this code snippet?

JAVA
import java.util.HashMap;

public class Test {
    public static void main(String[] args) {
        HashMap<Integer, String> map = new HashMap<>();
        map.put(1, "One");
        map.put(2, "Two");
        map.put(3, "One");

        map.compute(1, (k, v) -> v.concat("Plus"));
        map.computeIfAbsent(4, k -> "Four");
        map.computeIfPresent(2, (k, v) -> null);

        System.out.println(map);
    }
}

Implementing a HashMap Medium
A. {1=OnePlus, 2=Two, 3=One, 4=Four}
B. A NullPointerException is thrown.
C. {1=OnePlus, 2=null, 3=One, 4=Four}
D. {1=OnePlus, 3=One, 4=Four}

31 What is the final content of the deque and what is printed after executing the following code?

JAVA
import java.util.ArrayDeque;
import java.util.Deque;

public class DequeTest {
    public static void main(String[] args) {
        Deque<Integer> deque = new ArrayDeque<>();
        deque.push(10);
        deque.offerLast(20);
        deque.push(30);
        deque.offerFirst(40);
        System.out.print(deque.pollFirst() + ",");
        System.out.print(deque.pop());
    }
}

Implementing a Deque Medium
A. 10,20
B. 30,40
C. 40,10
D. 40,30

32 You need to implement a Last-In-First-Out (LIFO) stack data structure with a fixed capacity. If you use an ArrayDeque, which pair of methods should you use to add and remove elements to ensure that an exception is thrown if the operation cannot be completed (e.g., adding to a full stack)?

Implementing a Deque Medium
A. addFirst() and removeFirst()
B. offer() and poll()
C. offerFirst() and pollFirst()
D. add() and remove()

33 A Java application deployed on a client machine needs to connect to a corporate database. The client machine does not have any vendor-specific database libraries installed. A middle-tier application server is used to proxy database requests. Which type of JDBC driver is being described?

JDBC Drivers Medium
A. Type 1: JDBC-ODBC Bridge
B. Type 3: Network-Protocol Driver
C. Type 4: Thin Driver
D. Type 2: Native-API Driver

34 What is the primary advantage of using a Type 4 JDBC driver over a Type 2 driver for a standalone Java application that needs to be easily deployable on different operating systems?

JDBC Drivers Medium
A. Type 4 drivers provide better support for SQL-92 standards.
B. Type 4 drivers offer superior performance.
C. Type 4 drivers require an ODBC data source to be configured on the client machine.
D. Type 4 drivers are written in 100% pure Java and are platform-independent.

35 What does the integer value returned by the executeUpdate() method of a PreparedStatement typically represent when executing an UPDATE or DELETE statement?

CRUD operation Using JDBC Medium
A. The number of rows in the table that were affected by the execution.
B. The auto-generated key of the modified record.
C. The total number of rows in the table after the operation.
D. A status code indicating success (1) or failure (0).

36 Examine the following JDBC code snippet intended to prevent SQL injection. Which statement is most accurate?

JAVA
String userInput = "' OR '1'='1";
String query = "SELECT * FROM users WHERE username = '" + userInput + "' AND status = 'active'";
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(query);

CRUD operation Using JDBC Medium
A. This code is vulnerable to SQL injection; it should use PreparedStatement instead.
B. This code correctly uses a Statement and is safe from SQL injection.
C. This code is safe because the executeQuery method automatically sanitizes input.
D. This code will throw a SQLException because of the special characters in userInput.

37 Consider the following JDBC transaction management code. Assuming the DELETE statement is valid and affects 5 rows, what will be the state of the employees table after this code executes?

JAVA
Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
try {
    conn.setAutoCommit(false); // Start transaction
    Statement stmt = conn.createStatement();
    stmt.executeUpdate("DELETE FROM employees WHERE department = 'Sales'");
    conn.rollback(); // Roll back the transaction
    conn.commit();
} catch (SQLException e) {
    e.printStackTrace();
}

CRUD operation Using JDBC Medium
A. The 5 rows from the 'Sales' department will be permanently deleted.
B. An SQLException will be thrown when commit() is called after rollback().
C. The transaction will be in a pending state and will need to be manually committed later.
D. The employees table will be in its original state, as if the DELETE never happened.

38 When retrieving data from a ResultSet, what is the consequence of calling rs.getString("column_name") for a column that has a SQL NULL value?

CRUD operation Using JDBC Medium
A. It throws a NullPointerException.
B. It returns the empty string "".
C. It throws a SQLException indicating no data is available.
D. It returns a null reference.

39 Which of the following is a critical difference when establishing a JDBC connection to a NoSQL database (like Apache Cassandra) versus a traditional RDBMS (like PostgreSQL)?

Connecting to non-conventional Databases Medium
A. The java.sql.Connection interface is completely replaced by a vendor-specific interface.
B. NoSQL databases do not support the concept of transactions, so connection.setAutoCommit(false) will always fail.
C. The JDBC URL format and the specific driver class name are unique to the NoSQL database's JDBC driver.
D. PreparedStatement cannot be used with NoSQL databases due to the lack of a structured query language.

40 What is the primary role of the java.sql.DriverManager class in the JDBC API?

Introduction to JDBC Medium
A. To execute SQL queries and return a ResultSet.
B. To establish a connection to a database by selecting an appropriate driver from the list of registered drivers.
C. To provide metadata about the database, such as table names and column types.
D. To represent a specific database connection and manage transactions.

41 Consider a custom class Employee used as a key in a HashMap. The hashCode() method is correctly implemented, but the equals() method is mistakenly left as the default implementation from Object (i.e., this == obj). What is the primary consequence of this flawed implementation when two distinct Employee objects with identical content (and thus identical hash codes) are used?

Implementing a HashMap Hard
A. The second put() operation will add a new entry, and the map will contain two separate entries for logically equivalent keys, potentially in the same bucket.
B. The second put() operation with a logically equivalent but distinct key object will overwrite the first entry.
C. A RuntimeException will be thrown during the second put() operation due to the violation of the hashCode-equals contract.
D. Both objects will be stored in the HashMap in the same bucket, likely in a linked list or tree node, and get() will retrieve the first one inserted.

42 A TreeSet is created for a custom Product class. The Product class implements Comparable<Product> such that compareTo() only considers the product's price. What is the result of adding two different Product objects with the same price but different names to this TreeSet?

Implementing TreeSet using Comparable and Comparator interfaces Hard
A. The behavior is undefined and depends on the JVM implementation.
B. A ClassCastException is thrown because compareTo() is inconsistent with equals().
C. Only the first product is added; the add() call for the second product returns false.
D. Both products are added successfully as they are different objects.

43 You are executing a batch update using PreparedStatement.executeBatch(). The batch contains 100 SQL statements. The 50th statement fails due to a unique constraint violation. Assuming the JDBC driver supports batch update exceptions and there's no explicit transaction management (autoCommit is true), what is the state of the database and the return value of the method?

CRUD operation Using JDBC Hard
A. A standard SQLException is thrown, and the transaction is automatically rolled back, leaving the database unchanged.
B. The method returns an array of 100 integers, with the 50th element being Statement.EXECUTE_FAILED, and all other successful statements are committed.
C. A BatchUpdateException is thrown, and none of the 100 statements are committed to the database.
D. A BatchUpdateException is thrown. The first 49 statements are successfully committed, and the rest are not executed.

44 Analyze the following Java code. Why does the last line fail to compile?

JAVA
List<String> ls = new ArrayList<>();
List<? extends Object> lo = ls; 
// lo.add("Hello"); // This line fails to compile

Creating a collection by using generics Hard
A. Because List<? extends Object> is equivalent to List<Object>, and a List<String> cannot be assigned to it without an explicit cast.
B. Because lo is immutable and cannot be modified.
C. Because of type erasure, the compiler cannot guarantee that adding a String is type-safe.
D. Because the wildcard ? extends Object makes the list a producer (readable), but not a consumer (writable), except for null.

45 In a cloud-native microservices architecture where services are deployed in Docker containers, which JDBC driver type is almost universally preferred and why?

JDBC Drivers Hard
A. Type 1 (JDBC-ODBC Bridge), because it provides maximum compatibility with legacy systems.
B. Type 2 (Native-API Driver), because it offers the highest performance by using native database libraries.
C. Type 3 (Network-Protocol Driver), because it allows for a middle-tier server to handle database connections, improving security.
D. Type 4 (Database-Protocol Driver), because it is a self-contained, platform-independent pure Java driver, simplifying deployment and eliminating native dependencies.

46 An ArrayList is created with an initial capacity of 10. You then add 10 elements. What happens internally when you attempt to add the 11th element, and what is the amortized time complexity of adding N elements one by one to an initially empty ArrayList?

Implementing an ArrayList Hard
A. A new array, typically of size 15 (old capacity * 1.5), is created, and all 10 old elements are copied over. The amortized time complexity is .
B. A new array, typically of size 15 (old capacity * 1.5), is created, and all 10 old elements are copied over. The amortized time complexity is .
C. The ArrayList is converted to a LinkedList to accommodate the new element. The amortized time complexity is .
D. A new array of size 11 is created, and all 10 old elements are copied over. The amortized time complexity is .

47 You need a data structure that can function as a LIFO stack but must also provide capacity-restriction without throwing an exception upon failure. Which Deque implementation and method should you use to add elements?

Implementing a Deque Hard
A. LinkedList and the addFirst() method.
B. ArrayDeque and the push() method.
C. ArrayDeque and the addFirst() method.
D. LinkedBlockingDeque and the offerFirst() method.

48 Consider a JDBC transaction set to TRANSACTION_SERIALIZABLE isolation level. A long-running transaction (T1) reads all employees in the 'sales' department. While T1 is still active, another transaction (T2) attempts to insert a new employee into the 'sales' department and commit. What is the most likely outcome?

CRUD operation Using JDBC Hard
A. T2 will be blocked until T1 completes (either commits or rolls back).
B. T2 will commit successfully, but T1 will not see the new employee, even if it re-queries, thus preventing a phantom read.
C. T2 commits successfully, and a subsequent read by T1 within the same transaction will see the new employee (a phantom read).
D. T1 will immediately throw a SQLException because its result set has been invalidated by T2's insert.

49 What is the key difference between the state of an ArrayList after calling trimToSize() versus clear()?

Implementing an ArrayList Hard
A. trimToSize() has no effect if capacity equals size; clear() replaces the internal array with a new empty array.
B. Both methods set the size to 0, but trimToSize() deallocates the internal array while clear() fills it with null values.
C. trimToSize() removes all elements and sets capacity to 0; clear() only sets the size to 0 but keeps the internal array.
D. trimToSize() sets the capacity to the current size; clear() sets the size to 0 but leaves the capacity unchanged.

50 When using a JDBC driver for a key-value store like Redis, which JDBC concept is the most difficult to map meaningfully and is often implemented with significant limitations?

Connecting to non-conventional Databases Hard
A. Executing simple key lookups (PreparedStatement with WHERE key = ?).
B. Connection Management (DriverManager, DataSource).
C. Complex cross-key transactions with ACID properties.
D. Multi-row result sets from a single query (ResultSet).

51 Given the following code, what is the output?
java
class Person {
int id;
public Person(int id) { this.id = id; }
@Override public int hashCode() { return id; }
// equals() is NOT overridden
}

Set<Person> set = new HashSet<>();
set.add(new Person(1));
set.add(new Person(1));

TreeSet<Person> treeSet = new TreeSet<>(Comparator.comparingInt(p -> p.id));
treeSet.addAll(set);

System.out.println(treeSet.size());

Implementing TreeSet using Comparable and Comparator interfaces Hard
A. 0
B. 2
C. 1
D. A RuntimeException is thrown.

52 In Java 8, HashMap buckets convert from a linked list to a balanced tree (specifically, a red-black tree) when the number of nodes in a bucket reaches a certain threshold. What is the primary reason for this change and under what condition does it occur?

Implementing a HashMap Hard
A. To improve worst-case performance from to for bucket operations; this occurs when TREEIFY_THRESHOLD (default 8) is reached AND the map's total capacity is at least MIN_TREEIFY_CAPACITY (default 64).
B. To improve worst-case performance from to for bucket operations; this occurs as soon as the bucket size exceeds TREEIFY_THRESHOLD (default 8).
C. To save memory; this occurs when TREEIFY_THRESHOLD (default 8) is reached and map capacity is at least 64.
D. To handle null keys more efficiently; this occurs when a bucket containing a null key exceeds TREEIFY_THRESHOLD (default 8).

53 You create a PreparedStatement from a Connection object and then execute it 1000 times with different parameters in a loop. Separately, you create a Statement object and execute 1000 different SQL queries by concatenating strings in a loop. Why is the PreparedStatement approach significantly more performant, especially in a client-server database model?

CRUD operation Using JDBC Hard
A. PreparedStatement sends the query to the database only once; subsequent executions only send the new parameter values.
B. PreparedStatement automatically batches the requests, sending all 1000 at once.
C. PreparedStatement is faster because it prevents SQL injection, which has a high-performance overhead.
D. PreparedStatement uses a more optimized network protocol than Statement.

54 Consider an ArrayDeque<Integer>. What is the fundamental difference in behavior and outcome between calling remove() on an empty deque versus calling poll() on an empty deque?

Implementing a Deque Hard
A. Both return null.
B. Both throw a NoSuchElementException.
C. remove() throws a NoSuchElementException, while poll() returns null.
D. remove() returns null, while poll() throws a NoSuchElementException.

55 Given the following two method signatures in a class, what is the outcome?

JAVA
public void process(List<String> list) { /* ... */ }
public void process(List<Integer> list) { /* ... */ }

Creating a collection by using generics Hard
A. The code compiles only if one of the methods is declared static.
B. The code compiles, but at runtime, a ClassCastException will be thrown when either method is called.
C. The code compiles successfully, and method overloading works as expected based on the list's type.
D. The code fails to compile due to a clash, as type erasure removes the generic type information, making both signatures identical to the JVM.

56 In a modern, high-concurrency enterprise application, why is obtaining database connections via a DataSource object overwhelmingly preferred over using the traditional DriverManager.getConnection() method?

Introduction to JDBC Hard
A. DataSource is part of the newer JDBC 4.0 specification, while DriverManager is deprecated.
B. DataSource allows for connecting to non-conventional databases, which DriverManager does not support.
C. DataSource implementations typically provide connection pooling, which is crucial for performance and scalability by reusing existing connections.
D. DataSource provides a standardized way to handle different JDBC driver types, whereas DriverManager requires manual driver loading.

57 What happens if you obtain a subList from an ArrayList and then add an element to the original list?

Implementing an ArrayList Hard
A. The subList view is updated to reflect the new element if it falls within its range.
B. A ConcurrentModificationException will be thrown immediately upon modifying the original list.
C. Any subsequent attempt to access the subList (e.g., get(), size(), iterator()) will result in a ConcurrentModificationException.
D. The subList is unaffected as it is a copy of the original elements.

58 A HashMap is created with the default load factor (0.75) and default initial capacity (16). At what point will the map first trigger a resize operation?

Implementing a HashMap Hard
A. When the 16th element is added.
B. When the 13th element is added.
C. When the 17th element is added.
D. When the 12th element is added.

59 When creating a Statement, you can specify ResultSet.TYPE_SCROLL_SENSITIVE. What does this constant primarily enable and what is its major performance trade-off?

CRUD operation Using JDBC Hard
A. It enables the ResultSet to see updates and deletes made by others but not inserts (preventing phantom reads). It has moderate performance overhead.
B. It allows the ResultSet to be updated, but it is not sensitive to changes made by other transactions. It has high performance.
C. It creates a static snapshot of the data at the time of the query, preventing any updates from being seen. It has low performance overhead.
D. It allows bidirectional iteration over the ResultSet and makes it sensitive to changes (updates, deletes, inserts) made by other transactions after the ResultSet was created. It can be very resource-intensive for the database and driver.

60 A class Point has a compareTo method that is not transitive. Specifically, p1.compareTo(p2) > 0, p2.compareTo(p3) > 0, but p1.compareTo(p3) < 0. What is the likely result of adding these three points to a TreeSet?

Implementing TreeSet using Comparable and Comparator interfaces Hard
A. The TreeSet will contain all three points in a stable, predictable order.
B. The add method for p3 will return false as it will be considered a duplicate of p1.
C. The code will compile and run, but the internal red-black tree structure of the TreeSet will be corrupted, leading to undefined behavior on subsequent operations like contains() or remove().
D. An IllegalArgumentException or ClassCastException might be thrown during one of the insertions.