Author name: admin

Which method is used to rollback a transaction in JDBC?

Java MCQ: Which method is used to rollback a transaction in JDBC? a) undoTransaction() b) rollbackTransaction() c) rollback() d) revert() Answer: c) rollback() Explanation: The rollback() method is used to rollback a transaction in JDBC. When auto-commit mode is disabled, you can use rollback() on the Connection object to undo all changes made in the

Which method is used to rollback a transaction in JDBC? Read More »

Which JDBC method is used to commit a transaction?

Java MCQ: Which JDBC method is used to commit a transaction? a) commitTransaction() b) executeCommit() c) commit() d) finalizeTransaction() Answer: c) commit() Explanation: The commit() method is used to commit a transaction in JDBC. When auto-commit mode is disabled, multiple SQL statements can be grouped into a single transaction. After executing all the statements, calling

Which JDBC method is used to commit a transaction? Read More »

Which interface is used to execute SQL queries in JDBC?

Java MCQ: Which interface is used to execute SQL queries in JDBC? a) Statement b) ResultSet c) Connection d) PreparedStatement Answer: a) Statement Explanation: The Statement interface is used to execute SQL queries in JDBC. It provides methods to execute SQL statements, such as executeQuery() for SELECT statements, executeUpdate() for INSERT, UPDATE, and DELETE statements,

Which interface is used to execute SQL queries in JDBC? Read More »

Which method is used to establish a connection to a database?

Java MCQ: Which method is used to establish a connection to a database? a) DriverManager.connect() b) DriverManager.getConnection() c) Connection.create() d) Database.connect() Answer: b) DriverManager.getConnection() Explanation: The DriverManager.getConnection() method is used to establish a connection to a database in JDBC. This method takes a database URL, a username, and a password as arguments and returns a

Which method is used to establish a connection to a database? Read More »

What does JDBC stand for?

Java MCQ: What does JDBC stand for? a) Java Data Connection b) Java Database Connectivity c) Java DataBase Compiler d) Java Data Component Answer: b) Java Database Connectivity Explanation: JDBC stands for Java Database Connectivity. It is an API in Java that allows developers to connect to and interact with databases from Java applications. JDBC

What does JDBC stand for? Read More »

How does the sendAsync() method in Java 11 HttpClient differ from the send() method?

Java MCQ: How does the sendAsync() method in Java 11 HttpClient differ from the send() method? a) It sends requests over a different protocol b) It sends requests asynchronously, returning a CompletableFuture c) It sends requests faster d) It sends requests in batches Answer: b) It sends requests asynchronously, returning a CompletableFuture Explanation: The sendAsync()

How does the sendAsync() method in Java 11 HttpClient differ from the send() method? Read More »

What is the return type of the send() method in the Java 11 HttpClient class?

Java MCQ: What is the return type of the send() method in the Java 11 HttpClient class? a) HttpResponse b) String c) Future d) void Answer: a) HttpResponse Explanation: The send() method in the Java 11 HttpClient class returns an instance of HttpResponse. This method is used to send an HTTP request synchronously, meaning that

What is the return type of the send() method in the Java 11 HttpClient class? Read More »

Which method is used to create a new instance of HttpClient in Java 11?

Java MCQ: Which method is used to create a new instance of HttpClient in Java 11? a) HttpClient.create() b) HttpClient.newBuilder() c) HttpClient.newHttpClient() d) HttpClient.getInstance() Answer: c) HttpClient.newHttpClient() Explanation: The HttpClient.newHttpClient() method is used to create a new instance of HttpClient in Java 11. This method returns a default HttpClient that can be used to send

Which method is used to create a new instance of HttpClient in Java 11? Read More »

What does the Local-Variable Syntax for Lambda Parameters in Java 11 allow you to do?

Java MCQ: What does the Local-Variable Syntax for Lambda Parameters in Java 11 allow you to do? a) Define local variables in lambda expressions b) Use the var keyword to declare the types of lambda parameters c) Use instance variables inside lambda expressions d) Automatically infer the types of lambda parameters Answer: b) Use the

What does the Local-Variable Syntax for Lambda Parameters in Java 11 allow you to do? Read More »

What does the Optional.orElseThrow() method introduced in Java 10 do?

Java MCQ: What does the Optional.orElseThrow() method introduced in Java 10 do? a) Returns the contained value if present, otherwise throws NoSuchElementException b) Returns the contained value if present, otherwise returns null c) Returns the contained value if present, otherwise returns a default value d) Returns the contained value if present, otherwise throws IllegalStateException Answer:

What does the Optional.orElseThrow() method introduced in Java 10 do? Read More »

How does the Collectors.toUnmodifiableMap() method handle duplicate keys in Java 10?

Java MCQ: How does the Collectors.toUnmodifiableMap() method handle duplicate keys in Java 10? a) It merges the values associated with duplicate keys b) It throws an IllegalStateException c) It ignores duplicate keys d) It keeps only the first occurrence of the key Answer: b) It throws an IllegalStateException Explanation: The Collectors.toUnmodifiableMap() method, introduced in Java

How does the Collectors.toUnmodifiableMap() method handle duplicate keys in Java 10? Read More »

Which Java 10 feature allows you to collect elements into an unmodifiable list using Collectors?

Java MCQ: Which Java 10 feature allows you to collect elements into an unmodifiable list using Collectors? a) Collectors.toUnmodifiableSet() b) Collectors.toUnmodifiableMap() c) Collectors.toUnmodifiableList() d) Collectors.toImmutableList() Answer: c) Collectors.toUnmodifiableList() Explanation: The Collectors.toUnmodifiableList() method, introduced in Java 10, allows you to collect elements into an unmodifiable list. This method is part of the java.util.stream.Collectors class and is

Which Java 10 feature allows you to collect elements into an unmodifiable list using Collectors? Read More »

What is the behavior of the Map.copyOf() method introduced in Java 10 when invoked with a map containing null keys or values?

Java MCQ: What is the behavior of the Map.copyOf() method introduced in Java 10 when invoked with a map containing null keys or values? a) It removes the null keys or values from the map b) It replaces null keys or values with empty strings c) It throws a NullPointerException d) It converts null keys

What is the behavior of the Map.copyOf() method introduced in Java 10 when invoked with a map containing null keys or values? Read More »

How does the Set.copyOf() method introduced in Java 10 behave when given a null argument?

Java MCQ: How does the Set.copyOf() method introduced in Java 10 behave when given a null argument? a) It returns an empty set b) It throws a NullPointerException c) It creates a set with a null element d) It ignores the null argument Answer: b) It throws a NullPointerException Explanation: The Set.copyOf() method, introduced in

How does the Set.copyOf() method introduced in Java 10 behave when given a null argument? Read More »

Scroll to Top