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.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


Correct Answer : Get Lastest Questions and Answer :
Explanation: There is no issue with the given code. It will compile and run as expected.
There are two predicates, which will be applied on each element of the list. First predicate will check whether each String in list has length greater than 4. At the same time second
predicate will check whether string contains "Hadoop" keyword or not. If it contains Hadoop keyword then it will be considered for count. In given code all the 4 string contains
"Hadoop" word so it will print 4 as an output.





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"


Correct Answer : Get Lastest Questions and Answer :
Explanation: Both count() and sum() are terminal operation. When you call termination operation on a stream. Stream will be consumed and you can not call next termination
operation. It will throw a runtime exception.




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.


Correct Answer : Get Lastest Questions and Answer :
Explanation: As you can see, we can have switch statement without break and default statement. So there will be no compile time exception. Because each case will be
checked against the each character, if match true will be returned else it will return false. For each vowel it will return true. And in filter function we have used the method
reference, where it will use each vowel it will get true hence it will be passed to forEach and printed. But this is not applied on non-vowel characters.


Related Questions


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

package com.hadoopexam;

import java.util.Arrays;
import java.util.List;

public class Welcome {
public static void main(String[] args) {
List sites = Arrays.asList("HadoopExam", "QuickTechie", "Training4Exam");
sites.forEach(allSite -> System.out.print(allSite + " "));
String courseSite = sites.stream().filter(s -> s.contains("i")).reduce((s, t) -> s + t).get();
System.out.println("\n" + courseSite);
}
}
 : You have been given below code, what is the expected behavior?
1. It will print
HadoopExam QuickTechie Training4Exam
QuickTechieTraining4Exam

2. It will print
HadoopExam QuickTechie Training4Exam
HadoopExam

3. Access Mostly Uused Products by 50000+ Subscribers
QuickTechieTraining4Exam
HadoopExam QuickTechie Training4Exam

4. It will print
QuickTechieTraining4Exam




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.Function;

public class Welcome {
public static void main(String[] args) {
List sites = Arrays.asList("HadoopExam.com", "Training4Exam.com", "QuickTechie.com");
Function funVal = s -> " Welcome to : ".concat(s);
sites.stream().map(funVal).peek(System.out::print);
}
}
 : You have been given below code, what is the expected behavior?
1. It will print Welcome to : HadoopExam.com Welcome to : Training4Exam.com Welcome to : QuickTechie.com

2. It will print HadoopExam.com: Training4Exam.com: QuickTechie.com

3. Access Mostly Uused Products by 50000+ Subscribers

4. There will be compilation error

5. There will be a runtime error.



Question : You have been given below interface

package com.hadoopexam;

public interface Welcome {

public default void call(Integer distance) {
System.out.println("Welcome to HadoopExam Learning Resources");
}

public void run(Integer distance);
}

Which is the valid use of Welcome interface?
 : You have been given below interface
1. Welcome courseCount = n -> System.out.println("Start watching Hadoop Training " + n);
courseCount.run(1);
courseCount.call(2);


2. Welcome courseCount = n ->n + 10;
courseCount.run(1);
courseCount.call(2);


3. Access Mostly Uused Products by 50000+ Subscribers
courseCount.run(1);
Welcome.call(2)


4. Welcome is not correctly declare to be used in a lambda expression.



Question : You have been given below code, what would be printed if executed

package com.hadoopexam;

class Welcome {
public static void main(String[] args) {
try {
int i = 10 / 0;
System.out.print("1 ");
} catch (ArithmeticException ae) {
System.out.print("2 ");
return;
} finally {
System.out.print("3 ");
}
System.out.print("4 ");
}
}
 : You have been given below code, what would be printed if executed
1. 1 2

2. 2 3

3. Access Mostly Uused Products by 50000+ Subscribers

4. 1 2 3

5. 2 3 4



Question : You have been given below code, please select correct behavior of it

package com.hadoopexam;

import java.util.Scanner;

class Welcome {
public static void main(String[] args) {
try (Scanner scanner = new Scanner(System.in)) {
scanner.close();
scanner.close();
}
}
}
 : You have been given below code, please select correct behavior of it
1. It will not compile

2. It will compile but run time , it will throw IllegalStateException

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will compile and run throw RuntimeException

5. It will compile, run and no output will be produced.



Question : You have been given below code, what happen if you execute it.
package com.hadoopexam;

class Welcome {
public static void main(String[] args) {
try {
assert false;
} catch (RuntimeException re) {
System.out.println("RuntimeException");
} catch (Exception e) {
System.out.println("Exception");
} catch (Error e) {
System.out.println("Error");
} catch (Throwable t) {
System.out.println("Throwable");
}
}
}
 : You have been given below code, what happen if you execute it.
1. It will print RuntimeException

2. It will print Exception

3. Access Mostly Uused Products by 50000+ Subscribers

4. It will print Throwable

5. It will print nothing