Question 1

Given:
java
Optional<String> optionalName = Optional.ofNullable(null);
String bread = optionalName.orElse("Baguette");
System.out.print("bread:" + bread);
String dish = optionalName.orElseGet(() -> "Frog legs");
System.out.print(", dish:" + dish);
try {
String cheese = optionalName.orElseThrow(() -> new Exception());
System.out.println(", cheese:" + cheese);
} catch (Exception exc) {
System.out.println(", no cheese.");
}
What is printed?
  • Question 2

    Which of the following statements is correct about a final class?
  • Question 3

    Given:
    java
    DoubleSummaryStatistics stats1 = new DoubleSummaryStatistics();
    stats1.accept(4.5);
    stats1.accept(6.0);
    DoubleSummaryStatistics stats2 = new DoubleSummaryStatistics();
    stats2.accept(3.0);
    stats2.accept(8.5);
    stats1.combine(stats2);
    System.out.println("Sum: " + stats1.getSum() + ", Max: " + stats1.getMax() + ", Avg: " + stats1.getAverage()); What is printed?
  • Question 4

    Given:
    java
    int post = 5;
    int pre = 5;
    int postResult = post++ + 10;
    int preResult = ++pre + 10;
    System.out.println("postResult: " + postResult +
    ", preResult: " + preResult +
    ", Final value of post: " + post +
    ", Final value of pre: " + pre);
    What is printed?
  • Question 5

    How would you create a ConcurrentHashMap configured to allow a maximum of 10 concurrent writer threads and an initial capacity of 42?
    Which of the following options meets this requirement?