Given:
java
final Stream
Files.readAllLines(Paths.get("orders.csv"));
strings.skip(1)
.limit(2)
.forEach(System.out::println);
And that the orders.csv file contains:
mathematica
OrderID,Customer,Product,Quantity,Price
1,Kylian Mbappé,Keyboard,2,25.50
2,Teddy Riner,Mouse,1,15.99
3,Sebastien Loeb,Monitor,1,199.99
4,Antoine Griezmann,Headset,3,45.00
What is printed?
Given:
java
var hauteCouture = new String[]{ "Chanel", "Dior", "Louis Vuitton" };
var i = 0;
do {
System.out.print(hauteCouture[i] + " ");
} while (i++ > 0);
What is printed?
Given:
java
Optional o1 = Optional.empty();
Optional o2 = Optional.of(1);
Optional o3 = Stream.of(o1, o2)
.filter(Optional::isPresent)
.findAny()
.flatMap(o -> o);
System.out.println(o3.orElse(2));
What is the given code fragment's output?
Given:
java
Runnable task1 = () -> System.out.println("Executing Task-1");
Callable
System.out.println("Executing Task-2");
return "Task-2 Finish.";
};
ExecutorService execService = Executors.newCachedThreadPool();
// INSERT CODE HERE
execService.awaitTermination(3, TimeUnit.SECONDS);
execService.shutdownNow();
Which of the following statements, inserted in the code above, printsboth:
"Executing Task-2" and "Executing Task-1"?
Given:
java
StringBuilder result = Stream.of("a", "b")
.collect(
() -> new StringBuilder("c"),
StringBuilder::append,
(a, b) -> b.append(a)
);
System.out.println(result);
What is the output of the given code fragment?
Given:
java
System.out.print(Boolean.logicalAnd(1 == 1, 2 < 1));
System.out.print(Boolean.logicalOr(1 == 1, 2 < 1));
System.out.print(Boolean.logicalXor(1 == 1, 2 < 1));
What is printed?
You are working on a module named perfumery.shop that depends on another module named perfumery.provider.
The perfumery.shop module should also make its package perfumery.shop.eaudeparfum available to other modules.
Which of the following is the correct file to declare the perfumery.shop module?
Given:
java
var now = LocalDate.now();
var format1 = new DateTimeFormatter(ISO_WEEK_DATE);
var format2 = DateTimeFormatter.ISO_WEEK_DATE;
var format3 = new DateFormat(WEEK_OF_YEAR_FIELD);
var format4 = DateFormat.getDateInstance(WEEK_OF_YEAR_FIELD);
System.out.println(now.format(REPLACE_HERE));
Which variable prints 2025-W01-2 (present-day is 12/31/2024)?
Given:
java
List
integers.stream()
.peek(System.out::print)
.limit(2)
.forEach(i -> {});
What is the output of the given code fragment?
Given:
java
public static void main(String[] args) {
try {
throw new IOException();
} catch (IOException e) {
throw new RuntimeException();
} finally {
throw new ArithmeticException();
}
}
What is the output?
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?
Given:
java
try (FileOutputStream fos = new FileOutputStream("t.tmp");
ObjectOutputStream oos = new ObjectOutputStream(fos)) {
fos.write("Today");
fos.writeObject("Today");
oos.write("Today");
oos.writeObject("Today");
} catch (Exception ex) {
// handle exception
}
Which statement compiles?
Given:
java
public class ThisCalls {
public ThisCalls() {
this(true);
}
public ThisCalls(boolean flag) {
this();
}
}
Which statement is correct?
Given:
java
CopyOnWriteArrayList
list.add("A");
list.add("B");
list.add("C");
// Writing in one thread
new Thread(() -> {
list.add("D");
System.out.println("Element added: D");
}).start();
// Reading in another thread
new Thread(() -> {
for (String element : list) {
System.out.println("Read element: " + element);
}
}).start();
What is printed?
Given:
java
List
frenchAuthors.add("Victor Hugo");
frenchAuthors.add("Gustave Flaubert");
Which compiles?
Given:
java
Object input = 42;
String result = switch (input) {
case String s -> "It's a string with value: " + s;
case Double d -> "It's a double with value: " + d;
case Integer i -> "It's an integer with value: " + i;
};
System.out.println(result);
What is printed?
Given:
java
String textBlock = """
j \
a \t
v \s
a \
""";
System.out.println(textBlock.length());
What is the output?
Given:
java
List
abc.stream()
.forEach(x -> {
x = x.toUpperCase();
});
abc.stream()
.forEach(System.out::print);
What is the output?
What do the following print?
java
public class DefaultAndStaticMethods {
public static void main(String[] args) {
WithStaticMethod.print();
}
}
interface WithDefaultMethod {
default void print() {
System.out.print("default");
}
}
interface WithStaticMethod extends WithDefaultMethod {
static void print() {
System.out.print("static");
}
}