A lambda expression is a way to represent a functional interface (an interface with a single abstract method) as a block of code that can be passed around as a method argument or stored in a variable. It enables functional programming in Java.
What is the difference between a lambda expression and an anonymous inner class in Java 8?
An anonymous inner class is a class that is defined and instantiated in the same place, usually as an argument to a method. A lambda expression is a more concise way to represent a functional interface, and does not create an additional class.
What is a functional interface in Java 8?
A functional interface is an interface that has only one abstract method. In Java 8, functional interfaces are used as the basis for lambda expressions and method references.
What are the new features in the Date and Time API in Java 8?
The new Date and Time API in Java 8 includes classes such as LocalDate, LocalTime, and LocalDateTime to represent dates, times, and date-times without a time-zone. The API also includes classes such as ZonedDateTime to represent date-times with a time-zone and Duration to represent a duration of time.
What is the Stream API in Java 8?
The Stream API is a new feature in Java 8 that allows for functional-style operations on collections of elements, such as filtering, mapping, and reducing. It also allows for parallel processing of streams on multi-core architectures.
What are the new features in the Optional class in Java 8?
The Optional class in Java 8 is a container object which may or may not contain a non-null value. The class has several new methods like isPresent(), ifPresent(), filter(), map() and flatMap() which can be used for handling null values more effectively.
What is the new forEach() method in the Iterable interface in Java 8?
The forEach() method is a new method in the Iterable interface in Java 8 that allows for a more functional-style iteration over collections of elements. It takes a lambda expression as an argument and applies it to each element in the collection.
What is the new method reference feature in Java 8?
Method reference is a feature in Java 8 that allows a method to be passed as an argument to a functional interface. It is a more concise way to pass a method as an argument, and can be used in conjunction with lambda expressions.
What is the new default method feature in Java 8?
Default method is a new feature in Java 8 that allows interfaces to have default implementations for their methods. This allows for more flexibility in extending and implementing interfaces, and allows for the addition of new methods to interfaces without breaking existing code.
What is the new Base64 class in Java 8?
The Base64 class is a new class in Java 8 that provides a Base64 encoding and decoding as defined by RFC 4648. It can be used for a variety of purposes, such as simple data encoding, to help protect data from unauthorized access and providing data integrity.