Oracle Java SE 21 Developer Professional Sample Questions:
1. Given:
java
String colors = "red\n" +
"green\n" +
"blue\n";
Which text block can replace the above code?
A) None of the propositions
B) java
String colors = """
red \
green\
blue \
""";
C) java
String colors = """
red \s
green\s
blue \s
""";
D) java
String colors = """
red \t
green\t
blue \t
""";
E) java
String colors = """
red
green
blue
""";
2. Given:
java
Period p = Period.between(
LocalDate.of(2023, Month.MAY, 4),
LocalDate.of(2024, Month.MAY, 4));
System.out.println(p);
Duration d = Duration.between(
LocalDate.of(2023, Month.MAY, 4),
LocalDate.of(2024, Month.MAY, 4));
System.out.println(d);
What is the output?
A) P1Y
UnsupportedTemporalTypeException
B) P1Y
PT8784H
C) UnsupportedTemporalTypeException
D) PT8784H
P1Y
3. Given:
java
Object myVar = 0;
String print = switch (myVar) {
case int i -> "integer";
case long l -> "long";
case String s -> "string";
default -> "";
};
System.out.println(print);
What is printed?
A) integer
B) Compilation fails.
C) string
D) It throws an exception at runtime.
E) nothing
F) long
4. Which of the following isn't a valid option of the jdeps command?
A) --check-deps
B) --generate-module-info
C) --list-deps
D) --print-module-deps
E) --list-reduced-deps
F) --generate-open-module
5. Which two of the following aren't the correct ways to create a Stream?
A) Stream<String> stream = Stream.builder().add("a").build();
B) Stream stream = Stream.ofNullable("a");
C) Stream stream = Stream.of("a");
D) Stream stream = new Stream();
E) Stream stream = Stream.empty();
F) Stream stream = Stream.generate(() -> "a");
G) Stream stream = Stream.of();
Solutions:
| Question # 1 Answer: E | Question # 2 Answer: A | Question # 3 Answer: B | Question # 4 Answer: A | Question # 5 Answer: A,D |
We're so confident of our products that we provide no hassle product exchange.


By Edwina

