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.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

public class Welcome {
public static void main(String[] args) {
List str = Arrays.asList("Welcome", "to", "HadoopExam", "Learning", "Resources");
Predicate predicate = s -> {
int counter = 0;
boolean result = s.contains("Hadoop");
System.out.print((counter++) + ":");
return result;
};
str.stream().filter(predicate).findFirst().ifPresent(System.out::print);

}
}

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

2. 0 : 1 : 2 : Hadoop

3. Access Mostly Uused Products by 50000+ Subscribers

4. 0 : 1 : 2 : 3 : 4 :

5. A compilation error occurs.


Correct Answer : Get Lastest Questions and Answer :
Explanation: Counter value is always re-initialized in predicate call. Hence, count value=0.




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

package com.hadoopexam;

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

public class Welcome {
public static void main(String[] args) {
List subscriberInfo = Arrays.asList("100, Amit, Hadoop : ", "200, Martha, Spark : ", "101, Piyush, Java : ");
subscriberInfo.stream().filter(s -> s.contains("1")).sorted()
.forEach(System.out::print); // line n1
}
}
 : You have bene given code, what is the expected behavior?
1. 101, Piyush, Java : 100, Amit, Hadoop :

2. 100, Amit, Hadoop : 101, Piyush, Java :

3. Access Mostly Uused Products by 50000+ Subscribers

4. 100, Amit, Hadoop : 101, Piyush, Java : 200, Martha, Spark :

5. Compile time error.


Correct Answer : Get Lastest Questions and Answer :
Explanation: In this code, we are filtering the all the string which contains 1. And then we sort the output.




Question : You have been given below code, which of the code segment can be replaced at n. Which create an instance of Welcome class?

package com.hadoopexam;

public class Welcome {

private String name;

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

public static void main(String[] args) {
// n1

}
}

interface Hello {
Welcome get(String name);
}
 : You have been given below code, which of the code segment can be replaced at n. Which create an instance of Welcome class?
1. Welcome wel = Welcome ("Welcome to HadoopExam.com"):: new;

2. Welcome wel = Welcome :: new;
Welcome wel1 = wel :: get("Welcome to HadoopExam.com");

3. Access Mostly Uused Products by 50000+ Subscribers
Welcome wel = hello.get("Welcome to HadoopExam.com");

4. Welcome vehicle = Hello :: new :: get("Welcome to HadoopExam.com");


Correct Answer : Get Lastest Questions and Answer :
Explanation:


Related Questions


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


package com.hadoopexam;

class Welcome {
int counter;
int counter1;

Welcome() {
this(10);
}

Welcome(int c) {
counter = c;
counter1 = c;

}

public String toString() {
return "counter vale is: " + counter+counter1;
}

public static void main(String[] args) {
System.out.println(new Welcome());
}
}


 : You have been given below code, please select the correct option for it.
1. It will give compile time error, saying method Welcome(int) is not defined.

2. It will give compile time error. As counter is defined.

3. It will give runtime error, by throwing NullPointerException.

4. The code will run perfectly and print "counter value is: 1010"

5. The code will run perfectly and print "counter value is: 20"



Question : You have been given below code

package com.hadoopexam;

class Welcome {
private K key;
private V value;

public Welcome(K key, V value) {
this.key = key;
this.value = value;
}

public static Welcome createPair(T value) {
return new Welcome(value, value);
}

public K getKey() {
return key;
}

public V getValue() {
return value;
}

}
Which of the belwo option is invalid?

 : You have been given below code
1. Welcome score = new Welcome("Amit",100);

2. Welcome welcomePair = Welcome. createPair("HadoopExam.com");

3. Welcome anotherPair = new Welcome<>(97, 32);

4. Welcome myGrade = new Welcome<>("Amit", "B+");

5. None of the above



Question : What is the behavior is expected from below code ?

package com.hadoopexam;
class Welcome {
int counter;

Welcome() {
this(10);
}

Welcome(int c) {
counter=c;
}

String toString() {
return "Value of counter is" + counter;
}

public static void main(String[] args) {
System.out.println(new Welcome());
}
}

 : What is the behavior is expected from below code ?
1. It will compile and run perfectly and product output as "Value of counter is 10"

2. It will compile and run perfectly and product output as "Value of counter is 0"

3. Code will not compile as no valid Welcome(int) method is defined.

4. Code will not compile because, you are trying to restrict the visibility of toString() method.

5. As we know, every class by default extends the Object class. Which has public toString() method. Hence, you cannot restrict the access modifiers
for the overridden method.


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"



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



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));