Question 26

Given:
java
Runnable task1 = () -> System.out.println("Executing Task-1");
Callable<String> task2 = () -> {
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"?
  • Question 27

    Given:
    java
    StringBuffer us = new StringBuffer("US");
    StringBuffer uk = new StringBuffer("UK");
    Stream<StringBuffer> stream = Stream.of(us, uk);
    String output = stream.collect(Collectors.joining("-", "=", ""));
    System.out.println(output);
    What is the given code fragment's output?
  • Question 28

    Given:
    java
    List<String> frenchAuthors = new ArrayList<>();
    frenchAuthors.add("Victor Hugo");
    frenchAuthors.add("Gustave Flaubert");
    Which compiles?
  • Question 29

    Given:
    java
    var lyrics = """
    Quand il me prend dans ses bras
    Qu'il me parle tout bas
    Je vois la vie en rose
    """;
    for ( int i = 0, int j = 3; i < j; i++ ) {
    System.out.println( lyrics.lines()
    .toList()
    .get( i ) );
    }
    What is printed?
  • Question 30

    Given:
    java
    List<Integer> integers = List.of(0, 1, 2);
    integers.stream()
    .peek(System.out::print)
    .limit(2)
    .forEach(i -> {});
    What is the output of the given code fragment?