Premium

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



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.


Correct Answer : Get Lastest Questions and Answer :
Explanation: : Driver java.sql.DriverManager.getDriver(String url) throws SQLException

@CallerSensitive
Attempts to locate a driver that understands the given URL. The DriverManager attempts to select an appropriate driver from the set of registered JDBC drivers.
Parameters:
url a database URL of the form jdbc:subprotocol:subname
Returns:
a Driver object representing a driver that can connect to the given URL
Throws:
SQLException - if a database access error occurs





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"


Correct Answer : Get Lastest Questions and Answer :
Explanation: when you use Path class to represent a path. Then it is not required that path exist.

java.nio.file.Paths

This class consists exclusively of static methods that return a Path by converting a path string or URI.
int java.nio.file.Path.getNameCount()

Returns the number of name elements in the path.
Returns:
the number of elements in the path, or 0 if this path only represents a root component

Path java.nio.file.Path.getName(int index)

Returns a name element of this path as a Path object.
The index parameter is the index of the name element to return. The element that is closest to the root in the directory hierarchy has index 0. The element that is farthest from the
root has index count-1.
Parameters:
index the index of the element

Path java.nio.file.Path.getFileName()

Returns the name of the file or directory denoted by this path as a Path object. The file name is the farthest element from the root in the directory hierarchy.
Returns:
a path representing the name of the file or directory, or null if this path has zero elements





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


Correct Answer : Get Lastest Questions and Answer :
Explanation: There is no predefined order by which thread can be executed. However, the count is a static variable which will be shared between all the instances of a
Welcome class. So any thread can operate on this.


Related Questions


Question : You have been given below code, what is the expected behavior. All are in same package?

class Parent {
public final void call(int min, int temp) {
}

public void mix() {
}
}
public final class Peer {
public void peerMethod() {
}
}

public class Peer2 {
private Parent c = new Parent();
private final double discount = 0.25;

public void peer2Call() {
c.call(10, 120);
}
}

public class Child1 extends Parent {
public void call(int minutes, int temperature) {}
public void childMethod() {
}
}

 : You have been given below code, what is the expected behavior. All are in same package?
1. A compilation error occurs in Parent.

2. A compilation error occurs in Peer.

3. Access Mostly Uused Products by 50000+ Subscribers

4. A compilation error occurs in Child1

5. All classes compile successfully.



Question : Which two statements are true about localizing an application?
A. Support for new regional languages does not require recompilation of the code.
B. Textual elements (messages and GUI labels) are hard-coded in the code.
C. Language and region-specific programs are created using localized data.
D. Resource bundle files include data and currency information.
E. Language codes use lowercase letters and region codes use uppercase letters.

 : Which two statements are true about localizing an application?
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. D,E
5. A,E


Question : Which statement is true about java.util.stream.Stream?


 : Which statement is true about java.util.stream.Stream?
1. A stream cannot be consumed more than once.

2. The execution mode of streams can be changed during processing.

3. Access Mostly Uused Products by 50000+ Subscribers

4. A parallel stream is always faster than an equivalent sequential stream



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

package com.hadoopexam;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream; public final class Welcome {
public static void main(String[] args) {
Stream paths = Stream.of(Paths.get("resources\\Message.properties"),
Paths.get("resources\\Message.txt"), Paths.get("resources\\Message.xml"));
paths.filter(s -> s.toString().endsWith("txt")).forEach(s -> {
try {
Files.readAllLines(s).stream().forEach(System.out::println); // line n1
} catch (IOException e) {
System.out.println("Exception");
} });
}
}
 : You have been given following code, what is the expected behavior?
1. The program prints the content of resources\\Message.txt file.

2. The program prints:
Exception
<>
Exception

3. Access Mostly Uused Products by 50000+ Subscribers

4. The program prints the content of the three files.


Question : You have been given below code, which of the following changes will help to compile the code?
package com.hadoopexam;

import java.io.IOException;

final class Peer {// line n1
// line n2
public void message() {
System.out.print("Welcome to HadoopExam");
}


}

public class Peer2 {
public static void main(String[] args) throws Exception {
try (Peer f = new Peer()) {
f.message();
}
}
}
A. Replace n1 with implements AutoCloseable {
B. Replace n2 with
public void close() throws IOException {
System.out.print("Close");
}
C. Replaceline n1with:
class Folder extends Closeable {

D. Replaceline n1with:
class Folder extends Exception {

 : You have been given below code, which of the following changes will help to compile the code?
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,D
5. B,D


Question : Which of the following are true for creating Singleton object?
A. Make the classstatic.
B. Make the constructorprivate.
C. Overrideequals() andhashCode() methods of the java.lang.Object class.
D. Use astaticreference to point to the single instance.
E. Implement theSerializableinterface.

 : Which of the following are true for creating Singleton object?
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. D,E
5. A,E