Premium

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



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

package com.hadoopexam;

import java.io.FileInputStream;
import java.io.InputStreamReader;

public class Welcome {

public static void main(String[] args) {
int i;
char c;
try (FileInputStream fileInputStream = new FileInputStream("resources\\Message.properties");
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);) {
while (inputStreamReader.ready()) { // line n1
inputStreamReader.skip(2);
i = inputStreamReader.read();
c = (char) i;
System.out.print(c);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
 : You have been given below code, what is expected behavior?
1. tHoEmo?

2. t:HoEmo?

3. Access Mostly Uused Products by 50000+ Subscribers

4. A compilation error occurs at line n1.


Correct Answer : Get Lastest Questions and Answer :
Explanation: boolean java.io.InputStreamReader.ready() throws IOException

Tells whether this stream is ready to be read. An InputStreamReader is ready if its input buffer is not empty, or if bytes are available to be read from the underlying byte stream.
int java.io.InputStreamReader.read() throws IOException
Reads a single character.
Returns:
The character read, or -1 if the end of the stream has been reached
long java.io.Reader.skip(long n) throws IOException

Skips characters. This method will block until some characters are available, an I/O error occurs, or the end of the stream is reached.
Parameters:
n The number of characters to skip
Returns:
The number of characters actually skipped





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


package com.hadoopexam;

public class Welcome {
private T t;

public T get() {
return t;
}

public void set(T t) {
this.t = t;
}

public static void main(String args[]) {
Welcome siteName = new Welcome<>();
Welcome userId = new Welcome();// line n1
siteName.set("HadoopExam.com");
userId.set(101);// line n2
System.out.print(siteName.get() + ":" + userId.get());
}
}
 : You have been given below code, what is the expected output?
1. HadoopExam.com:101

2. java.lang.string@java.lang.Integer@

3. Access Mostly Uused Products by 50000+ Subscribers
Welcome userId = new Welcome();

4. A compilation error occurs. To rectify it, replace line n2with:
userId.set (Integer(101));


Correct Answer : Get Lastest Questions and Answer :
Explanation: With generics, you write code for one type (say T) that is applicable for all types, instead of writing separate classes for each type.




Question : You have been given below class and its member variables ,

package com.hadoopexam;

public class Welcome {
String name;

void setName(String name) {
this.name = name;
}

String getName() {
return name;
}
}

Which action encapsulates the Welcome class?
 : You have been given below class and its member variables ,
1. Make the Vehicle class public.

2. Make the name variable public.

3. Access Mostly Uused Products by 50000+ Subscribers

4. Make the name variable private.

5. Make the setName method private.



Correct Answer : Get Lastest Questions and Answer :
Explanation: Publicly visible data members violate encapsulation since any code can modify the
name value of a Welcome object directly. It is important to make data members private to enforce encapsulation.



Related Questions


Question : You have been given below code, what is 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.nio.file.StandardCopyOption;

public class Welcome {

public static void main(String[] args) throws IOException {
Path sourceFile = Paths.get("resources\\Message.xml");
Path destinition = Paths.get("resources\\sub\\Message.xml");
Files.move(sourceFile, destinition, StandardCopyOption.ATOMIC_MOVE);
Files.delete(sourceFile);
}
}
 : You have been given below code, what is expected behavior?
1. The Messaage.xml file content is replaced by the sub\Message.xml file content and the sub\Message.xml file is deleted.

2. The sub\Message.xml file content is replaced by the Message.xml file content and an exception is thrown.

3. Access Mostly Uused Products by 50000+ Subscribers

4. A FileAlreadyExistsException is thrown at runtime.



Question : You have been given below interface, which of the below two will compile successfully.

public interface Welcome {
}


A. abstract class ChildA implements Welcome {
public void call(String s) {
}
}
B. abstract class ChildB implements Welcome {
public abstract void call(String s) { }
public void callB(Boolean b) { }
}

C. class ChildC implements Welcome {
public void call(Integer i) {
}
}
D. class ChildD implements Welcome {
public void callA(Integer i) {
}

public String callB(Integer j) {
}
}


 : You have been given below interface, which of the below two will compile successfully.
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,D
5. B,D


Question : You have been given below code, which code snippet should be replaced at line n , so that it can print
 : You have been given below code, which code snippet should be replaced at line n , so that it can print
1. Stream.of(dataSet1, dataSet2)
.flatMap(data -> data.stream())
.forEach(s -> System.out.print(s + " "));

2. Stream.of(dataSet1, dataSet2)
.flatMap(data -> data.intStream())
.forEach(s -> System.out.print(s + " "));

3. Access Mostly Uused Products by 50000+ Subscribers
.flatMap(dataSet2.stream().flatMap(e1 -> e1.stream()).forEach(s -> System.out.println(s + " ")));

4. Stream.of(dataSet1, dataSet2)
.flatMapToInt(data -> data.stream())
.forEach(s -> System.out.print(s + " "));



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