Java SE 17 Developer

Question bank

Oracle logo

Java SE 17 Developer

1Z0-829

45 Java SE 17 Developer questions with the correct answer and a written explanation, organised across 12 exam domains.

45 questions
12 domains
Foundation level

Question index

Jump straight to any question. Answers and explanations are inline.

Arrays and Collections

4 questions in this domain

  1. Question 1Single Choice

    Why is it critical to close JDBC resources such as Connection, Statement, and ResultSet in a finally block or with try-with-resources?

    • ATo release database resources and prevent leaksCorrect answer
    • BTo make the SQL statement execute faster
    • CTo automatically commit the transaction
    • DTo increase the number of returned rows

    Why this is the answer

    Unclosed JDBC resources hold database connections and network resources. Closing them in a finally block or using try-with-resources prevents exhausting the connection pool.

  2. Question 2Multiple Select

    Which of the following situations are described in the JDBC playbook as common traps? (Choose all that apply.)

    • AAssuming JDBC URLs follow normal URI syntaxCorrect answer
    • BForgetting to register OUT parameters in a CallableStatementCorrect answer
    • CReading a ResultSet after re-executing the StatementCorrect answer
    • DClosing JDBC resources with try-with-resources

    Why this is the answer

    The URL syntax trap, unregistered OUT parameters, and ResultSet scope are listed as traps. Closing resources properly is a recommended practice, not a mistake.

  3. Question 3Interactive

    In the code shown, a boolean value is assigned after an SQL query is executed. What does that boolean represent?

    • AIt indicates a ResultSet was producedCorrect answer
    • BIt indicates the affected row count
    • CIt indicates the connection is open
    • DIt indicates the SQL was formatted correctly

    Why this is the answer

    In JDBC, execute() returns a boolean. A true value means the first result is a ResultSet, while false means there was no result set or it was an update count.

  4. Question 4Single Choice

    Why can a JDBC URL be misunderstood when it is compared with a standard URI pattern?

    • AIt uses a driver-specific subprotocolCorrect answer
    • BIt begins with http://
    • CIt only supports non-relational databases
    • DIt cannot include connection parameters

    Why this is the answer

    A JDBC URL uses the driver-specific format jdbc:subprotocol:subname. It is not necessarily a standard URI, so parsing it with general URI rules can cause failures.

Concurrency

6 questions in this domain

  1. Question 5Single Choice

    Which group of JDBC objects must be explicitly closed after use to prevent a database resource leak?

    • AConnection, Statement, ResultSetCorrect answer
    • BConnection, DriverManager, DatabaseMetaData
    • CStatement, ResultSet, Driver
    • DConnection, PrintWriter, Statement

    Why this is the answer

    Closing Connection, Statement, and ResultSet releases database resources; DriverManager, Driver, and PrintWriter do not represent JDBC resources to close.

  2. Question 6Multiple Select

    Which statements about JDBC URLs are correct with respect to the connection string syntax supported by database drivers?

    • AEvery JDBC URL begins with the prefix `jdbc:` followed by a driver-specific subprotocol.Correct answer
    • BAll JDBC drivers require the exact same subname format after the subprotocol.
    • CJDBC URL syntax is defined by the driver vendor and is not required to follow standard URI rules.Correct answer
    • D`jdbc:mysql://localhost:3306/books` is an accepted form of JDBC URL for MySQL.Correct answer

    Why this is the answer

    JDBC URLs begin with jdbc: and a driver-specific subprotocol; the remainder is driver-defined and may not comply with standard URI syntax.

  3. Question 7Interactive

    Given the driver-loading code, which statement best describes the use of Class.forName when the driver on the classpath is JDBC 4.0+ compliant?

    • AIt is optional because DriverManager can discover JDBC 4.0+ drivers automatically from the classpath.Correct answer
    • BIt is mandatory even for JDBC 4.0+ drivers.
    • CIt must be executed after a connection is opened.
    • DIt is required to release the driver at the end of the program.

    Why this is the answer

    JDBC 4.0+ drivers on the classpath are registered automatically, so a manual Class.forName call is not required.

  4. Question 8Single Choice

    When Statement.executeUpdate() is called for an UPDATE, DELETE, or INSERT statement, what type of value is returned to the caller?

    • Aboolean
    • Bint representing the affected row countCorrect answer
    • CResultSet with generated keys
    • Dvoid

    Why this is the answer

    executeUpdate() returns an int. For UPDATE, DELETE, and INSERT statements, the int is the number of affected rows.

  5. Question 9Multiple Select

    Which statements correctly distinguish Statement.execute() from Statement.executeUpdate() in terms of return values and usage?

    • A`execute()` returns a boolean, whereas `executeUpdate()` returns an int.Correct answer
    • BWhen `execute()` returns false, the first result is an update count rather than a `ResultSet`.Correct answer
    • C`executeUpdate()` returns a `ResultSet` when it runs a SELECT statement.
    • D`execute()` is useful when the application is not sure whether SQL produces a `ResultSet`.Correct answer

    Why this is the answer

    execute() returns boolean; true means a ResultSet, false means update count. executeUpdate() returns an int of affected rows.

  6. Question 10Interactive

    In the stored procedure code shown, why must registerOutParameter be called before the statement is executed by the CallableStatement?

    • ATo register the parameter with its JDBC type so getInt can retrieve the output value after execution.Correct answer
    • BTo identify the OUT parameter name inside the stored procedure.
    • CTo make the OUT parameter an input argument for the prepared statement.
    • DTo enable the connection to be closed automatically.

    Why this is the answer

    Before executing a CallableStatement, OUT parameters must be registered with their JDBC type so values can be retrieved by getXxx().

Controlling Program Flow

2 questions in this domain

  1. Question 11Single Choice

    In JDBC, what is the accurate difference between the return type of execute() and the return type of executeUpdate()?

    • Aexecute() returns boolean; executeUpdate() returns int.Correct answer
    • Bexecute() returns int; executeUpdate() returns boolean.
    • Cexecute() returns ResultSet; executeUpdate() returns boolean.
    • Dexecute() returns long; executeUpdate() returns boolean.

    Why this is the answer

    execute() returns a boolean that indicates whether the first result is a ResultSet. executeUpdate() returns an int indicating the number of affected rows. Mixing up these return types is a common JDBC trap.

  2. Question 12Multiple Select

    According to the JDBC resource-leak trap, which two practices help ensure that Connection, Statement, and ResultSet objects are properly released?

    • AClose each resource in a finally block or use try-with-resources.Correct answer
    • BUse try-with-resources to close JDBC objects in the correct order automatically.Correct answer
    • CWait for the garbage collector to close the JDBC resources after the objects go out of scope.
    • DClose result sets and statements, but ignore the connection because it is managed by the driver.

    Why this is the answer

    JDBC resources should be released deterministically. Try-with-resources automatically closes them, and manual management should close ResultSet, Statement, then Connection, usually in a finally block. Relying on garbage collection or ignoring the connection can lead to resource leaks.

Handling Date, Time, Text, Numeric and Boolean Values

4 questions in this domain

  1. Question 13Single Choice

    Which JDBC Statement method returns a boolean value to show whether the SQL produced a ResultSet?

    • AStatement.execute()Correct answer
    • BStatement.executeQuery()
    • CStatement.executeUpdate()
    • DConnection.prepareStatement()

    Why this is the answer

    Statement.execute() returns true when SQL produces a ResultSet and false otherwise. executeQuery() returns ResultSet; executeUpdate() returns int.

  2. Question 14Multiple Select

    Which JDBC objects should be closed after your database work is complete to prevent resource leaks? Select all that apply.

    • AConnectionCorrect answer
    • BStatementCorrect answer
    • CResultSetCorrect answer
    • DDriverManager

    Why this is the answer

    Connection, Statement, and ResultSet all hold database resources and should be closed, ideally in a try-with-resources block. DriverManager is a manager class and should not be closed.

  3. Question 15Interactive

    Review the JDBC code. What is the main resource-management problem shown in the snippet?

    • AIt does not close any acquired resourcesCorrect answer
    • BIt uses executeQuery for a SELECT query
    • CIt fails to call Class.forName before connecting
    • DIt does not register the driver with a DataSource

    Why this is the answer

    The code acquires Connection, Statement, and ResultSet but never explicitly closes them; a try-with-resources block or finally block is needed to avoid resource leaks.

  4. Question 16Single Choice

    Which action is sufficient to load a JDBC driver automatically in a Java 17 application?

    • AThe driver JAR is on the classpathCorrect answer
    • BThe application calls Class.forName once
    • CThe MySQL server is available locally
    • DThe driver class is imported in every class

    Why this is the answer

    JDBC 4.0+ automatically discovers drivers from the classpath using ServiceLoader, so Class.forName is no longer necessary when the driver JAR is present.

Handling Exceptions

3 questions in this domain

  1. Question 17Single Choice

    Which practice prevents resource leaks when a JDBC `Connection`, `Statement`, or `ResultSet` is used and an exception occurs during processing?

    • AUse `try-with-resources` to close all JDBC resources.Correct answer
    • BClose only the `ResultSet` after executing the query.
    • CSet each JDBC resource to `null` after use.
    • DRely on the garbage collector to free JDBC resources.

    Why this is the answer

    `try-with-resources` closes all declared JDBC resources when the `try` block exits normally or by exception. Manually closing only the ResultSet or relying on garbage collection can cause resource leaks.

  2. Question 18Multiple Select

    Which statements correctly describe the JDBC driver-loading trap and the exception that can occur when a driver class is not found?

    • A`Class.forName` was required in older JDBC.Correct answer
    • B`Class.forName` throws `ClassNotFoundException` if the class is absent.Correct answer
    • CModern JDBC auto-registers drivers from the classpath.Correct answer
    • D`Class.forName` is mandatory after JDBC 4.0.

    Why this is the answer

    Older JDBC required `Class.forName` for driver loading. Modern JDBC auto-registers drivers from the classpath. A missing driver class makes `Class.forName` throw `ClassNotFoundException`; manual loading is unnecessary after JDBC 4.0.

  3. Question 19Interactive

    What guarantees that the JDBC resources created in the code block are closed when an exception occurs during query execution?

    • AThe try-with-resources construct closes all declared resources automatically.Correct answer
    • BThe catch block explicitly calls close() on each resource.
    • CThe finally block closes the Connection.
    • DThe garbage collector closes them before the method returns.

    Why this is the answer

    The code uses try-with-resources, so each initialized resource is automatically closed before exception handling continues in the catch block.

I/O and NIO.2

3 questions in this domain

  1. Question 20Single Choice

    Which statement accurately describes how JDBC drivers are loaded in JDBC 4.0 and later versions?

    • AThe driver is automatically discovered and loaded using the service provider mechanism.Correct answer
    • BThe driver must always be loaded with Class.forName before it can be used.
    • CThe driver must be manually instantiated and passed to the DriverManager.
    • DThe driver is loaded automatically only when the URL begins with http.

    Why this is the answer

    In JDBC 4.0, drivers are loaded from the classpath by the service provider mechanism, making explicit driver loading optional.

  2. Question 21Multiple Select

    Which three JDBC objects must be closed after use to avoid database resource leaks? Select all that apply.

    • AConnectionCorrect answer
    • BStatementCorrect answer
    • CResultSetCorrect answer
    • DDriverManager

    Why this is the answer

    Connection, Statement, and ResultSet must be closed to free database resources. DriverManager does not implement AutoCloseable and is not closed directly.

  3. Question 22Interactive

    In the provided code block, what is the primary reason that the database connection attempt will fail?

    • AThe URL is missing the required jdbc: prefix.Correct answer
    • BThe database name must be omitted from the connection URL.
    • CThe password must be included in the URL query string.
    • DThe username must contain the host and port.

    Why this is the answer

    JDBC connection URLs always start with jdbc:, followed by a subprotocol such as mysql. Without the jdbc: prefix, DriverManager cannot identify a suitable driver.

JDBC

3 questions in this domain

  1. Question 23Single Choice

    Which return type is correct for the execute() method of a Statement?

    • AbooleanCorrect answer
    • Bint
    • CResultSet
    • Dlong

    Why this is the answer

    The execute() method returns a boolean, indicating whether the SQL produced a ResultSet. In contrast, executeUpdate() returns an int affected row count.

  2. Question 24Multiple Select

    Which two steps are required to retrieve an OUT parameter from a stored procedure with CallableStatement?

    • ACall registerOutParameter() before executionCorrect answer
    • BRetrieve value with the appropriate getter after executionCorrect answer
    • CCall registerOutParameter() after execution
    • DUse ResultSet.next() to retrieve the value

    Why this is the answer

    OUT parameters must be registered with registerOutParameter() before the procedure is executed. After execution, the value is retrieved using an appropriate getter method.

  3. Question 25Interactive

    The code block closes the Connection before reading the ResultSet. What happens when the code is run?

    • AThe ResultSet has already been closed, causing SQLException.Correct answer
    • BThe ResultSet returns false from next() because it is empty.
    • CThe Statement is automatically closed and must be recreated.
    • DThe database driver is not loaded because Class.forName() is missing.

    Why this is the answer

    Closing a Connection closes its Statement and ResultSet objects. The code tries to iterate a ResultSet after that, so SQLException is thrown. Resource scope must contain processing.

Localization

2 questions in this domain

  1. Question 26Single Choice

    In JDBC, what does the executeUpdate() method return when it successfully performs an INSERT, UPDATE, or DELETE statement?

    • AA boolean true or false
    • BA ResultSet object
    • CAn int containing the row countCorrect answer
    • DA Connection object

    Why this is the answer

    executeUpdate() returns an int indicating the number of rows affected. execute() returns a boolean, while executeQuery() returns a ResultSet.

  2. Question 27Multiple Select

    According to JDBC best practices, which two resource-management approaches help prevent the common database resource leak trap?

    • AClose Connection, Statement, and ResultSet objects after use.Correct answer
    • BUse try-with-resources to automatically close JDBC resources.Correct answer
    • CCall Statement.execute() instead of executeUpdate().
    • DRely on the garbage collector to close JDBC resources automatically.

    Why this is the answer

    Closing Connection, Statement, and ResultSet objects or using try-with-resources prevents resource leaks. Garbage collection and execute() choices do not address proper closure.

Modules and Deployment

4 questions in this domain

  1. Question 28Single Choice

    Which practice is most likely to cause a JDBC resource leak according to the documented common traps?

    • ALeaving JDBC resources unclosedCorrect answer
    • BClosing resources in a finally block
    • CUsing try-with-resources
    • DRegistering output parameters before calls

    Why this is the answer

    A resource leak occurs when JDBC objects such as Connection or Statement are not closed. Developers often focus on SQL logic and overlook these resources.

  2. Question 29Multiple Select

    Based on the common JDBC traps described in the source, which two of the following actions are recognized as pitfalls?

    • AUsing a ResultSet outside its valid scopeCorrect answer
    • BClosing resources with try-with-resources
    • CAssuming JDBC URLs follow standard URI syntax onlyCorrect answer
    • DRegistering OUT parameters before calling the procedure

    Why this is the answer

    The source identifies the ResultSet scope and JDBC URL syntax as common traps. Registering OUT parameters and using try-with-resources are proper, recommended practices.

  3. Question 30Interactive

    Review the code block. What type of value is returned by the first JDBC method call shown?

    • AA boolean result valueCorrect answer
    • BAn integer count of affected rows
    • CA set of database rows
    • DA configured database connection

    Why this is the answer

    The first JDBC call is assigned to a boolean variable because execute() returns a boolean. In contrast, executeUpdate() returns an int row count.

  4. Question 31Single Choice

    Older JDBC versions often required a specific setup step before a database connection could be created; what was that step?

    • AExplicitly loading the database driver classCorrect answer
    • BClosing ResultSet objects before executing queries
    • CRegistering output parameters in the connection URL
    • DCalling a single method for all SQL statements

    Why this is the answer

    Older JDBC versions commonly required explicit driver loading through Class.forName(). Modern drivers can often be loaded automatically, but legacy code needed this step.

Object-Oriented Concepts

8 questions in this domain

  1. Question 32Single Choice

    Why must JDBC objects such as Connection, Statement, and ResultSet be closed after use in a database application?

    • ATo prevent database resource leaksCorrect answer
    • BTo make SQL compile faster
    • CTo ensure the driver is loaded
    • DTo validate the JDBC URL

    Why this is the answer

    These objects hold underlying database resources; failure to close them can exhaust database connections and degrade application performance.

  2. Question 33Multiple Select

    Resource management is important in JDBC programs. Which two statements correctly describe JDBC resource management?

    • Atry-with-resources automatically closes declared JDBC resources.Correct answer
    • BResource leaks can consume available database connections.Correct answer
    • CJDBC resources should never be closed manually.
    • DClosing a single Statement also closes the Connection automatically.

    Why this is the answer

    JDBC resources should be explicitly closed, ideally with try-with-resources, because each open resource consumes a limited database connection.

  3. Question 34Interactive

    Look at the connection string in the code block. Which segment is the JDBC subprotocol?

    • AmysqlCorrect answer
    • Bjdbc
    • Clocalhost:3306/school
    • Dschool

    Why this is the answer

    In a JDBC URL of the form jdbc:subprotocol:subname, the subprotocol appears immediately after the jdbc: prefix.

  4. Question 35Single Choice

    In modern JDBC drivers, how is the appropriate driver normally discovered when a database connection is requested?

    • ADetected automatically through ServiceLoaderCorrect answer
    • BIt must be loaded using an explicit driver class
    • CThe developer manually creates the driver instance
    • DIt is registered by executing a special command

    Why this is the answer

    JDBC 4+ uses ServiceLoader to find driver implementations on the classpath automatically, so Class.forName is not required in most cases.

  5. Question 36Multiple Select

    In JDBC, which two statements correctly describe the return types of execute and executeUpdate when used to run SQL?

    • Aexecute() returns a boolean value.Correct answer
    • BexecuteUpdate() returns an int row count.Correct answer
    • Cexecute() returns the number of affected rows.
    • DexecuteUpdate() returns a ResultSet.

    Why this is the answer

    execute indicates whether the first result is a ResultSet, while executeUpdate returns an int for insert, update, delete, or DDL.

  6. Question 37Interactive

    Consider the code block. What does the boolean value from the first execution imply?

    • AThe first SQL result is a ResultSet.Correct answer
    • BThe first SQL was a DELETE that affected rows.
    • CThe database connection is invalid.
    • DThe driver cannot handle the SQL type.

    Why this is the answer

    execute returns true only when the first result is a ResultSet; false means an update count or no result.

  7. Question 38Single Choice

    Before executing a stored procedure with output parameters through a CallableStatement, what step must be completed?

    • ARegister each OUT parameterCorrect answer
    • BNo special action is needed
    • CPlace all output values in a properties file
    • DClose the CallableStatement before execution

    Why this is the answer

    OUT parameters must be registered with registerOutParameter before the call; otherwise the output values cannot be retrieved correctly.

  8. Question 39Multiple Select

    Which two statements are true about the scope of a ResultSet created by a Statement in JDBC?

    • AClosing the Statement makes the ResultSet unsafe.Correct answer
    • BRe-executing the Statement can invalidate the ResultSet.Correct answer
    • CRe-executing the Statement has no effect on the ResultSet.
    • DThe ResultSet remains valid after the Connection is closed.

    Why this is the answer

    The ResultSet belongs to its Statement, so closing or re-executing that statement can close the ResultSet.

Streams and Lambda Expressions

5 questions in this domain

  1. Question 40Single Choice

    Which Java construct automatically closes JDBC resources such as Connection, Statement, and ResultSet when the code block finishes?

    • AUse try-with-resources and declare the resources in its parentheses.Correct answer
    • BCreate each resource inside a private constructor and await finalization.
    • CUse a finally block without calling close in it.
    • DRely on the ResultSet to close the Connection automatically.

    Why this is the answer

    try-with-resources closes each resource automatically when the try block exits, preventing the resource leak that happens when close calls are forgotten.

  2. Question 41Multiple Select

    When you are building a database connection string in JDBC, which two statements correctly describe the parts that make up the URL?

    • AA JDBC URL starts with the prefix `jdbc:`.Correct answer
    • BAfter `jdbc:` come a subprotocol and a subname.Correct answer
    • CThe subprotocol always matches the driver vendor's website.
    • DJDBC URLs must start with `https://` to be accepted.

    Why this is the answer

    A JDBC URL has the form `jdbc:<subprotocol>:<subname>`. The subprotocol identifies the driver mechanism, and the subname carries database-specific information; `https://` is not a JDBC connection form.

  3. Question 42Interactive

    In the provided code, what is true about the line that loads the driver class for this JDBC 4.0-compliant driver?

    • AIt is still mandatory for every JDBC driver in Java 17.
    • BIt is optional because DriverManager can discover JDBC 4.0 drivers from the classpath.Correct answer
    • CIt allows the program to connect without producing a Connection object.
    • DIt removes the need to provide host information in the JDBC URL.

    Why this is the answer

    Because the driver jar is on the classpath and implements JDBC 4.0, DriverManager loads it automatically through the service-provider mechanism; manual class loading is optional.

  4. Question 43Single Choice

    Which JDBC method should be used to obtain the number of rows affected by an UPDATE statement?

    • A`executeUpdate()` returns an int with the number of affected rows.Correct answer
    • B`execute()` returns an int with the number of affected rows.
    • C`executeQuery()` returns an int with the number of affected rows.
    • D`registerOutParameter()` returns an int with the number of affected rows.

    Why this is the answer

    executeUpdate() returns the row count for INSERT, UPDATE, DELETE, and DDL statements. execute() returns a boolean, executeQuery() returns a ResultSet, and registerOutParameter() is used with CallableStatement.

  5. Question 44Multiple Select

    Which two steps are required to obtain the value of an OUT parameter from a JDBC CallableStatement?

    • ARegister the OUT parameter with `registerOutParameter()` before executing the procedure.Correct answer
    • BCall `execute()` or `executeUpdate()` after registering the parameter.Correct answer
    • CRead the OUT parameter with an input setter such as `setString()`.
    • DClose the `CallableStatement` before retrieving the OUT parameter.

    Why this is the answer

    A CallableStatement OUT parameter must be registered before execution. After the procedure runs, getters such as getString() read the result. Setters are only for IN parameters.

Supplementary Topics

1 questions in this domain

  1. Question 45Single Choice

    According to common JDBC traps, which method of a Statement returns a boolean value?

    • Aexecute()Correct answer
    • BexecuteUpdate()
    • CexecuteQuery()
    • DexecuteBatch()

    Why this is the answer

    In JDBC, execute() returns a boolean indicating whether the first result is a ResultSet. executeUpdate() returns an int, and executeQuery() returns a ResultSet.

Frequently asked questions

Everything about the Java SE 17 Developer question bank and how to use it.