Premium

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



Question : You have been given below code, what behavior are you expecting ?

package com.hadoopexam;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

class Welcome {

public static void main(String[] args) {

Stream> iStr = Stream.of(Arrays.asList("1", "Amit"),
Arrays.asList("2", null), Arrays.asList("1", "Amit"));
Stream stream = iStr.flatMap((x) -> x.stream());
stream.forEach(System.out::print);
}
}


 : You have been given below code, what behavior are you expecting ?
1. It will give compile time error

2. It will give runtime error and produce NullPointer Exception

3. It will run and print "1Amit2null1Amit"

4. It will run and print "1Amit2null"


Correct Answer : 3
Explanation: flatMap function will change list of list to kind of flatten map.

[1, Amit]
[2, null]
[1, Amit]

It will be changed like this
[1, Amit, 2, null, 1 , Amit]

And forEach loop will print each element one by one. Hence, result will be
1Amit2null1Amit





Question : Which ONE of the following statements is TRUE?


 : Which ONE of the following statements is TRUE?
1. You cannot extend a concrete class and declare that derived class abstract

2. You cannot extend an abstract class from another abstract class

3. A n abstract class must declare at least one abstract method in it

4. You can create an instance of a concrete subclass of an abstract class but
cannot create an instance of an abstract class itself


Correct Answer : 4
Explanation:




Question : You have been given below code,

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;

class Welcome {

public static void main(String[] args) throws IOException {

Path file = Paths.get ("Welcome.java");

//n1
}
}

Which of the below code , can be replaced with line n1 so that Welcome.java contents can be printed?

 : You have been given below code,
1. Stream fc = Files.lines(file);
fc.forEach (s -> System.out.println(s));

2. Stream fc = Files.readAllLines(file);
fc.forEach (s -> System.out.println(s));


3. List fc = readAllLines(file);
fc.stream().forEach (s - > System.out.println(s));


4. List fc = Files.list(file);
fc.stream().forEach(s -> System.out.println(s));


Correct Answer : 1
Explanation: Stream java.nio.file.Files.lines(Path path) throws IOException

Read all lines from a file as a Stream. Bytes from the file are decoded into characters using the UTF-8 charset.
This method works as if invoking it were equivalent to evaluating the expression:
Files.lines(path, StandardCharsets.UTF_8)
Parameters:
path the path to the file
Returns:
the lines from the file as a Stream



Related Questions


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

package com.hadoopexam;

import java.util.function.Predicate;

interface CourseFilter extends Predicate {
public default boolean test(String str) {
return str.equals("Hadoop");
}
}

package com.hadoopexam;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

class Welcome {

public static void main(String[] args) throws IOException {
List strs = Arrays.asList("Hadoop and Spark", "Hadoop and HBase", "Hadoop and AWS", "Hadoop ");
Predicate predicate = s -> s.length() > 4;
Predicate cf2 = new CourseFilter() { // line n1
public boolean test(String s) {
return s.contains("Hadoop ");
}
};

long c = strs.stream().filter(predicate).filter(cf2)// line n2
.count();
System.out.println(c);
}
}

 : You have been given below code, what is the expected behavior?
1. It will fail to compile

2. It will run and print 3

3. It will run and print 4

4. It will run and print 0



Question : You have been given following code, what will be the behavior?

package com.hadoopexam;

import java.util.stream.DoubleStream;

public class Welcome {
public static void main(String[] args) {
DoubleStream nums = DoubleStream.of(1.0, 2.0, 3.0).map(i -> -i); // n1
System.out.printf("Total element count = %d, Sum of all elements = %f", nums.count(), nums.sum());
}
}
 : You have been given following code, what will be the behavior?
1. Code will compile and run successful with output as Total element count = 3, Sum of all elements = 6

2. Code will compile and run successful with output as Total element count = 3, Sum of all elements =

3. Code will give compile time exception as you can not use same stream twice.

4. Code will compile, but will throw a RuntimeException "java.lang.IllegalStateException: stream has already been operated upon or closed"



Question : You have been given following code, what would be the behavior of it.

package com.hadoopexam;

class Welcome {
private static boolean checkChars(int c) {
switch (c) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
return true;
}
return false;
}

public static void main(String[] args) {
"hadoopexam.com".chars().filter(Welcome::checkChars)
.forEach(ch -> System.out.printf("%c", ch));
}
}
 : You have been given following code, what would be the behavior of it.
1. It will compile and run successfully and print nothing

2. It will compile and run successfully and print hdpxm.cm

3. It will compile and run successfully and print aooeao

4. It will give compile time error. Because, you don't have break and default statement in switch.



Question : You have been given the below code, what is the behavior you expect.

package com.hadoopexam;

import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;

class Welcome {
public static void main(String[] args) {
Deque deque = new ArrayDeque<>();
deque.addAll(Arrays.asList(1, 2, 3, 4, 5));
System.out.println("First removed element is = " + deque.remove());
}
}
 : You have been given the below code, what is the behavior you expect.
1. Code will through compile time exception.

2. Code will compile but through Runtime exception "IllegalStateException"

3. Code will compile and run perfectly and print First removed element is = 5

4. Code will compile and run perfectly and print First removed element is = 1



Question : You have been given below code. Select the correct behavior of the code.

package com.hadoopexam;

class Parent {

private T test;
void call(T t) {
test = t;
System.out.println("Testing Method 1");
}
}



package com.hadoopexam;

class Welcome extends Parent {
public Welcome(S s) {
}

void call(S s) {
System.out.println("Testing Method 2");
}
}

package com.hadoopexam;

class Test {
public static void main(String[] args) {
Welcome err = new Welcome("Test");
err.call("Calling");
}
}

 : You have been given below code. Select the correct behavior of the code.
1. Code will compile and run with the output as "Testing Method 2"

2. Code will compile and run with the output as "Testing Method 1"

3. Access Mostly Uused Products by 50000+ Subscribers

4. Code will not compile because there is an ambiguity in code call method



Question : Select the correct functional interface from below.

A. java.util.stream.Stream
B. java.util.function.Consumer
C. java.util.function.Supplier
D. java.util.function.Predicate
E. java.util.function.Function

 : Select the correct functional interface from below.
1. A,B,C
2. B,C,D
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,D,E
5. B,C,D,E