Premium

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



Question : You have been given below code, what would be printed?

package com.hadoopexam;

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

public final class Welcome {
public static void main(String[] args) throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");
String query = "SELECT userId FROM Subscriber";
try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery(query);
stmt.executeQuery("SELECT userId FROM Course");
while (rs.next()) {
// process the results
System.out.println("User ID: " + rs.getInt("userId"));
}
} catch (Exception e) {
System.out.println("Error");
}
}
}
 : You have been given below code, what would be printed?
1. The program prints subscriber IDs.

2. The program prints course IDs.

3. Access Mostly Uused Products by 50000+ Subscribers

4. compilation fails.


Correct Answer : Get Lastest Questions and Answer :
Explanation: reusing a ResultSet is ok as well as long as you're properly closing it after you're done with it. You can reuse a single ResultSet
and Statement as long as the operations are done in serial, not parallel. ie instantiate run query 1 with your Statement, get back value xyz from the ResultSet;
close the statement, instantiate & run query 2 with your Statement using value xyz.

A ResultSet object is automatically closed when the Statement object that generated it is closed, re-executed, or used to retrieve the next result
from a sequence of multiple results.





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

package com.hadoopexam;

import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import java.util.function.UnaryOperator;

public final class Welcome {
public static void main(String[] args) throws SQLException {
List codes = Arrays.asList(1, 2);
UnaryOperator unaryOperator = s -> s + 1;
codes.replaceAll(unaryOperator);
codes.forEach(value -> System.out.print(value));
}
}
 : You have been given below code, what is the expected behavior?
1. It will print 23

2. It will print 12

3. Access Mostly Uused Products by 50000+ Subscribers

4. A compilation error occurs.

5. A NumberFormatExceptionis thrown at run time.


Correct Answer : Get Lastest Questions and Answer :
Explanation: UnaryOperator is a functional interface and it extends Function interface, and you can use the
apply() method declared in the Function interface; further, it inherits the default functions compose() and
andThen() from the Function interface.





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

package com.hadoopexam;

public class Welcome {
private String courseName;
private String userName;
private static int totalSubscriber;

public Welcome(String courseName, String userName) {
courseName = courseName;
userName = userName;
++totalSubscriber;
}

static {
totalSubscriber = 0;
}

public static int getTotalSubscriber() {
return totalSubscriber;
}
}

public class Peer {
public static void main(String[] args) {
Welcome c1 = new Welcome("Amit", "Kumar");
Welcome c2 = new Welcome("Venkat", "G");
Welcome c3 = new Welcome("Rahul", "Khetan");
Welcome c4 = new Welcome("Vijay", "Chauhan");
c4 = null;
c3 = c2;
System.out.println(Welcome.getTotalSubscriber());
}
}
 : You have been given below code, what is the expected output?
1. 0

2. 2

3. Access Mostly Uused Products by 50000+ Subscribers

4. 4

5. 5


Correct Answer : Get Lastest Questions and Answer :
Explanation: A static variable is associated with its class rather than its object or instance; hence they are known as class variables.
A static variable is initialized only once when execution of the program starts. A static variable shares its state with all instances of the class.
You access a static variable using its class name (instead of an instance)

There are two types of member variables: class variables and instance variables. All variables that require an instance (object) of the class to access
them are known as instance variables. All variables that are shared among all instances and are associated with a class rather than an object are referred to as class variables
(Declared using the static keyword).
. All static members do not require an instance to call/access them. You can directly call/access them using the class name.
. A static member can call/access only a static member of the same class.



Related Questions


Question : You have been given below code. What would be the behavior.

package com.hadoopexam;

import java.util.Arrays;

class Welcome {
public static void main(String[] args) {
"HadoopExam.com".chars().distinct()
.peek(ch -> System.out.printf("%c ", ch)).sorted();
}
}
 : You have been given below code. What would be the behavior.
1. It will print "H a d o p E x m . c"

2. It will print "H a d o o p E x a m . c o m"

3. Code will not compile.

4. Code will not print any output.



Question : You have been given following code, what is the behavior you expect.

package com.hadoopexam;

import java.util.stream.IntStream;

class Welcome {
public static void main(String[] args) {
IntStream.rangeClosed(5, 5).forEach(System.out::println);
}
}

 : You have been given following code, what is the behavior you expect.
1. It will compile and run perfectly and print 5,6

2. It will compile and run perfectly and print 5,5

3. It will compile and run perfectly and print 5

4. It will compile and run perfectly but not print anything

5. It will compile and run perfectly but throw exception at runtime. NoSufficientArgumentsProvided.



Question : You have been given below source code and Message.properties file

package com.hadoopexam;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;


class Welcome {

public static void main(String[] args) throws IOException {
Properties prop = new Properties ();
FileInputStream fis = new FileInputStream("resources//Message.properties");
prop.load(fis);
System.out.println(prop.getProperty("hadoopexam"));
System.out.println(prop.getProperty("training", "Welcome to Training4Exam.com"));
System.out.println(prop.getProperty("quickTechie"));
System.out.println(prop.getProperty("quicktechie"));
}

}

- resources\Message.properties
hadoopexam=Welcome to HadoopExam Learning Resources
quickTechie=Welcome to QuickTechie Professional Network

What is the behavior of the code?
 : You have been given below source code and Message.properties file
1. It will give compile time error.

2. It will give "NullPointerException" when executed.

3. It will run perfectly and print as below.
Welcome to HadoopExam Learning Resources
Welcome to Training4Exam.com
Welcome to QuickTechie Professional Network
null

4. It will run perfectly and print as below.
Welcome to HadoopExam Learning Resources
Welcome to Training4Exam.com
Welcome to QuickTechie Professional Network




Question : Which action can be used to load a database driver by using JDBC.?


 : Which action can be used to load a database driver by using JDBC.?
1. Add the driver class to the META-INF/services folder of the JAR file

2. Include the JDBC driver class in a jdbc.properties file.

3. Use the java.lang.Class.forName method to load the driver class.

4. Use the DriverManager.getDriver method to load the driver class.



Question : You have been given below code, what is the expected behavior assume below path does not exist "/com/HadoopExam.java" ?

package com.hadoopexam;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

class Welcome {

public static void main(String[] args) throws IOException {
Path p1 = Paths.get("/com/HadoopExam.java");
System.out.println(p1.getNameCount() + ":" + p1.getName(1) + ":" + p1.getFileName());
}
}
 : You have been given below code, what is the expected behavior assume below path does not exist
1. It will give compile time error.

2. It will throw "NullPointerException"

3. It will throe "FileNotFoundException"

4. It will print "2:HadoopExam.java:HadoopExam.java"

5. It will print "2:com:HadoopExam.java"



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

package com.hadoopexam;

import java.util.concurrent.atomic.AtomicInteger;

class Welcome implements Runnable {
private static AtomicInteger count = new AtomicInteger(5);

public void run() {
int counterValue = count.incrementAndGet();
System.out.print(counterValue + " ");
}

public static void main(String[] args) {
Thread thread1 = new Thread(new Welcome());
Thread thread2 = new Thread(new Welcome());
Thread thread3 = new Thread(new Welcome());
Thread[] ta = { thread1, thread2, thread3 };
for (int x = 0; x < 3; x++) {
ta[x].start();
}
}
}

 : You have been given below code, what is the expected behavior?
1. It will print 5,5,5

2. It will print 5,6,7 but order can be anything

3. It will print 6,7,8

4. It will print 6,7,8 but its order can be anything

5. It will anything in any order