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());
Intermediate (Non-Terminal) operations
- these return a stream and allow chaining.
- they are lazy : they don’t execute until a terminal operation is called .
Example :
- filter(Predicate<T>)
- map(Function<T,R>)
- flatMap(Function<T,stream<R>>)
- sorted()
- sorted(Comperator<T>)
- distinct()
- peek(Consumer<T>)
- limit(long n)
- skip(long n)
- peek(Consumer<T>)
Terminal operations
- collect(Collectors)
- forEach(Consumer<T>)
- reduce(Binaryoperator<T>)
- count()
- min(Comperator)
- max(Comperator)
- anyMatch()
- allMatch()
- findFirst()
- findAny()
- The introduction of the new TE244 Series expands TSC Auto ID's growing line of high-performance desktop-class label printers ; Dual-motor gear driven design
6. Method References
- Method Reference is a shorthand (shortcut) notation of writing lambda expressions when your lambda is only calling an existing method.
list.forEach(System.out::println);
7. Optional Class
Optional<T>is a Java 8 container class used to avoidNullPointerExceptionand write cleaner, safer code.It represents a value that may or may not be present.
Optional<String> name = Optional.of("Java");
8. New Date and Time API (java.time package)
- Better date/time handling with immutable objects.
- This replaced the old, confusing classes like
Date,Calendar, andSimpleDateFormat.
Old API problems:
- Not thread-safe (
SimpleDateFormat) - Poor design (
Datestarts at 1900, months start at 0) - Difficult to handle time zones
- Modifying dates was hard
New API advantages:
- Immutable
- Thread-safe
- Easy to use
- Clear date/time manipulation
- Better time zone support
LocalDate date = LocalDate.now();
- Premium 70gsm Thermal Paper: Crafted with high-quality 70gsm direct thermal paper, ensuring crisp and clear printouts. No need for ink or toner, making it cost-effective and efficient for long-term use
- Reliable Adhesion: Equipped with a strong adhesive backing that ensures a secure bond to various surfaces, including packages, boxes, envelopes, and more.
9. Collectors Class
- Used to collect data processed by streams into lists, sets, maps, etc.
- The
Collectorsclass provides predefined collector methods used with thecollect()terminal operation of a Stream.
Commonly Used Collectors Methods Are .
1.Collect to List
Collectors.toList() is used with the Stream API to convert a stream of elements back into a List. stream → processing → List
List<String> list = names.stream()
.collect(Collectors.toList());
2.Collect to Set
Collectors.toSet() is used to collect stream results into a Set, which:
- Removes duplicates
- Has no guaranteed order
- Provides faster lookup (HashSet)
Set<String> set = names.stream()
.collect(Collectors.toSet());
3.Collect to Map
Collectors.toMap() is used to convert a stream into a Map<K, V> .
Map<Integer, String> map = employees.stream()
.collect(Collectors.toMap(emp -> emp.getId(), emp -> emp.getName()));
4.Joining Strings
Collectors.joining() is used with Streams to concatenate strings with:
- No delimiter
- A delimiter (
,, space,|, etc.) - Optional prefix
- Optional suffix
String result = names.stream()
.collect(Collectors.joining(", "));
5.Counting Elements
Collectors.counting() is a collector that returns the number of elements processed in the stream.
long count = names.stream()
.collect(Collectors.counting());
6.Summing Integer/Double
It is a collector that adds (sums) integer values extracted from objects.
int totalAge = employees.stream()
.collect(Collectors.summingInt(emp -> emp.getAge()));
7.Average
Collectors.averagingInt(), averagingLong(), and averagingDouble() are used to compute the average value of numeric fields in a collection.
double avgAge = employees.stream()
.collect(Collectors.averagingInt(emp -> emp.getAge()));
8.Finding Max / Min
- It is used to find the maximum element in a stream using a Comparator.
- It is used to find the minimum element in a stream using a Comparator.
Optional<Employee> maxSalaryEmp =
employees.stream()
.collect(Collectors.maxBy(Comparator.comparing(Employee::getSalary)));
9.Grouping
It is one of the most powerful collectors used to group data based on a specific key—like SQL GROUP BY.
Map<String, List<Employee>> group =
employees.stream()
.collect(Collectors.groupingBy(Employee::getDepartment));
10.Partitioning
partitioningBy() divides a stream into two groups based on a boolean condition:
- true group
- false group
Map<Boolean, List<Employee>> map =
employees.stream()
.collect(Collectors.partitioningBy(e -> e.getSalary() > 50000));
10. ForEach() Method
- Added in the
Iterableinterface for iterating elements easily.
list.forEach(item -> System.out.println(item));


