01. Which interface in the java.util.function package can return a primitive type?
a) ToDoubleFunction
b) Supplier
c) BiFunction
d) LongConsumer
02. Which two statements independently compile?
(Choose two.)
a) List<? super Short> list = new ArrayList<Number>();
b) List<? super Number> list = new ArrayList<Integer>();
c) List<? extends Number> list = new ArrayList<Byte>();
d) List<? extends Number> list = new ArrayList<Object>();
e) Listlist = new ArrayList();
03. Given the code fragment:
10. var lst = List.of(1, 2, 3, 4);
11. lst.replaceAll(x -> x + 100);
12. System.out.println(“-Completed-”);
Which action enables to print -Completed-?
a) Replacing line 10, with List<Integer> lst = List.of(1,2,3,4);
b) Replacing line 11, with lst.replaceAll(x = x + 100);
c) Replacing line 10, with var lst = Arrays.asList(1, 2, 3, 4);
d) Replacing line 11, with lst.forEach(x -> x + 100);
04. var numbers = List.of(0,1,2,3,4,5,6,7,8,9); You want to calculate the average of numbers. Which two codes will accomplish this?
(Choose two.)
a) double avg = numbers.stream().parallel().averagingDouble(a −> a);
b) double avg = numbers.parallelStream().mapToInt (m −> m).average().getAsDouble();
c) double avg = numbers.stream().mapToInt (i −> i).average().parallel();
d) double avg = numbers.stream().average().getAsDouble();
05. Given the code fragment:
Stream<Integer> numStream = Stream.of(10, 20, 30);
numStream.map(n -> n + 10).peek(s -> System.out.print(s));
numStream.forEach(s -> System.out.println(s));
What it the result?
a) 203040
102030
b) 102030
203040
c) 102030
102030
d) An exception is thrown at runtime.
06. Which code fragment does a service use to load the service provider with a Print interface?
a) private Print print = com.service.Provider.getInstance();
b) private java.util.ServiceLoader loader = ServiceLoader.load(Print.class);
c) private java.util.ServiceLoader loader = new java.util.ServiceLoader<>();
d) private Print print = new com.service.Provider.PrintImpl();
07. Which two are guidelines for preventing denial of service attacks?
a) Release resources in all cases.
b) Resource limit checks should not suffer from numeric overflow.
c) Purge sensitive information from exceptions.
d) Validate file formats before processing untrusted files.
e) Make public static fields final.
f) Use mutable classes whenever possible.
08. Given these named modular JARs and their module-info java files order.jar:
module order {
requires product;
exports com.oracle.order;
}
product.jar:
module product {
exports com.oracle.product;
}
Which is the only possible result of executing the command jdeps -s order.jar product.jar?
a) order -> java.
baseorder -> product
product -> java.base
b) order -> product
c) product -> order
d) java.base -> product
java.base -> order
product -> order
09. Which two statements set the default locale used for formatting numbers, currency, and percentages?
(Choose two.)
a) Locale.setDefault(Locale.Category.FORMAT, “zh-CN”);
b) Locale.setDefault(Locale.Category.FORMAT, Locale.CANADA_FRENCH);
c) Locale.setDefault(Locale.SIMPLIFIED_CHINESE);
d) Locale.setDefault(“en_CA”);
e) Locale.setDefault(“es”, Locale.US);
10. Given:
public class Client {
static void doCalc(byte... a) {
System.out.print("byte...");
}
static void doCalc(long a, long b) {
System.out.print("long, long");
}
static void doCalc(Byte s1, Byte s2) {
System.out.print("Byte, Byte");
}
public static void main (String[] args) {
byte b = 5;
doCalc(b, b);
}
}
a) byte…
b) long, long
c) Byte, Byte
d) compilation error