Junior — Middle
What new features and capabilities were added in Java 8?
sobes.tech AI
Answer from AI
Java 8 introduced several key innovations that significantly expanded the capabilities of the language and platform:
- Lambda expressions — allow writing concise functional code, for example, for processing collections.
- Stream API — a convenient way to work with data collections, supporting filtering, transformation, aggregation, and parallel processing.
- Interfaces with default methods — enable adding new methods to interfaces without breaking existing implementations.
- New date and time API (java.time) — more convenient and safer compared to the outdated Date and Calendar.
- Optional — a class for handling the possible absence of a value, helping to avoid NullPointerException.
- Methods for repeated annotations — the ability to use the same annotation multiple times on a single element.
- Reflection methods for annotations — improvements in working with annotations.
Example of using lambda and Stream API:
List<String> names = Arrays.asList("Anna", "Bob", "Charlie");
List<String> filtered = names.stream()
.filter(name -> name.startsWith("A"))
.collect(Collectors.toList());