Home Subjects Java Programming

Java Programming

Java OOP, collections, multithreading

476 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 131–140 of 476
Topics in Java Programming
Q.131 Medium Generics
What is type erasure in Java Generics?
A The process by which generic type information is removed at runtime
B Automatic deletion of generic collections
C Compiler optimization of generic code
D Runtime type checking for generics
Correct Answer:  A. The process by which generic type information is removed at runtime
EXPLANATION

Type erasure is a mechanism where the Java compiler removes all generic type information during compilation, converting generic code to its raw type equivalent.

Take Test
Q.132 Medium JDBC
In JDBC 2024-25, which exception is thrown when attempting to use a closed Connection object?
A SQLException
B SQLClientInfoException
C SQLInvalidAuthorizationSpecException
D SQLNonTransientConnectionException
Correct Answer:  A. SQLException
EXPLANATION

A SQLException (specifically a SQLNonTransientConnectionException as a subclass) is thrown when operations are attempted on a closed Connection. SQLException is the general exception for database access errors.

Take Test
Q.133 Medium JDBC
When using ResultSet in JDBC, which cursor type allows bidirectional movement through rows but does not reflect database changes?
A TYPE_FORWARD_ONLY
B TYPE_SCROLL_INSENSITIVE
C TYPE_SCROLL_SENSITIVE
D TYPE_DYNAMIC
Correct Answer:  B. TYPE_SCROLL_INSENSITIVE
EXPLANATION

TYPE_SCROLL_INSENSITIVE allows movement in both directions (previous, next, absolute) but doesn't reflect changes made to the database after the ResultSet was created. TYPE_SCROLL_SENSITIVE would reflect changes.

Take Test
Q.134 Medium JDBC
A developer needs to execute the same SQL query multiple times with different parameters. Which JDBC feature should be used to optimize performance?
A Statement with loop execution
B PreparedStatement with parameterized queries
C CallableStatement for all queries
D Multiple Connection objects
Correct Answer:  B. PreparedStatement with parameterized queries
EXPLANATION

PreparedStatement pre-compiles the query and allows parameter binding, reducing overhead and improving performance for repeated executions. It also prevents SQL injection.

Take Test
Q.135 Medium JDBC
Which JDBC feature allows monitoring of database metadata like table structure and column information?
A DatabaseMetaData interface
B ResultSetMetaData interface
C ParameterMetaData interface
D StatementMetaData interface
Correct Answer:  A. DatabaseMetaData interface
EXPLANATION

DatabaseMetaData (obtained from Connection.getMetaData()) provides information about the entire database like tables, columns, keys, and supported features.

Take Test
Q.136 Medium JDBC
What is the correct way to handle resource management in JDBC with Java 7+?
A try-catch-finally blocks with explicit close()
B try-with-resources statement (try-with parentheses)
C Using finally blocks only
D Automatic garbage collection handles it
Correct Answer:  B. try-with-resources statement (try-with parentheses)
EXPLANATION

try-with-resources automatically closes AutoCloseable resources (Connection, Statement, ResultSet), preventing connection leaks elegantly.

Take Test
Q.137 Medium JDBC
In JDBC 2024-25, which data type mapping is incorrect for Java to SQL?
A int → INTEGER
B String → VARCHAR
C boolean → BOOLEAN
D byte[] → CHAR
Correct Answer:  D. byte[] → CHAR
EXPLANATION

byte[] should map to BLOB (Binary Large Object), not CHAR. CHAR is for single character types.

Take Test
Q.138 Medium JDBC
Which method in ResultSet is used to check if a column value is NULL?
A isNull()
B wasNull()
C checkNull()
D getNullValue()
Correct Answer:  B. wasNull()
EXPLANATION

wasNull() returns true if the last retrieved value was NULL in the database, checked after calling a getter method like getString() or getInt().

Take Test
Q.139 Medium JDBC
In a multi-threaded JDBC application, what should be the approach for Connection object usage?
A Share single Connection object across all threads
B Each thread should use its own Connection from the pool
C Create new Connection for each database operation
D Use static Connection objects
Correct Answer:  B. Each thread should use its own Connection from the pool
EXPLANATION

Connection objects are not thread-safe. Each thread should obtain its own Connection from a thread-safe connection pool to avoid race conditions.

Take Test
Q.140 Medium JDBC
What does the setMaxRows() method in Statement do?
A Limits the number of rows returned by a query
B Sets the maximum number of connections
C Defines batch size for updates
D Controls transaction timeout
Correct Answer:  A. Limits the number of rows returned by a query
EXPLANATION

setMaxRows() limits the number of rows returned by executeQuery(), useful for memory management when dealing with large result sets.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips