Premium

Oracle Advacned Java Advanced Certification Questions and Answers (Dumps and Practice 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.


Correct Answer : Get Lastest Questions and Answer :
Explanation: As soon as we are out of block. Stream will be closed.

boolean java.io.BufferedReader.ready() throws IOException
Tells whether this stream is ready to be read. A buffered character stream is ready if the buffer is not empty, or if the underlying character stream is ready.
Overrides: ready() in Reader
Returns:
True if the next read() is guaranteed not to block for input, false otherwise. Note that returning false does not guarantee that the next read will block.
Throws:
IOException - If an I/O error occurs





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.


Correct Answer : Get Lastest Questions and Answer :
Explanation: private method is not accessible in other classes. It will be accessible only in same class.




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


Correct Answer : Get Lastest Questions and Answer :
Explanation: Callable is interface, hence B cannot be correct. Call() methods can retrun Object not primitive type. Hence, option A is wrong.

V java.util.concurrent.Callable.call() throws Exception

Computes a result, or throws an exception if unable to do so.
Returns:
computed result
Throws:
Exception - if unable to compute a result



Related Questions


Question : You have been given below code, what is the expected behavior?
package com.hadoopexam;

import java.io.IOException;

public class Welcome extends Thread {

@Override
public void run() {
System.out.print("HadoopExam");
}

public static void main(String[] args) throws IOException, InterruptedException {
Welcome wel = new Welcome();
wel.start();
Thread.sleep(500);
System.out.print(".com ");
}
}
 : You have been given below code, what is the expected behavior?
1. It will give compile time error

2. It will give run time error

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will print "HadoopExam"

5. It will print "HadoopExam.com"



Question : You have a various runnable tasks, which needs to be executed one by one, based on their priority (Between to ). However, you are keep getting higher priority tasks
in the Queue and you lower priority tasks will never get an opportunity to being executed. Which of the following problem is discussed in above statement?

A. Deadlock
B. Starvation
C. Livelock
D. R ace condition

 : You have a various runnable tasks, which needs to be executed one by one, based on their priority (Between  to ). However, you are keep getting higher priority tasks
1. Deadlock

2. Starvation

3. Access Mostly Uused Products by 50000+ Subscribers

4. R ace condition



Question : Which of the following definition are correct?

 : Which of the following definition are correct?
1. class Welocme {
public synchronized void foo() {}
}


2. abstract class Welcome {
public abstract synchronized void foo();
}


3. Access Mostly Uused Products by 50000+ Subscribers
public synchronized void foo();
}


4. A and C



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

package com.hadoopexam;

import java.util.concurrent.atomic.AtomicInteger;

public class Welcome {
static AtomicInteger atomicInt = new AtomicInteger(100);

public static void plustOne() {
atomicInt.incrementAndGet();
}

public static void minusOne() {
atomicInt.getAndDecrement();
}

public static void setValue() {
atomicInt.compareAndSet(100, 99);
}

public static void main(String[] args) {
plustOne();
minusOne();
setValue();
System.out.println(atomicInt);
}
}

 : You have been given below code, what is the expected behavior?
1. It will give compile time error.

2. It will print 100

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will print 99

5. It will print "Null"



Question : You have been given below code, what is the output, when executed using command "java -ea RateOfInterest"
package com.hadoopexam;
public class Welcome {

public static void main(String[] args) {
int courseFee = 0;
String courseName = "Web Service";
switch (courseName) {
case "Hadoop":
courseFee = 79;
break;
case "Spark":
courseFee = 89;
break;
default:
assert false : "Given course is in Progress and currently not available"; // line n1
}
System.out.println("Fees for the course is :" + courseFee);
}
}
 : You have been given below code, what is the output, when executed using command
1. AssertionError: Given course is in Progress and currently not available

2. It will print Given course is in Progress and currently not available.

3. Access Mostly Uused Products by 50000+ Subscribers

4. A compilation error occurs at line n1.



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

package com.hadoopexam;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class Welcome implements Callable {
String message;

public Welcome(String s) {
this.message = s;
}

public String call() throws Exception {
return message.concat("Welcome to HadoopExam Learning Resources");
}

public static void main(String[] args) throws InterruptedException, ExecutionException {
ExecutorService executorService = Executors.newFixedThreadPool(4); // line n1
Future futureResult = executorService.submit(new Welcome("Thank you ... "));
String resultValue = futureResult.get().toString();
System.out.println(resultValue);
}
}

 :
1. The program prints Thank you ... Welcome to HadoopExam Learning Resources and terminates.

2. The program prints Thank you ... Welcome to HadoopExam Learning Resources and does not terminate.

3. Access Mostly Uused Products by 50000+ Subscribers

4. An ExecutionExceptionis thrown at run time.