โ† 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 describes an 'effectively final' variable in the context of lambda capture?

    Answer: A variable whose value is never changed after its initial assignment

    Effectively final means a variable that could have been declared final because it is never reassigned after initialization, even without the explicit final keyword.

  2. What is the difference between a lambda expression and an anonymous class instance in Java?

    Answer: Lambdas do not introduce a new scope for 'this'; anonymous classes do.

    Inside a lambda, 'this' refers to the enclosing instance; inside an anonymous class, 'this' refers to the anonymous class instance itself.

  3. Which built-in functional interface accepts an int and returns an int without boxing?

    Answer: IntUnaryOperator

    IntUnaryOperator's applyAsInt(int) method accepts and returns a primitive int, avoiding autoboxing overhead.

  4. Given: BiFunction f = (s, n) -> s.repeat(n); what does f.apply("ab", 3) return?

    Answer: ababab

    String.repeat(n) repeats the string n times, so "ab".repeat(3) returns "ababab".

  5. What is printed by: Supplier s = Math::random; System.out.println(s.get() == s.get());

    Answer: true or false depending on random values

    Each call to s.get() invokes Math.random() independently, so the two values are extremely unlikely to be equal but could theoretically be.

  6. Which of the following correctly chains a lambda to transform a stream element and then filter it?

    Answer: Both A and B are valid but produce different results when filter precedes map

    Both chains are valid Java, but applying filter before or after map can yield different elements because the predicate tests different values in each ordering.

  7. In a lambda used with Optional.map(), what does the lambda receive and return?

    Answer: It receives the unwrapped value and returns a new value; Optional.map wraps the result.

    Optional.map(Function) passes the contained value to the function and wraps the returned value in a new Optional; the lambda itself does not deal with Optional directly.