What are the new features introduced in Java 8?

Java 8 was a major release that added functional programming support and several new APIs to the language, most notably lambda expressions, the Stream API, a new Date and Time API, and default/static methods on interfaces.

Key Points: • Lambda expressions introduced concise, inline implementations of functional interfaces, reducing anonymous-class boilerplate. • The Stream API (java.util.stream) added a declarative way to filter, map, sort, and aggregate collections, with easy parallelization via parallelStream(). • The new java.time package (LocalDate, LocalDateTime, LocalTime, Duration, Period) replaced the error-prone, mutable java.util.Date and Calendar classes with an immutable, thread-safe design. • Default and static methods in interfaces let the JDK evolve interfaces like Collection without breaking existing implementations. • Optional<T> was added to represent possibly-absent values more safely than returning null, and the java.util.function package introduced standard functional interfaces like Function, Predicate, Consumer, and Supplier.

Example: Where Java 7 code needed a Calendar and nested null checks, Java 8 code can use LocalDate.now().plusDays(5) for dates and Optional.ofNullable(value).orElse(defaultValue) for null-safety, both far more concise and less error-prone.

Interview Tip: A concise interview answer is:

"The headline features are lambda expressions and the Stream API for functional-style, declarative code; a new immutable Date and Time API to replace the old Date and Calendar classes; default and static methods on interfaces; and Optional for expressing possibly-missing values more safely than null. Together they modernized how Java handles collections, dates, and null-safety."