FlashKeepers

Java · College · College and University

Java IV: Lambdas and Streams

Functional interfaces, lambda syntax, method references, Optional, and the Stream API with map, filter, reduce and collectors.

About this set

40 basic cards for College Java. Set 4 of 6 in Java. It opens with "What is a functional interface in Java?" and "What does the @FunctionalInterface annotation do?". Study it alongside the other College sets below.

40 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

What is a functional interface in Java?
Show answerAn interface with exactly one abstract method, used as the target type for lambda expressions and method references.
What does the @FunctionalInterface annotation do?
Show answerIt marks an interface as functional and causes a compile error if the interface violates the single abstract method rule.
What is the Single Abstract Method (SAM) rule?
Show answerA functional interface must have exactly one abstract method; default and static methods do not count.
Can a functional interface have default or static methods?
Show answerYes, it can have any number of default and static methods; only the count of abstract methods matters.
What does the Function<T,R> functional interface represent?
Show answerA function that takes a parameter of type T and returns a result of type R.
What is the basic syntax of a lambda expression?
Show answer(parameters) -> body, where parameters are the inputs and body is the expression or statement block.
How do you write a lambda with zero parameters?
Show answer() -> expression or () -> { statements; }, using empty parentheses.
How do you write a lambda with a single parameter without explicit type?
Show answerx -> expression, omitting the parentheses when there is exactly one parameter and no type is declared.
How do you write a lambda with multiple parameters?
Show answer(x, y) -> expression or (x, y) -> { statements; }, with parentheses around multiple parameters.
What is type inference in lambda expressions?
Show answerThe compiler deduces parameter types from the context, so you can omit explicit types like (String x) -> x.length().
How do you write a multi-statement lambda?
Show answer(params) -> { statement1; statement2; return result; }, using curly braces and explicit return statement.
What is variable capture in lambdas?
Show answerA lambda can access and use variables from its enclosing scope (captured variables).
Why must captured local variables be final or effectively final?
Show answerTo ensure thread safety and prevent unexpected behavior; if a variable could change, the lambda's behavior would be unpredictable.
What are method references?
Show answerA shorthand for lambdas that call a single existing method, using the syntax ClassName::methodName.
What is the syntax for a static method reference?
Show answerClassName::staticMethodName, for example String::valueOf or Math::abs.

25 more cards in the app

Study this set free