← All 1Z0-819 Flashcard Decks

Functional Interfaces 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 Functional Interfaces flashcards as text
  1. Which method reference form is used in `Arrays.sort(names, String::compareToIgnoreCase)`?

    Answer: Instance method reference on an arbitrary instance of a type

    String::compareToIgnoreCase is an instance method reference on an arbitrary instance — the first argument becomes the receiver of the method call.

  2. What functional interface does a constructor reference like `ArrayList::new` satisfy?

    Answer: Supplier

    ArrayList::new with no arguments matches Supplier because it takes no input and produces a new ArrayList instance.

  3. Given `Function f = Integer::parseInt;`, what kind of method reference is this?

    Answer: Static method reference

    Integer.parseInt is a static method, so Integer::parseInt is a static method reference.

  4. What does `Comparator.comparing(Person::getName)` return?

    Answer: A Comparator that orders persons by their name

    Comparator.comparing accepts a key extractor Function and returns a Comparator that orders by the extracted key's natural order.

  5. Which code correctly creates a Comparator that sorts strings by length, then alphabetically?

    Answer: Comparator.comparing(String::length).thenComparing(Comparator.naturalOrder())

    thenComparing chains a secondary Comparator used only when the primary comparison yields equal results.

  6. What does `Comparator.reversed()` do when chained with `Comparator.comparing(Person::getAge)`?

    Answer: Sorts by age in descending order

    reversed() returns a Comparator that imposes the reverse ordering of the original, yielding descending age sort.

  7. An interface has one abstract method and one default method. Can it be annotated with `@FunctionalInterface`?

    Answer: Yes — default methods do not count toward the single abstract method requirement

    @FunctionalInterface requires exactly one abstract method; default and static methods do not affect this count.