Premium

Oracle Advacned Java Advanced Certification Questions and Answers (Dumps and Practice Questions)



Question : You have been given below code,

Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * FROM table"));
int columnCount = resultSet.getMetaData().getColumnCount();

Select the correct statement, which applies?
A. Table header can be accessed using 0th Index.
B. Table header can be accessed using 1st Index
C. MetaData object cannot return number of columns in query.
D. A and C
E. B and C

 : You have been given below code,
1. Table header can be accessed using 0th Index.

2. Table header can be accessed using 1st Index

3. Access Mostly Uused Products by 50000+ Subscribers

4. A and C

5. B and C


Correct Answer : Get Lastest Questions and Answer :
Explanation: java.sql.ResultSetMetaData

An object that can be used to get information about the types and properties of the columns in a ResultSet object. The following code fragment creates the ResultSet object rs,
creates the ResultSetMetaData object rsmd, and uses rsmd to find out how many columns rs has and whether the first column in rs can be used in a WHERE clause.

ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2");
ResultSetMetaData rsmd = rs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
boolean b = rsmd.isSearchable(1);





Question : You have been given below code, once you execute it what will be the expected result?

package com.hadoopexam;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

class Welcome {
public static void main(String[] args) {
Connection connection=null;
try (Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * FROM User")) {
System.out.println(resultSet.getInt("user_id") + "\t"
+ resultSet.getString("UserName") + "\t"
+ resultSet.getString("lastName") + "\t"
+ resultSet.getString("emailId") + "\t"
+ resultSet.getString("Cell"));
} catch (SQLException sqle) {
System.out.println("SQLException");
}
}
}

 : You have been given below code, once you execute it what will be the expected result?
1. It will give compile time error

2. It will give runtime error

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will compile and run and print nothing.


Correct Answer : Get Lastest Questions and Answer :
Explanation: This code will throw run time error. Because if you want to use ResultSet, you should use next() method on it. while (resultSet.next()) should be used.




Question : Select the correct statement with regards to JDBC Statement interface

 : Select the correct statement with regards to JDBC Statement interface
1. The Statement interface and its derived interfaces implement the AutoCloseable interface, hence Statement objects can be used with the try with- resources
statement.

2. You can use PreparedStatement is used to execute stored procedures

3. Access Mostly Uused Products by 50000+ Subscribers

4. A and C

5. B and C


Correct Answer : Get Lastest Questions and Answer :
Explanation: java.sql.Statement

The object used for executing a static SQL statement and returning the results it produces.
By default, only one ResultSet object per Statement object can be open at the same time. Therefore, if the reading of one ResultSet object is interleaved with the reading of another,
each must have been generated by different Statement objects. All execution methods in the Statement interface implicitly close a current ResultSet object of the statement if an open
one exists.
java.sql.PreparedStatement

An object that represents a precompiled SQL statement.
A SQL statement is precompiled and stored in a PreparedStatement object. This object can then be used to efficiently execute this statement multiple times.
Note: The setter methods (setShort, setString, and so on) for setting IN parameter values must specify types that are compatible with the defined SQL type of the input parameter. For
instance, if the IN parameter has SQL type INTEGER, then the method setInt should be used.
If arbitrary parameter type conversions are required, the method setObject should be used with a target SQL type.
In the following example of setting a parameter, con represents an active connection:
PreparedStatement pstmt = con.prepareStatement("UPDATE EMPLOYEES
SET SALARY = ? WHERE ID = ?");
pstmt.setBigDecimal(1, 153833.00)
pstmt.setInt(2, 110592)

java.sql.CallableStatement

The interface used to execute SQL stored procedures. The JDBC API provides a stored procedure SQL escape syntax that allows stored procedures to be called in a standard way for all
RDBMSs. This escape syntax has one form that includes a result parameter and one that does not. If used, the result parameter must be registered as an OUT parameter. The other
parameters can be used for input, output or both. Parameters are referred to sequentially, by number, with the first parameter being 1.
{?= call [(,, ...)]}
{call [(,, ...)]}



Related Questions


Question : You have been given below code, what is the expected behavior?

package com.hadoopexam;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class Welcome {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = null;
try (BufferedReader _bufferedReader = new BufferedReader(new FileReader("resources\\Message.txt"))) { // line n1
_bufferedReader.lines().forEach(eachChar -> System.out.println(eachChar));
bufferedReader = _bufferedReader;// line n2
}
bufferedReader.ready(); // line n3;
}
}
 : You have been given below code, what is the expected behavior?
1. A compilation error occurs at line n3.

2. A compilation error occurs at line n1.

3. Access Mostly Uused Products by 50000+ Subscribers

4. The code prints the content of the resources\\Message.txt file and throws an exception at line n3.



Question : You have been given below code, what is the behavior expected?

package com.hadoopexam;

public class Welcome {
private String startCourse(String bname) {
return "Watch " + bname;
}
}

class Child extends Welcome {
public String startCourse(String url) {
return "Complete " + url;
}
}

class Util {
public static void main(String[] args) {
Welcome p1 = new Welcome();
p1.startCourse("Hadoop Training"); //n1
Welcome child = new Child();
child.startCourse("http://hadoopexam.com/java"); //n2
}
}
 : You have been given below code, what is the behavior expected?
1. Watch Hadoop Training
Complete http://hadoopexam.com/java

2. Watch Hadoop Training
Watch http://hadoopexam.com/java

3. Access Mostly Uused Products by 50000+ Subscribers

4. The Util.java file fails to compile.



Question : Which of the following code snippet is correct?
 : Which of the following code snippet is correct?
1. class Welcome implements Callable {
public int call() {
System.out.println("In Callable.call()");
return 0;
}
}


2. class Welcome extends Callable {
public Integer call() {
System.out.println("In Callable.call()");
return 0;
}
}


3. Access Mostly Uused Products by 50000+ Subscribers
public Integer call() {
System.out.println("In Callable.call()");
return 0;
}
}


4. A and C



Question :
You have been given following code. What is the expected behavior?

package com.hadoopexam;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.Callable;
import java.util.concurrent.CopyOnWriteArrayList;

class Welcome implements Callable {
public static void main(String[] args) {
ArrayList cowAList = new CopyOnWriteArrayList();
cowAList.addAll(Arrays.asList(1,2,3,4));
System.out.println(cowAList);
}
}
 :
1. It will give compile time error.

2. It will compile and run with output as [1,2,3,4]

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will compile and run but no output.



Question : Which one of the following methods return a Future object?


 : Which one of the following methods return a Future object?
1. The overloaded run() methods declared in the Thread class.

2. The run() method declared in the Runnable interface

3. Access Mostly Uused Products by 50000+ Subscribers

4. The call() method declared in the Callable interface



Question : Which of the following is not a correct option, with regard to JDBC?
 : Which of the following is not a correct option, with regard to JDBC?
1. It is the responsibility of Driver Manager to manage the list of available Data Sources.

2. It is the responsibility of Driver Manager to use appropriate driver to communicate with DBMS.

3. Access Mostly Uused Products by 50000+ Subscribers

4. A and C

5. B and C