← All 1Z0-819 Flashcard Decks

Lambda Expressions Flashcards

7 cards from real 1Z0-819 practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.

Read the first 7 Lambda Expressions flashcards as text
  1. Which of the following lambda expressions is equivalent to the method reference Integer::parseInt?

    Answer: s -> Integer.parseInt(s)

    Integer::parseInt is a static method reference equivalent to the lambda s -> Integer.parseInt(s).

  2. A lambda that takes no arguments and returns void corresponds to which functional interface?

    Answer: Runnable

    Runnable's run() method takes no parameters and returns void, making it the natural fit for () -> { ... } style lambdas.

  3. What does Function.identity() return?

    Answer: A function that returns its input argument unchanged

    Function.identity() returns a Function that always returns its input argument (t -> t).

  4. Given: Predicate isEven = n -> n % 2 == 0; Predicate isPositive = n -> n > 0; which call correctly creates a predicate for even AND positive numbers?

    Answer: isEven.and(isPositive)

    Predicate.and() returns a composed predicate that represents a short-circuit logical AND of both predicates.

  5. Which of the following is TRUE about serializing lambda expressions in Java?

    Answer: Lambdas are serializable only if the target functional interface extends Serializable.

    A lambda is serializable if and only if its target type (the functional interface) extends java.io.Serializable.

  6. What is the output of: List.of("a","bb","ccc").stream().filter(s -> s.length() > 1).count();

    Answer: 2

    filter keeps "bb" and "ccc" (lengths 2 and 3, both > 1), so count() returns 2.

  7. When using a lambda to implement an interface with a throws clause on the abstract method, what must the lambda body do?

    Answer: Handle or propagate only checked exceptions declared by the functional interface method

    The lambda body can throw checked exceptions only if the functional interface's abstract method declares them; otherwise only unchecked exceptions are permitted.