Java 8 — Core Features
The Java release that introduced lambdas, streams, default methods, and the modern date/time API
1. Why Java 8 matters
Java 8 changed everyday Java programming by adding functional-style programming constructs while keeping the
object-oriented model. The most important features are lambda expressions, functional interfaces, Stream API, method
references, Optional, default/static interface methods, and [Link].
2. Lambda expressions
Lambdas let you pass behavior as a value through functional interfaces.
Predicate<Integer> even = n -> n % 2 == 0;
[Link]([Link](10));
3. Stream API
Streams provide declarative operations over data sources such as collections. Common operations include filter, map,
flatMap, sorted, distinct, limit, reduce, collect, and toList.
List<String> result = [Link]()
.filter(n -> [Link]() > 3)
.map(String::toUpperCase)
.sorted()
.toList();
4. Optional
Optional represents a value that may be present or absent. It is useful for making absence explicit, especially in return
values.
Optional<User> user = [Link](id);
[Link](u -> [Link]([Link]()));
String name = [Link](User::getName)
.orElse("Unknown");
Optional is not a universal replacement for null. Avoid blindly using Optional for every field or parameter.
5. Default and static interface methods
Interfaces can contain default method implementations and static methods. This allowed Java to evolve interfaces
while reducing the need to break existing implementations.
interface Vehicle {
default void start() {
[Link]("Starting");
}
static boolean validSpeed(int speed) {
return speed >= 0;
}
}
6. [Link]
Java 8 introduced the [Link] API, which is generally preferred over the older Date/Calendar APIs.
LocalDate — date without time zone.
LocalTime — time without date/time zone.
LocalDateTime — date and time without a zone.
Instant — point on the UTC timeline.
ZonedDateTime — date/time with a time zone.
Duration — time-based amount; Period — date-based amount.
LocalDate today = [Link]();
LocalDate nextWeek = [Link](1);
Instant now = [Link]();
7. CompletableFuture
CompletableFuture supports asynchronous composition and callbacks. It is especially useful when independent or
sequential asynchronous tasks need to be combined.
[Link](() -> loadUser())
.thenApply(User::getName)
.thenAccept([Link]::println);
8. Java 8 interview checklist
Know functional interfaces and why a lambda needs a target type.
Know map vs filter vs flatMap.
Know intermediate vs terminal stream operations.
Know Optional's purpose and limitations.
Know LocalDate/Instant/ZonedDateTime differences.
Know default interface methods and method references.