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.regex.Pattern;
import java.util.stream.Stream;

public class Welcome {
public static void main(String[] args) {
Stream words = Pattern.compile(" ").splitAsStream("Hadoop Exam .com Quick Techie .com");
System.out.println(words.map(word -> word.length()).sum());
}
}
 : You have been given below code, what is the expected behavior
1. Code will give compile time error.

2. Code will give run time error.

3. Access Mostly Uused Products by 50000+ Subscribers

4. Code will run and compile perfectly and print 29



Correct Answer : Get Lastest Questions and Answer :
Explanation: As we have used map function using lambda expression which return as Stream. And you know that sum() method is not available on it.
Hence, you will get compile time error. To solve this issue we should have used mapToInt() method as below.

System.out.println(words.mapToInt(word -> word.length()).sum());





Question : You have been given below code, select the correct behavior
package com.hadoopexam;

import java.util.OptionalInt;
import java.util.stream.IntStream;

public class Welcome {
public static void main(String args[]) {
maxValue(IntStream.of(1,2,3,4,5)); // //n1
}

public static void maxValue(IntStream values) {
OptionalInt max = values.max(); //n2
if (max.ifPresent()) { //n3
System.out.print(max.getAsInt());
}
}
}
 : You have been given below code, select the correct behavior
1. Code will give compile time error.

2. Code will give run time error

3. Access Mostly Uused Products by 50000+ Subscribers

4. Code will run perfectly and print nothing


Correct Answer : Get Lastest Questions and Answer :
Explanation: : Look carefully, its illusion question. You check method at line n3, it is not isPresent it is ifPresent() method. And ifPresent() signature
is wrong. Hence, you will get compile time error. Change ifPresent to isPresent you will get 5 as output.




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

package com.hadoopexam;

import java.util.Optional;
import java.util.stream.Stream;

public class Welcome {
public static void main(String args[]) {
Stream.of("Hadoop ", "Exam ", ".com ", null).forEach(Welcome::changeCase);
}

private static void changeCase(String word) {
Optional str = Optional.ofNullable(word);
System.out.print(str.map(String::toUpperCase).orElse("NULL"));
}
}
 : You have been given below code, what is the expected behavior?
1. Code will give compile time error.

2. Code will give run time error.

3. Access Mostly Uused Products by 50000+ Subscribers

4. Code will run perfectly and print "Hadoop Exam .com NULL"


Correct Answer : Get Lastest Questions and Answer :
Explanation: There are following important point to understand
ofNullable() : Returns an Optional describing the specified value, if non-null, otherwise returns an empty Optional.
orElse() : Return the value if present, otherwise return other.



Related Questions


Question : Which of the following is a correct override for extending the ListResourceBundle class?


 : Which of the following is a correct override for extending the ListResourceBundle class?
1. public HashMap getContents() {
Map contents = new HashMap<>();
contents.add("Hadoop", "Exam");
return contents;
}

2. public Object[] getContents() {
return new Object[] { { "Hadoop" } , { "Exam" } };
}

3. public Object[][] getContents() {
return new Object[][] { { "Hadoop", "Exam" } };
}

4. public String[] getKeysAndValues() {
return new String[] { { "Hadoop" } , { "Exam" } };
}



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

package com.hadoopexam;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;

public class Welcome {

public static void main(String[] args) {
ZonedDateTime startTime = ZonedDateTime.of(2016, 1, 01, 2, 0, 0, 0, ZoneId.of("UTC-4"));
ZonedDateTime endTime = ZonedDateTime.of(2016, 1, 01, 8, 0, 0, 0, ZoneId.of("UTC-1"));
long hrs = ChronoUnit.HOURS.between(startTime, endTime); // line n1
System.out.println("Total time difference is " + hrs + " hours");
}
}


 : You have been given below code, what is the behavior expectd?
1. Total time difference is 4 hours

2. Total time difference is 3 hours

3. Total time difference is 2 hours

4. An exception is thrown at line n1.



Question : Assume that you've the following resource bundles in your classpath:
ResourceBundle.properties
ResourceBundle_ar.properties
ResourceBundle_en.properties
ResourceBundle_it.properties
ResourceBundle_it_IT_Rome.properties
Also assume that the default locale is English (US), where the language code is en and
country code is US. Which one of these five bundles will be loaded for the call
loadResourceBundle("ResourceBundle", new Locale("fr", "CA", ""));?


 : Assume that you've the following resource bundles in your classpath:
1. ResourceBundle.properties

2. ResourceBundle_ar.properties

3. ResourceBundle_en.properties

4. ResourceBundle_it.properties

5. ResourceBundle_it_IT_Rome.properties



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

package com.hadoopexam;

import java.nio.file.Path;
import java.nio.file.Paths;

public class Welcome {

public static void main(String[] args) {
Path path1 = Paths.get("/my/./file/");
Path res1 = path1.resolve("file.txt");
Path path2 = Paths.get("/data/use/");
Path res2 = path2.resolve("/hadoop.txt/");
System.out.println(res1);
System.out.println(res2);
}
}


 : You have been given below code, what is the expected result ?
1. \my\.\file\file.txt
\data\use\hadoop.txt

2. \my\.\file\file.txt
\hadoop.txt

3. It will throw error : java.nio.file.InvalidPathException: UNC path is missing sharename:
4. java.nio.file.InvalidPathException: UNC path is missing sharename: //hadoop.txt/



Question : Which of the following can be a valid syntax for , resource bundle property files ?





 : Which of the following can be a valid syntax for , resource bundle property files ?
1. Key:value

2. Key=value

3. Key==value

4. Key;value





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

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 allSites = Arrays.asList("HadoopExam", "QuickTechie", "Training4Exam");
Predicate predicate = site -> {
System.out.println("Watching Hadoop Training Course ...");
return site.contains("Hadoop");
};
allSites.stream().filter(siteName -> siteName.length() > 3).allMatch(predicate);
}
}



 : You have been given below code, what is the behavior expected?
1. It will print Watching Hadoop Training Course ...

2. It will print
Watching Hadoop Training Course ...
Watching Hadoop Training Course ...

3. It will print
Watching Hadoop Training Course ...
Watching Hadoop Training Course ...
Watching Hadoop Training Course ...

4. There will be a compile time error.