Java Programming
Java OOP, collections, multithreading
270 Questions 10 Topics Take Test
Advertisement
Showing 71–80 of 270 questions
Q.71 Easy Generics
Which keyword is used to declare a generic class in Java?
A
B generic
C template
D type
Correct Answer:  A.
EXPLANATION

<T> is the standard syntax for declaring a generic type parameter in Java classes.

Take Test
Q.72 Easy Generics
What is the primary purpose of Generics in Java?
A To provide type safety and eliminate type casting
B To increase memory allocation
C To reduce code compilation time
D To automatically manage garbage collection
Correct Answer:  A. To provide type safety and eliminate type casting
EXPLANATION

Generics enable type safety at compile time and eliminate the need for explicit type casting, reducing runtime errors.

Take Test
Q.73 Easy JDBC
In a JDBC application, which interface is responsible for executing SQL queries and returning ResultSet objects?
A Statement
B Connection
C Driver
D DataSource
Correct Answer:  A. Statement
EXPLANATION

The Statement interface is used to execute SQL queries. Connection creates the statement, Driver manages connections, and DataSource provides connection pooling, but Statement is the actual executor.

Take Test
Q.74 Easy JDBC
What is the difference between commit() and rollback() in JDBC transactions?
A commit() saves changes, rollback() undoes them
B Both perform the same function
C rollback() is faster than commit()
D commit() is used for SELECT queries, rollback() for UPDATE
Correct Answer:  A. commit() saves changes, rollback() undoes them
EXPLANATION

commit() permanently saves all changes made during the transaction, while rollback() discards all changes and reverts to the previous state.

Take Test
Q.75 Easy JDBC
Which exception is thrown when a JDBC driver is not found in the classpath?
A SQLException
B ClassNotFoundException
C DriverNotFoundException
D JDBCException
Correct Answer:  B. ClassNotFoundException
EXPLANATION

When Class.forName() cannot locate the driver class, it throws ClassNotFoundException, indicating the driver JAR is not in the classpath.

Take Test
Q.76 Easy JDBC
In JDBC, what does the BatchUpdate feature allow developers to do?
A Execute single queries faster
B Execute multiple queries in a single batch for improved performance
C Create backup of database
D Monitor database connections
Correct Answer:  B. Execute multiple queries in a single batch for improved performance
EXPLANATION

addBatch() and executeBatch() methods allow multiple SQL statements to be grouped and executed together, reducing network traffic and improving performance.

Take Test
Q.77 Easy JDBC
Which method of Connection interface is used to start a transaction in JDBC?
A setAutoCommit(false)
B beginTransaction()
C startTransaction()
D createTransaction()
Correct Answer:  A. setAutoCommit(false)
EXPLANATION

setAutoCommit(false) disables auto-commit mode, allowing manual control over transactions through commit() and rollback() methods.

Take Test
Q.78 Easy JDBC
What is the correct sequence to establish a JDBC connection in Java?
A Load Driver → Create Connection → Execute Query → Close Connection
B Create Connection → Load Driver → Execute Query → Close Connection
C Load Driver → Create Statement → Execute Query → Close Connection
D Create Statement → Load Driver → Create Connection → Execute Query
Correct Answer:  A. Load Driver → Create Connection → Execute Query → Close Connection
EXPLANATION

The correct JDBC connection sequence is: Class.forName() → DriverManager.getConnection() → Create Statement → Execute Query → Close resources.

Take Test
Q.79 Easy JDBC
Which interface in JDBC is used to execute parameterized queries and prevent SQL injection attacks?
A Statement
B PreparedStatement
C CallableStatement
D Connection
Correct Answer:  B. PreparedStatement
EXPLANATION

PreparedStatement is used for parameterized queries with placeholders (?), which prevents SQL injection by separating SQL logic from data.

Take Test
Q.80 Easy JDBC
In JDBC, what does the executeQuery() method return?
A int
B boolean
C ResultSet
D void
Correct Answer:  C. ResultSet
EXPLANATION

executeQuery() returns a ResultSet containing the rows fetched from the database for SELECT queries.

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