λ Lambdas & Functional Java
11 Java concepts, each explained step by step with real code, a common trap and practice questions.
- Lambda syntax(a, b) -> a + b, block bodies, type inference from the target.
- Core functional interfacesFunction, Predicate, Consumer, Supplier, BiFunction, UnaryOperator, BinaryOperator.
- Primitive functional interfacesIntPredicate, ToIntFunction… avoid boxing.
- Method referencesStatic, bound instance, unbound instance and constructor references.
- Effectively final captureLambdas can only capture locals that are never reassigned.
- this in lambdas vs anonymous classesA lambda's this is the enclosing instance.
- Composing functionsandThen, compose, Predicate.and/or/negate, Function.identity.
- OptionalRepresenting absence: map, flatMap, orElse vs orElseGet, orElseThrow; not for fields or parameters.
- Checked exceptions in lambdasStandard functional interfaces cannot throw checked exceptions.
- Higher-order functionsMethods that take or return functions; strategy via lambdas.
- Comparator with lambdasComparator.comparing, nullsFirst, chaining.