Java 1.
8 (Java 8) – Key Features & Concepts
1. Lambda Expressions
Enables writing anonymous functions (functional-style code).
Syntax: (parameters) -> expression
Example:
(a, b) -> a + b;
2. Functional Interfaces
Interfaces with only one abstract method.
Used with lambda expressions.
Marked with @FunctionalInterface.
Example:
@FunctionalInterface
interface MyFunc {
void execute();
}
3. Default & Static Methods in Interfaces
Interfaces can have method implementations.
default – for instance methods.
static – for utility/static methods.
4. Stream API
For processing collections in a functional style.
Supports filtering, mapping, reducing, etc.
Example:
list.stream().filter(x -> x > 10).forEach(System.out::println);
5. Method References
Shorthand for lambda expressions calling existing methods.
Syntax: ClassName::methodName
Example: System.out::println
6. Optional Class
Avoids NullPointerException.
Wraps potential null values.
Example:
Optional<String> name = Optional.ofNullable("John");
7. New Date & Time API (java.time)
Replaces old Date and Calendar classes.
Key classes:
o LocalDate
o LocalTime
o LocalDateTime
o ZonedDateTime
8. Collectors (in Stream API)
Used for collecting stream results into collections.
Example:
List<String> names = list.stream().collect(Collectors.toList());
9. Nashorn JavaScript Engine
Allows execution of JavaScript within Java applications.
ScriptEngine support.
10. PermGen Removed, Metaspace Introduced
PermGen memory space removed.
Replaced with Metaspace (automatically grows).