// Before Java 8 button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("Button clicked"); } }); // With Java 8 Lambda button.addActionListener(e -> System.out.println("Button clicked")); A powerful API for processing sequences of data using functional-style operations. Streams enable parallel processing with minimal effort.
public static void main(String[] args) { List<Employee> employees = Arrays.asList( new Employee("Alice", LocalDate.of(2018, 5, 10), 75000), new Employee("Bob", LocalDate.of(2020, 3, 15), 68000), new Employee("Charlie", LocalDate.of(2015, 11, 20), 95000) ); java se development kit 8
// Lambda + Stream API + Method Reference double averageSalary = employees.stream() .filter(e -> Period.between(e.hireDate(), LocalDate.now()).getYears() >= 3) .mapToDouble(Employee::salary) .average() .orElse(0.0); // Before Java 8 button