Subject : Advanced Java Programming
Unit 5: Interacting with Database
1. Which of the following is a JDBC driver?
A. MySQL Connector/J B. PostgreSQL JDBC Driver
C. Oracle JDBC Driver D. All of the above
Answer: _____________________________________
2. Which of the following is a PreparedStatement?
A. A statement that is used to execute SQL queries
B. A statement that is used to insert, update, or delete data in a
database
C. A statement that is used to retrieve metadata about a database
D. All of the above
Answer: _______________________________________________
3. Which of the following is a ResultSet?
A. An object that contains the results of a SQL query
B. An object that is used to execute SQL queries
C. An object that is used to insert, update, or delete data in a
database
D. None of the above
Answer: _______________________________________________
4. Which of the following methods is used to execute a SQL query?
A. execute() B. executeQuery()
C. executeUpdate() D. All of the above
Answer: _______________________________________________
5. Which of the following methods is used to close a database
connection?
A. close() B. disconnect()
C. release() D. All of the above
Answer: _______________________________________________
6. Which of the following is a good practice to follow when
interacting with databases?
A. Use a connection pool to manage database connections.
B. Use PreparedStatements to prevent SQL injection.
C. Close database connections as soon as you are finished with them.
D. All of the above
Answer: _______________________________________________
7. Which of the following is a type of transaction?
A. Read-committed B. Repeatable-read
C. Serializable D. All of the above
Answer: _______________________________________________
8. Which of the following methods is used to start a transaction?
A. setAutoCommit(false) B. startTransaction()
C. beginTransaction() D. All of the above
Answer: _______________________________________________
9. Which of the following methods is used to commit a transaction?
A. commit() B. endTransaction()
C. rollback() D. None of the above
Answer: _______________________________________________
10. Which of the following methods is used to rollback a
transaction?
A. commit() B. endTransaction()
C. rollback() D. None of the above
Answer: _______________________________________________
11. Which of the following is a type of database lock?
A. Shared lock B. Exclusive lock
C. Deadlock D. All of the above
Answer: _______________________________________________
12. Which of the following is a method for preventing deadlocks?
A. Ordering locks B. Using lock timeouts
C. Detecting and resolving deadlocks D. All of the above
Answer: _______________________________________________
13. Which of the following is a database schema?
A. The logical structure of a database
B. The physical structure of a database
C. The data contained in a database D. None of the above
Answer: _______________________________________________
14. Which of the following is a database table?
A. A logical collection of data B. A physical collection of data
C. A data type D. None of the above
Answer: _______________________________________________
15. Which of the following is a database column?
A. A field in a database table B. A data type
C. A row in a database table D. None of the above
Answer: _______________________________________________
16. Which of the following is a database index?
A. A data structure that improves the performance of database queries
B. A constraint that is used to enforce data integrity
C. A type of database lock D. None of the above
Answer: _______________________________________________
17. Which of the following is a database constraint?
A. A data rule that is used to ensure the accuracy and consistency of data
B. A data structure that improves the performance of database queries
C. A type of database lock D. None of the above
Answer: _______________________________________________
18. Which of the following is a database view?
A. A virtual table that is based on one or more database tables
B. A data rule that is used to ensure the accuracy and consistency of data
C. A data structure that improves the performance of database queries
D. None of the above
Answer: _______________________________________________
19. Which of the following is a database function?
A. A named set of SQL statements that can be executed as a single unit
B. A named set of SQL statements that returns a value
C. A data rule that is used to ensure the accuracy and consistency of data
D. None of the above
Answer: _______________________________________________
20. Which of the following is a database trigger?
A. A named set of SQL statements that can be executed as a single unit
B. A named set of SQL statements that returns a value
C. A data rule that is used to ensure the accuracy and consistency of data
D. A named set of SQL statements that is executed automatically when a
certain event occurs
Answer: _______________________________________________
21. Which of the following is a JDBC connection pool?
A. A set of database connections that are managed by a pool manager
B. A JDBC driver that provides a more efficient way to manage database
connections
C. A database schema that is optimized for performance
D. None of the above
Answer: _______________________________________________
22. Which of the following is a benefit of using a JDBC connection
pool?
A. Improved performance B. Reduced memory usage
C. Improved scalability D. All of the above
Answer: _______________________________________________
23. Which of the following is a good practice to follow when using a
JDBC connection pool?
A. Return connections to the pool as soon as you are finished with them.
B. Use separate connection pool for each database that you are connecting to.
C. Configure the connection pool to have a maximum number of connections.
D. All of the above
Answer: _______________________________________________
24. Which of the following is a type of database exception?
A. SQLException B. ClassNotFoundException
C. IOException D. All of the above
Answer: _______________________________________________
25. Which of the following methods is used to handle a database
exception?
A. try-catch block B. throws clause
C. finally block D. All of the above
Answer: _______________________________________________
26. Which of the following is a good practice to follow when
handling database exceptions?
A. Log the exception.
B. Roll back the transaction, if one is in progress.
C. Close the database connection, if it is open. D. All of the above
Answer: _______________________________________________
27. Which of the following is a type of object-relational mapping
(ORM) framework?
A. Hibernate B. JPA
C. Spring Data JPA D. All of the above
Answer: _______________________________________________
28. Which of the following is a benefit of using an ORM framework?
A. Increased productivity B. Improved code quality
C. Reduced risk of errors D. All of the above
Answer: _______________________________________________
29. Which of the following is a good practice to follow when using
an ORM framework?
A. Use the ORM framework to manage all of your database
interactions.
B. Use the ORM framework to generate your database schema.
C. Use the ORM framework to cache database objects.
D. All of the above
Answer: _______________________________________________
30. Which of the following is a database indexing technique?
A. B-tree B. Hash table
C. Trie D. All of the above
Answer: _______________________________________________
31. Which of the following is a database partitioning technique?
A. Horizontal partitioning B. Vertical partitioning
C. Range partitioning D. All of the above
Answer: _______________________________________________
32. Which of the following is a database replication technique?
A. Synchronous replication B. Asynchronous replication
C. Master-slave replication D. All of the above
Answer: _______________________________________________
33. Which of the following is a database load balancing technique?
A. Round robin B. Weighted round robin
C. Least connections D. All of the above
Answer: _______________________________________________
34. Which of the following is a database transaction isolation level?
A. Read uncommitted B. Read committed
C. Repeatable read D. Serializable
Answer: _______________________________________________
35. Which of the following is a database concurrency control
technique?
A. Locking B. Optimistic concurrency control
C. Timestamping D. All of the above
Answer: _______________________________________________
36. Which of the following is a database security technique?
A. Authentication B. Authorization
C. Encryption D. All of the above
Answer: _______________________________________________
37. Which of the following is a distributed database?
A. A database that is spread across multiple physical servers
B. A database that is managed by a single database management
system
C. A database that is designed to be used by multiple applications
D. All of the above
Answer: _______________________________________________
38. Which of the following is a NoSQL database?
A. A database that does not use SQL to query data
B. A database that is designed to scale horizontally
C. A database that is optimized for a specific type of data
D. All of the above
Answer: _______________________________________________
39. Which of the following is a benefit of using a NoSQL database?
A. Scalability B. Performance
C. Flexibility D. All of the above
Answer: _______________________________________________
40. Which of the following is a good practice to follow when
designing a database schema?
A. Normalize the schema to reduce data redundancy
B. Use appropriate data types for each column
C. Create indexes on frequently accessed columns
D. All of the above
Answer: _______________________________________________
41. Which of the following is a good practice to follow when writing
database queries?
A. Use prepared statements to prevent SQL injection
B. Use appropriate indexes to improve performance
C. Avoid using SELECT * queries
D. All of the above
Answer: _______________________________________________
42. Which of the following is a good practice to follow when
managing database transactions?
A. Start a transaction before performing any database operations
B. Commit the transaction if all of the database operations were
successful
C. Roll back the transaction if any of the database operations failed
D. All of the above
Answer: _______________________________________________
43. Which of the following is a good practice to follow when using a
JDBC connection pool?
A. Return connections to the pool as soon as you are finished with them
B. Use separate connection pool for each database that you are connecting to
C. Configure the connection pool to have a maximum number of connections
D. All of the above
Answer: _______________________________________________
44. Which of the following is a good practice to follow when using
an ORM framework?
A. Use ORM framework to manage all of your database interactions
B. Use the ORM framework to generate your database schema
C. Use the ORM framework to cache database objects
D. All of the above
Answer: _______________________________________________
45. Which of the following is a good practice to follow when
designing a distributed database?
A. Use a database partitioning strategy to distribute the data across
multiple servers
B. Use a database replication strategy to keep the data synchronized
across all of the servers
C. Use a database load balancing strategy to distribute the traffic
across all of the servers
D. All of the above
Answer: _______________________________________________
46. Which of the following is a good practice to follow when writing
NoSQL database queries?
A. Use the appropriate query language for the NoSQL database that
you are using
B. Use filters to narrow down the results of your queries
C. Use projections to return only the data that you need
D. All of the above
Answer: _______________________________________________
47. Which of the following is a good practice to follow when
managing database security?
A. Use strong passwords for all database accounts
B. Grant users the least privileges necessary
C. Regularly audit database activity
D. All of the above
Answer: _______________________________________________
48. Which of the following is a good practice to follow when
monitoring database performance?
A. Collect metrics such as CPU usage, memory usage, and query
execution times
B. Analyze the metrics to identify areas where performance can be
improved
C. Implement performance improvements and monitor their impact
D. All of the above
Answer: _______________________________________________
49. Which of the following is a database performance tuning
technique?
A. Normalizing the database schema
B. Creating indexes on frequently accessed columns
C. Using appropriate data types for each column
D. All of the above
Answer: _______________________________________________
50. Which of the following is a database monitoring tool?
A. JConsole B. VisualVM
C. New Relic D. All of the above
Answer: _______________________________________________
51. Which of the following is a database development tool?
A. Eclipse B. IntelliJ IDEA
C. MySQL Workbench D. All of the above
Answer: _______________________________________________
52. Which of the following is a database migration tool?
A. Liquibase B. Flyway
C. SchemaSpy D. All of the above
Answer: _______________________________________________
53. Which of the following is a database backup and recovery tool?
A. pg_dump B. mysqldump
C. Oracle RMAN D. All of the above
Answer: _______________________________________________
54. Which of the following is a database testing tool?
A. JUnit B. TestNG
C. Selenium D. All of the above
Answer: _______________________________________________
55. Which of the following is a database performance
benchmarking tool?
A. JMeter B. Gatling
C. LoadRunner D. All of the above
Answer: _______________________________________________
56. Which of the following is a database administration task?
A. Creating and managing database users
B. Granting and revoking user privileges
C. Monitoring database performance D. All of the above
Answer: _______________________________________________
57. Which of the following is a database security task?
A. Creating and managing database passwords
B. Auditing database activity
C. Implementing database encryption D. All of the above
Answer: _______________________________________________
58. Which of the following is a database development task?
A. Designing the database schema
B. Writing database queries
C. Creating and managing database tables D. All of the above
Answer: _______________________________________________
59. Which of the following is a database migration task?
A. Upgrading the database schema to a newer version
B. Moving data from one database to another
C. Creating a copy of the database for testing purposes
D. All of the above
Answer: _______________________________________________
60. Which of the following is a database backup and recovery task?
A. Creating a backup of the database
B. Restoring a database from a backup
C. Testing the database backup D. All of the above
Answer: _______________________________________________
61. Which of the following is a database testing task?
A. Testing the database schema B. Testing database queries
C. Testing database procedures and functions D. All of the above
Answer: _______________________________________________
62. Which of the following is a database performance
benchmarking task?
A. Measuring the performance of database queries
B. Measuring the performance of database transactions
C. Measuring the performance of the database overall
D. All of the above
Answer: _______________________________________________
63. Which of the following is a benefit of using a database
management system (DBMS)?
A. Data integrity
B. Data security
C. Data accessibility
D. All of the above
Answer: _______________________________________________
64. Which of the following is a function of a DBMS?
A. To store data in a database
B. To manage access to data in a database
C. To protect the data in a database D. All of the above
Answer: _______________________________________________
65. Which of the following is a type of database lock?
A. Shared lock B. Exclusive lock
C. Deadlock D. All of the above
Answer: _______________________________________________
66. Which of the following is a method for preventing deadlocks?
A. Ordering locks B. Using lock timeouts
C. Detecting and resolving deadlocks D. All of the above
Answer: _______________________________________________
67. Which of the following is a database schema?
A. The logical structure of a database
B. The physical structure of a database
C. The data contained in a database
D. None of the above
Answer: _______________________________________________
68. Which of the following is a database table?
A. A logical collection of data B. A physical collection of data
C. A data type D. None of the above
Answer: _______________________________________________
69. Which of the following is a database column?
A. A field in a database table B. A data type
C. A row in a database table D. None of the above
Answer: _______________________________________________
70. Which of the following is a database index?
A. A data structure that improves the performance of database
queries
B. A constraint that is used to enforce data integrity
C. A type of database lock D. None of the above
Answer: _______________________________________________
71. Which of the following is a database constraint?
A. A data rule that is used to ensure the accuracy and consistency of data
B. A data structure that improves the performance of database queries
C. A type of database lock D. None of the above
Answer: _______________________________________________
72. Which of the following is a database view?
A. A virtual table that is based on one or more database tables
B. A data rule that is used to ensure the accuracy and consistency of
data
C. A data structure that improves the performance of database
queries
D. None of the above
Answer: _______________________________________________
73. Which of the following is a database procedure?
A. A named set of SQL statements that can be executed as a single unit
B. A named set of SQL statements that returns a value
C. A data rule that is used to ensure the accuracy and consistency of data
D. None of the above
Answer: _______________________________________________
74. Which of the following is a database function?
A. A named set of SQL statements that can be executed as a single unit
B. A named set of SQL statements that returns a value
C. A data rule that is used to ensure the accuracy and consistency of data
D. None of the above
Answer: _______________________________________________
75. Which of the following is a database trigger?
A. A named set of SQL statements that can be executed as a single unit
B. A named set of SQL statements that returns a value
C. A data rule that is used to ensure the accuracy and consistency of data
D. A named set of SQL statements that is executed automatically when a
certain event occurs
Answer: _______________________________________________
76. Which of the following is a JDBC connection pool?
A. A set of database connections that are managed by a pool manager
B. A JDBC driver that provides a more efficient way to manage database
connections
C. A database schema that is optimized for performance
D. None of the above
Answer: _______________________________________________
77. Which of the following is a benefit of using a JDBC connection
pool?
A. Improved performance B. Reduced memory usage
C. Improved scalability D. All of the above
Answer: _______________________________________________
78. Which of the following is a good practice to follow when
handling database exceptions?
A. Log the exception.
B. Roll back the transaction, if one is in progress.
C. Close the database connection, if it is open. D. All of the above
Answer: _______________________________________________
79. Which of the following is a type of object-relational mapping
(ORM) framework?
A. Hibernate B. JPA
C. Spring Data JPA D. All of the above
Answer: _______________________________________________
80. Which of the following is a benefit of using an ORM framework?
A. Increased productivity B. Improved code quality
C. Reduced risk of errors D. All of the above
Answer: _______________________________________________
81. Which of the following is a good practice to follow when using
an ORM framework?
A. Use the ORM framework to manage all of your database
interactions.
B. Use the ORM framework to generate your database schema.
C. Use the ORM framework to cache database objects.
D. All of the above
Answer: _______________________________________________
82. Which of the following is a database performance optimization
technique?
A. Normalizing the database schema
B. Creating indexes on frequently accessed columns
C. Using appropriate data types for each column D. All of the above
Answer: _______________________________________________
83. Which API is commonly used for interacting with relational
databases in Java?
A. JDBC B. JPA
C. Hibernate D. JDBA
Answer: _______________________________________________
84. What does JDBC stand for in the context of database interaction
in Java?
A. Java Database Connector B. Java Data Binding Connector
C. Java Database Connectivity D. Java Data Bridge Connector
Answer: _______________________________________________
85. In JDBC, what is the purpose of a Connection object?
A. To execute SQL queries
B. To establish a connection to the database
C. To map Java objects to database records
D. To retrieve the query results
Answer: _______________________________________________
86. Which of the following is an example of a checked exception in
JDBC?
A. SQLException B. NullPointerException
C. ArrayIndexOutOfBoundsException D. FileNotFoundException
Answer: _______________________________________________
87. What is the role of a PreparedStatement in JDBC?
A. It represents a pre-compiled SQL statement.
B. It stores the result set of a query.
C. It is used for batch processing.
D. It provides metadata about the database.
Answer: _______________________________________________
88. Which interface in Java is used to execute SQL queries and
retrieve their results in JDBC?
A. ResultSet B. ResultSetMetaData
C. Statement D. DriverManager
Answer: _______________________________________________
89. In JDBC, which method is used to establish a connection to the
database?
A. connect() B. open()
C. getConnection() D. createConnection()
Answer: _______________________________________________
90. What is the purpose of the ConnectionPool in database
interaction?
A. To manage JDBC drivers B. To store query results
C. To maintain a pool of database connections
D. To optimize SQL queries
Answer: _______________________________________________
91. Which type of JDBC driver provides the highest level of
portability but may be slower?
A. Type-1 B. Type-2
C. Type-3 D. Type-4
Answer: _______________________________________________
92. What is the primary advantage of using Object-Relational
Mapping (ORM) frameworks like Hibernate in Java?
A. Automatic database schema generation
B. Improved SQL query performance
C. Direct control over JDBC connections
D. Compatibility with NoSQL databases
Answer: _______________________________________________
93. In the context of database transactions, what does ACID stand
for?
A. Atomicity, Consistency, Isolation, Durability
B. Aggregation, Concurrency, Integrity, Data
C. Association, Consistency, Integration, Dependency
D. Authenticity, Complexity, Isolation, Dependency
Answer: _______________________________________________
94. What is the purpose of the Java Persistence API (JPA) in Java
database interaction?
A. To manage database connections
B. To provide a higher-level abstraction for working with databases
C. To optimize SQL queries
D. To create stored procedures
Answer: _______________________________________________
95. Which annotation is used to mark a Java class as an entity in
JPA?
A. @Entity B. @Table
C. @Persistent D. @Data
Answer: _______________________________________________
96. What is the role of the EntityManager in JPA?
A. To establish a database connection
B. To manage database transactions
C. To load and persist entities D. To define database tables
Answer: _______________________________________________
97. In JPA, what is the purpose of the @JoinColumn annotation?
A. It specifies the name of the database table.
B. It defines a foreign key relationship between entities.
C. It sets the isolation level for transactions.
D. It controls the transaction boundary.
Answer: _______________________________________________
98. Which query language is used in JPA for defining database
queries?
A. SQL B. HQL (Hibernate Query Language)
C. JQL D. JPQL (Java Persistence Query Language)
Answer: _______________________________________________
99. What is the role of a named query in JPA?
A. To define a unique identifier for an entity
B. To create a temporary query that is not saved in the database
C. To pre-compile and store a query for later use
D. To define the primary key of an entity
Answer: _______________________________________________
100. Which JPA feature allows for automatic generation of primary
key values for entities?
A. Identity Columns B. Auto-Incrementing Fields
C. Sequence Generators D. GenerationType.IDENTITY
Answer: _______________________________________________