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.IntPredicate;
import java.util.stream.IntStream;

public class Welcome {
public static void main(String[] args) {
IntStream values = IntStream.of(-1, -2, -3, -4, 5, -6, -7);
IntPredicate positivePred = val -> val > 0;
if (values.anyMatch(positivePred)) {
int positiveVal = values.filter(positivePred).findAny().getAsInt(); //
System.out.println(positiveVal);
}
}
}
 : You have been given below code, what is the expected behavior?
1. Program will compile and run perfectly and print 5

2. Program will compile and run perfectly and print nothing

3. Access Mostly Uused Products by 50000+ Subscribers

4. Program will not compile


Correct Answer : Get Lastest Questions and Answer :
Explanation: As we can see in the code, we are trying to consume the same stream twice. First using anyMatch (It is a termination method) and second with findAny().
Second call with findAny() throw java.lang.IllegalStateException: stream has already been operated upon or closed




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

import java.util.stream.Stream;

public class Welcome {
public static void main(String[] args) {
boolean value = Stream.of("Ha", "do", "op", "Ex", "am", ".c", "om")
.filter(str -> str.length() > 3) //n1
.peek(System.out::println)
.allMatch(str -> str.length() > 5);
System.out.println(value);
}
}
 : You have been given below code, what is the behavior expected?
1. Code will give compile time error.

2. Code will throw IllegalStateException.

3. Access Mostly Uused Products by 50000+ Subscribers

4. Code will run perfectly and print true

5. Code will run perfectly and print true


Correct Answer : Get Lastest Questions and Answer :
Explanation: As we know that first predicate will not result any output at line n1, hence peek method will not print anything. Next we call allMatch method over the
empty stream. Hence, it will return true. Because allMatch() and noneMatch() on empty stream will return true.




Question : You have been given following code, what is the behavior you are expecting?
package com.hadoopexam;

import java.util.*;

class Welcome {
public static void main(String[] args) {
List list = Arrays.asList("Hadoop ", "Exam ", "Quick ", "Techie ");
Collections.sort(list, (str1, str2) -> str2.compareTo(str1));
list.forEach(word -> System.out.print(word));
}
}
 : You have been given following code, what is the behavior you are expecting?
1. Code will give compile time error.

2. Code will give runtime error

3. Access Mostly Uused Products by 50000+ Subscribers

4. Code will run perfectly and print "Exam Hadoop Quick Techie"


Correct Answer : Get Lastest Questions and Answer :
Explanation: As we know that Collections.sort() methods second argument should be a Comparator. Hence, we are creating a lambda expression which is a Comparator
for the sort method. However, we have provided labda expression such that str2 will be compared with str1. Which will produce result in descending order.


Related Questions


Question : Which one of the following statements is a correct way to instantiate a Statement object?


 : Which one of the following statements is a correct way to instantiate a Statement object?
1. Statement statement = connection.getStatement();

2. Statement statement = connection.createStatement();

3. Access Mostly Uused Products by 50000+ Subscribers

4. Statement statement = connection.getStatementInstance();



Question : Which one of the following statements is true with respect to ResultSet?


 : Which one of the following statements is true with respect to ResultSet?
1. Calling absolute(1) on a ResultSet instance is equivalent to calling
first(), and calling absolute(-1) is equivalent to calling last().

2. Calling absolute(0) on a ResultSet instance is equivalent to calling
first(), and calling absolute(-1) is equivalent to calling last().

3. Access Mostly Uused Products by 50000+ Subscribers
first(), and calling absolute(0) is equivalent to calling last().

4. Calling absolute(1) on a ResultSet instance is equivalent to calling
first(), and calling absolute(0) is equivalent to calling last().



Question : Please map below statements makes use of a factory method?

A. Locale locale1 = new Locale("en", "", "");
B. NumberFormat.getInstance(Locale.INDIA);
C. Locale locale3 = new Locale.Builder().setLanguageTag("en").build();
D. Date today = new Date();

1. Factory Method
2. Constructor instantiation
3. Access Mostly Uused Products by 50000+ Subscribers

 : Please map below statements makes use of a factory method?
1. 1-A, 2- B and D, 3-C
2. 1-B and D, 2- A, 3-C
3. Access Mostly Uused Products by 50000+ Subscribers
4. 1-B, 2- A , 3-C and D
5. 1-A and D, 2- D, 3-C