Premium

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



Question : You have been given below code,

package com.hadoopexam;

abstract class Welcome {
Welcome() {
System.out.println("Welcome Constructor");
}

protected void message() {
System.out.println("Hello and welcome to HadoopExam.com");
}
}


package com.hadoopexam;

class Child1 extends Welcome {
int weight;

Child1(int weight) {
//n1
this.weight = weight;
}

public void message() {
System.out.println("Welcome to Child 1 Class");
}
}

class GrandChild1 extends Child1 {
int age, height;

GrandChild1(int x, int y) {
//n2
age = x;
height = y;
}

public void message() {
System.out.println("Welcome to grand child class");
}
}

Which of the following statement are correct, so that code will compile without error?



 : You have been given below code,
1. Replace n1 with this()

2. Replace n1 with super(x)

3. Replace n2 with super(x)

4. Replace n2 with super(x,y)


Correct Answer : 3
Explanation: As you know, when we have parent child relation. We should take care of constructor chaining as well. Suppose you are defining a constructor with argument
in parent class e.g. Child1 class having one argument constructor. Hence, GrandChild1 constructor class have to explicitly call super constructor to get it compiled.
And super(x) call should be the first line of constructor.




Question : Which of the following method(s) from Object class can be overridden? (Select all that apply.)
A. finalize()
B. clone()
C. getClass()
D. notify()
E. wait()

 : Which of the following method(s) from Object class can be overridden? (Select all that apply.)
1. A,B
2. B,C
3. C,D
4. D,E
5. A,E

Correct Answer : 1
Explanation: The methods finalize() and clone() can be overridden. The methods getClass(),
notify(), and wait() are final methods and so cannot be overridden.





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

package com.hadoopexam;

import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.RecursiveAction;

class Welcome extends RecursiveAction { // line n1
static final int MAX_INDEX_COUNT = 3;
int startIndex, lastIndex;
int[] data;

public Welcome(int[] data, int start, int end) {
this.data = data;
this.startIndex = start;
this.lastIndex = end;
}

protected void compute() {
int sum = 0;
if (lastIndex - startIndex <= MAX_INDEX_COUNT) {
for (int i = startIndex; i < lastIndex; i++) {
sum += data[i];
}
System.out.println(sum);
} else {
new Welcome(data, startIndex + MAX_INDEX_COUNT, lastIndex).fork();
new Welcome(data, startIndex, Math.min(lastIndex, startIndex + MAX_INDEX_COUNT)).compute();
}
}

public static void main(String[] args) {
ForkJoinPool fjPool = new ForkJoinPool();
int data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
fjPool.invoke(new Welcome(data, 0, data.length));
}
}
 : You have been given below code, what is the expected behavior?
1. Code will give compile time error

2. Code will run and print 55

3. Code will run and print any one value between 0 to 55

4. Code will run and print 4 values, whose total will be 55



Correct Answer : 4
Explanation: It is a complete example of Fork-Join application. In this we have 1 to 10 values , total 10 elements. We are forking new compute task
for each 3 indexes. Here we have 10 elements as below.

0 to 2 -> total will be (1+2+3) -> 6
3 to 5 -> total will be (4+5+6) -> 15
6 to 9 -> total will be (7+8+9) ->24
10 -> total will be 10

Hence, resultant total should be 6+15+24+10 = 55

So each fork compute task is print its result.



Related Questions


Question : You have been given below code, please select the correct option which applies to it.

package com.hadoopexam;

import java.util.*;

class Welcome {
public static void main(String []args) {
List hList = new ArrayList<>();
hList.add(1);
hList.add(2);
System.out.println("Contents in list are : " + hList);
}
}
 : You have been given below code, please select the correct option which applies to it.
1. Code will compile and run perfectly and print to "Contents in list are : [1,2]"

2. Code will compile and run perfectly and print to "Contents in list are : [2,1]"

3. Code will compile successfully but will produce run time error IllegalStateException

4. Code will not compile



Question : You have been given below code, what would be printed once you run the code.

package com.hadoopexam;

import java.util.*;

class Welcome {
public static void main(String[] args) {
List integerList = new LinkedList<>();
List doublelList = new LinkedList<>();
System.out.println("Type of integerList = " + integerList.getClass());
System.out.println("Type of doublelList = " + doublelList.getClass());
}
}
 : You have been given below code, what would be printed once you run the code.
1. It will print following statements
Type of integerList = class java.util.LinkedList
Type of doublelList = class java.util.LinkedList

2. It will print following statements
Type of integerList = class java.util.LinkedList<>
Type of doublelList = class java.util.LinkedList<>

3. It will print following statements
Type of integerList = class java.util.LinkedList
Type of doublelList = class java.util.LinkedList

4. It will print following statements
Type of integerList = class java.util.List
Type of doublelList = class java.util.List




Question : You have been given following code, please select the correct statement for it.

package com.hadoopexam;

import java.util.Arrays;

class Welcome {
public static void main(String[] args) {
String[] names = { "Bala", "Reena", "Iva", "Cate" };
Arrays.sort(names, null); //n1
for (String name : names) {
System.out.print(name + " ");
}
}
}

 : You have been given following code, please select the correct statement for it.
1. Code will not compile.

2. Code will compile but produce runtime error. As no InvalidComparatorException is defined.

3. There will be no compile time error. Code will be run successfully and print Bala Cate Iva Reena

4. There will be no compile time error. Code will be run successfully and print "Bala", "Reena", "Iva", "Cate"



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