Java 8 Features
Java 8 was introduced to modernize Java by adding functional programming features, improving performance, and making the language more concise, readable, and expressive. It aimed to reduce boilerplate code, improve parallel processing, and enable more declarative coding styles—especially important for handling large data collections and multi-core processors.

Lambda Expressions
- Enables you to treat functionality as a method argument.
- Makes code concise and readable.
(List<String> list) -> list.size();
2. Functional Interfaces
- An interface with exactly one abstract method.
- Example:
Runnable
,Callable
,Comparator
,Function
@FunctionalInterface
interface MyFunc {
void execute();
}
3. Default Method in Interface
- Interfaces can have methods with default implementations.
interface MyInterface {
default void show() {
System.out.println("Default method");
}
}
4.Static Method in Interface
Interface MyInterface {
default void show() {
System.out.println("Default method");
}
}
5. Stream API
- For processing collections of objects.
- Supports functional-style operations:
map()
,filter()
,reduce()
,collect()
list.stream().filter(s -> s.startsWith("A")).collect(Collectors.toList());
6. Method References
- A shorthand for calling a method using
::
operator.
list.forEach(System.out::println);
7. Optional Class
- A container to avoid
NullPointerException
.
Optional<String> name = Optional.of("Java");
8. New Date and Time API (java.time package)
- Better date/time handling with immutable objects.
LocalDate date = LocalDate.now();
9. Collectors Class
- Used to collect data processed by streams into lists, sets, maps, etc.
List<String> names = list.stream().collect(Collectors.toList());
10. ForEach() Method
- Added in the
Iterable
interface for iterating elements easily.
list.forEach(item -> System.out.println(item));