Premium

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



Question : You have been given below code,

package com.hadoopexam;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Welcome {

public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
System.out.print ("What is your course id? : ");
//n1
}
}
Which of the below code segment you will use, so that it can read the values entered from keyboard by user?
 : You have been given below code,
1. int courseId = Integer.parseInt (bufferedReader.readline());

2. int courseId = bufferedReader.read();

3. int courseId = bufferedReader.nextInt();

4. int courseId = Integer.parseInt (bufferedReader.next());


Correct Answer : Get Lastest Questions and Answer :
Explanation: String java.io.BufferedReader.readLine() throws IOException

Reads a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.
Returns:
A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached
int java.io.BufferedReader.read() throws IOException

Reads a single character.
Overrides: read() in Reader
Returns:
The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached





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

package com.hadoopexam;

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

class Welcome {

public static void main(String[] args) throws IOException {
Path source = Paths.get ("resources\\test\\Message.properties");
Path destination = Paths.get("resources");
Files.copy(source, destination);
}
}
 : You have been given below code, what is the behavior expected?
1. It will create a new file name Message.properties in resources directory.

2. It will create a new file "resources\\resources\\test\\Message.properties"

3. It will throw run time exception, with " FileAlreadyExistsException"

4. It will not do anything , just run and come out.


Correct Answer : Get Lastest Questions and Answer :
Explanation: : Path java.nio.file.Files.copy(Path source, Path target, CopyOption... options) throws IOException

Copy a file to a target file.
This method copies a file to the target file with the options parameter specifying how the copy is performed. By default, the copy fails if the target file already exists or is a
symbolic link, except if the source and target are the same file, in which case the method completes without copying the file. File attributes are not required to be copied to the
target file. If symbolic links are supported, and the file is a symbolic link, then the final target of the link is copied. If the file is a directory then it creates an empty
directory in the target location (entries in the directory are not copied). This method can be used with the walkFileTree method to copy a directory and all entries in the directory,
or an entire file-tree where required.
Parameters:
source the path to the file to copy
target the path to the target file (may be associated with a different provider to the source path)
options options specifying how the copy should be done
Returns:
the path to the target file
Throws:
UnsupportedOperationException - if the array contains a copy option that is not supported
FileAlreadyExistsException - if the target file exists but cannot be replaced because the REPLACE_EXISTING option is not specified (optional specific exception)
DirectoryNotEmptyException - the REPLACE_EXISTING option is specified but the file cannot be replaced because it is a non-empty directory (optional specific exception)
IOException - if an I/O error occurs
SecurityException - In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to the source file, the checkWrite
is invoked to check write access to the target file. If a symbolic link is copied the security manager is invoked to check LinkPermission("symbolic").





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

package com.hadoopexam;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

class Welcome {

String course, name, city;

public Welcome(String name, String course, String city) {
this.course = course;
this.name = name;
this.city = city;
}

public String toString() {
return course + ":" + name + ":" + city;
}

public String getCourse() {
return course;
}

public void setCourse(String course) {
this.course = course;
}

public static void main(String[] args) throws IOException {
List stds = Arrays.asList(
new Welcome ("Amit", "Hadoop", "Chennai"),
new Welcome ("Kumar", "Spark", "New Delhi"),
new Welcome ("Jatin", "AWS", "Kolkata"));
stds.stream().collect(Collectors.groupingBy(Welcome::getCourse)).forEach((src, res) -> System.out.print(src+":"));
}
}

 : You have been given below code, what is the expected behavior?
1. It will print "Hadoop:Spark:AWS:"

2. It will print "Jatin:Kumar:Amit:"

3. It will print "New Delhi:Chennai:Kolkata:"

4. It will not print "Jatin:New Delhi:Chennai:"


Correct Answer : Get Lastest Questions and Answer :
Explanation: It will print only unique keys from the Map, created.

Collector>> java.util.stream.Collectors.groupingBy(Function classifier)

Returns a Collector implementing a "group by" operation on input elements of type T, grouping elements according to a classification function, and returning the results in a Map.
The classification function maps elements to some key type K. The collector produces a Map> whose keys are the values resulting from applying the
classification function to the input elements, and whose corresponding values are Lists containing the input elements which map to the associated key under the classification
function.
There are no guarantees on the type, mutability, serializability, or thread-safety of the Map or List objects returned.



Related 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.



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.



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



Question : You have been given a Course table, with following columns detail.

. COURSE_ID:INTEGER: PK
. COURSENAME:VARCHAR(100)
. COST:REAL
. QUANTITY:INTEGER

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

package com.hadoopexam;

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

public class Welcome {
public static void main(String[] args) {
try {
Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");
String query = "Select * FROM SUBSCRIBER WHERE COURSE_ID = HDP100";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
System.out.println("COURSE ID:" + rs.getInt("COURSE_ID"));
System.out.println("Course name:" + rs.getString("COURSENAME"));
System.out.println("Cost of the course :" + rs.getDouble("COST"));
System.out.println("Total order :" + rs.getInt("QUANTITY"));
}
} catch (SQLException se) {
System.out.println("There is an Error");
}
}
}

 : You have been given a Course table, with following  columns detail.
1. An exception is thrown at runtime.

2. Compilation fails.

3. Access Mostly Uused Products by 50000+ Subscribers

4. The code prints information about Item HDP100.



Question : You have been given below code.

package com.hadoopexam;

import java.util.concurrent.CyclicBarrier;

public class Welcome extends Thread {
CyclicBarrier cb;

public Welcome(CyclicBarrier cb) {
this.cb = cb;
}

public void run() {
try {
cb.await();
System.out.println("Slave worker");
} catch (Exception ex) {
}
}
}

import java.util.concurrent.CyclicBarrier;

class Peer implements Runnable { // line n1
public void run() {
System.out.println("Controller Thread ...");

}

public static void main(String[] args) {
Peer master = new Peer();
CyclicBarrier cb = new CyclicBarrier(1, master);
//line n2
Welcome worker = new Welcome(cb);
worker.start();
}
}

Which of the following modification will help the code to run both the tread. First controller and then slave?

 : You have been given below code.
1. At line n2, insert CyclicBarrier cb = new CyclicBarrier(2, master);

2. Replace line n1 with class Master extends Thread {

3. Access Mostly Uused Products by 50000+ Subscribers

4. At line n2, insert CyclicBarrier cb = new CyclicBarrier(master);



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

package com.hadoopexam;

import java.util.function.ToIntFunction;

public class Welcome {
public static void main(String[] args) {
String message = "Welcome to HadoopExam Learning Resources";
ToIntFunction index = message::indexOf;
int position = index.applyAsInt("H");
System.out.println(position);
}
}

 : You have been given below code, what is the expected output?
1. 0

2. 11

3. Access Mostly Uused Products by 50000+ Subscribers

4. A compilation error occurs.

5. A runtime error occurs.