Java 8 is the most awaited release of Java programming language development because, in the entire history of Java, it never release that many major features. It consists of major features of Java. It is a new version of Java and was released by Oracle on 18 March 2014. Java provided support for functional programming, new Java 8 APIs, a new JavaScript engine, new Java 8 streaming API, functional interfaces, default methods, date-time API changes, etc.
This Tutorial covers all the important Java 8 features like Java 8 APIs, Java arrays, Java 8 ArrayList, and many more included in Java 8 programming language.
Java 8 Features
- Lambda Expressions
- Functional Interfaces
- Method Reference
- Streams
- Comparable and Comparator
- Optional Class
- Date/Time API
- Miscellaneous
Lambda Expressions
Lambda Expression basically expresses an instance of the functional interface, in other words, you can say it provides a clear and concise way to represent a method of the functional interface using an expression. Lambda Expressions are added in Java 8.
- Lambda Expressions in Java 8
- Lambda Expressions Parameters
- Java Lambda Expression with Collections
- Lambda Expression Variable Capturing with Examples
- How to Create Thread using Lambda Expressions in Java?
- Serialization of Lambda Expression in Java
- Block Lambda Expressions in Java
- Match Lambdas to Interfaces in Java
- Converting ArrayList to HashMap in Java 8 using a Lambda Expression
- Check if a String Contains Only Alphabets in Java Using Lambda Expression
- Remove Elements From a List that Satisfy a Given Predicate in Java
Functional Interfaces
An interface that contains only one abstract method is known as a functional interface, but there is no restriction, you can have n number of default and static methods inside a functional interface.
- Functional Interfaces in Java
- Consumer Interface in Java with Examples
- BiConsumer Interface in Java with Examples
- Predicate Interface with Examples
- Function Interface in Java with Examples
- Supplier Interface in Java with Examples
Method Reference
Method reference is a shorthand notation of a lambda expression to call a method. There are four types of method references that are as follows:
- Static Method Reference
- Instance Method Reference of a particular object
- Instance Method Reference of an arbitrary object of a particular type
- Constructor Reference.
Example:
numList.stream().filter(n -> n > 5).sorted().forEach(System.out::println);
- Method References in Java with examples
- Converting ArrayList to HashMap using Method Reference in Java 8
Streams
Stream API is introduced in Java 8 and is used to process collections of objects with the functional style of coding using the lambda expression. So to understand what stream API is, you must have knowledge of both lambda and functional interfaces.
- Java 8 Stream
- Difference Between Streams and Collections in Java
- Implement Filter Function using Reduce in Java 8 Streams
- Java Stream API – Filters
- Parallel vs Sequential Stream in Java
- Functional Programming in Java 8+ using the Stream API with Example
- Intermediate Methods of Stream in Java
- Difference Between map() And flatMap() In Java Stream
- Array to Stream in Java
- 10 Ways to Create a Stream in Java
- How to Print Elements of a Stream in Java 8
- Collecting a Stream to an Immutable Collection in Java
- Comparing Streams to Loops in Java
- Why You Need to Close the Java Streams in Finally Block?
- Convert an Iterable to Stream in Java
- Convert an Iterator to Stream in Java
- Difference Between Stream.of() and Arrays.stream() method in Java
- Convert Stream to Set in Java
- Convert a Set to Stream in Java
- Streams on Arrays in Java 8
Java Stream Programs
- Program to Convert a Map to a Stream in Java
- Program to Convert Boxed Array to Stream in Java
- Program to Convert Primitive Array to Stream in Java
- Program to Convert a Set to Stream in Java using Generics
- Program to Convert List to Stream in Java
- Program to Convert Stream to an Array in Java
- How to get Slice of a Stream in Java
- Flattening Nested Collections in Java
- How to Convert a Stream into a Map in Java
- Find the First Element of a Stream in Java
- Find the Last Element of a Stream in Java
- How to Find Duplicate Elements in a Stream in Java
- Count the Occurrence of a Given Character in a String Using Stream API in Java
- Reverse Elements of a Parallel Stream in Java
- How to Get ArrayList From Stream in Java 8
- Generate Infinite Stream of Double in Java
- Generate Infinite Stream of Integers in Java
- Program to Iterate over a Stream with Indices in Java 8
- Flatten a Stream of Arrays in Java using forEach loop
- Flatten a Stream of Lists in Java using forEach loop
- Flatten a Stream of Map in Java using forEach loop
- Convert a String to a List of Characters in Java
- Initialize a List in a Single Line with a Specified Value using Java Stream
Java Stream Methods
- Stream forEach() method in Java with Examples
- Stream forEachOrdered() Method in Java with Examples
- foreach() loop vs Stream foreach() vs Parallel Stream foreach()
- Stream of() method in Java
- Java Stream findAny() with Examples
- Stream anyMatch() in Java with Examples
- Stream allMatch() in Java with Examples
- Stream filter() in Java with Examples
- Stream sorted (Comparator comparator) Method in Java
- Stream sorted() in Java
- Stream.distinct() in Java
- Stream.concat() in Java
- Stream.reduce() in Java with Examples
- stream.limit() method in Java
- Stream ofNullable(T) method in Java with Examples
- Stream dropWhile() method in Java with Examples
- Stream iterate(T,Predicate,UnaryOperator) Method in Java with Examples
- Stream takeWhile() method in Java with Examples
- concat() Method of Stream Interface in Java API
- Stream findFirst() in Java with Examples
- DoubleStream mapToObj() in Java
- Stream.Builder accept() Method in Java
- IntStream.Builder add() Method in Java
- DoubleStream.Builder build() in Java
- Stream.Builder build() in Java
- Collectors.joining() Method with Examples
- Stream builder() in Java with Examples
- Stream empty() in Java with Examples
- LongStream flatMap(LongFunction mapper) in Java
- LongStream filter() in Java with Examples
Comparable and Comparator
- Comparable vs Comparator in Java
- Comparator Interface in Java with Examples
- Why to Use Comparator Interface Rather than Comparable Interface in Java?
- Sort an Array of Triplet using Java Comparable and Comparator
- Java Program to Sort LinkedList using Comparable
- How to Sort HashSet Elements using Comparable Interface in Java?
- Sort LinkedHashMap by Values using Comparable Interface in Java
- Sort LinkedHashMap by Keys using Comparable Interface in Java
- How to Sort LinkedHashSet Elements using Comparable Interface in Java?
Optional Class
- Java 8 Optional Class
- Optional ofNullable() Method in Java with Examples
- Optional orElse() Method in Java with Examples
- Optional ifPresentOrElse() Method in Java with Examples
- Optional orElseGet() Method in Java with Examples
- Optional filter() Method in Java with Examples
- Optional empty() Method in Java with Examples
- Optional hashCode() Method in Java with Examples
- Optional toString() Method in Java with Examples
- Optional equals() Method in Java with Examples
- Optional stream() Method in Java with examples
- Optional or() Method in Java with Examples
- Optional get() Method in Java with Examples
- Optional isPresent() Method in Java with Examples
- Optional orElseThrow() Method in Java with Examples
- Optional of() method in Java with Examples
Date/Time API
- Date-Time API in Java 8
- java.time.LocalDate Class in Java
- java.time.LocalTime Class in Java
- java.time.LocalDateTime Class in Java
- java.time.MonthDay Class in Java
- java.time.OffsetTime Class in Java
- java.time.OffsetDateTime Class in Java
- java.time.Clock Class in Java
- java.time.ZonedDateTime Class in Java
- java.time.ZoneId Class in Java
- java.time.ZoneOffset Class in Java
- java.time.Year Class in Java
- java.time.YearMonth Class in Java
- java.time.Period Class in Java
- java.time.Duration Class in Java
- java.time.Instant Class in Java
- Java 8 Clock instant() method with Examples
- Java 8 Clock fixed() method with Examples
Miscellaneous
- Default Methods In Java 8
- Static method in Interface in Java
- Can We Override Default Method in Java?
- forEach() method in Java
- Nashorn JavaScript Engine in Java with Examples
- MetaSpace in Java 8 with Examples
- Java class dependency analyzer in Java 8 with Examples
- LongUnaryOperator Interface in Java
- IntUnaryOperator Interface in Java
- DoubleUnaryOperator Interface in Java
- UnaryOperator Interface in Java
- ObjLongConsumer Interface with Example
- ObjIntConsumer Interface with Example
- ObjDoubleConsumer Interface with Example
- DoubleSupplier Interface with Examples
- BooleanSupplier Interface with Examples
- IntSupplier Interface with Examples
- LongSupplier Interface with Examples
- LongConsumer Interface in Java with Examples
- DoubleConsumer Interface in Java with Examples
- IntConsumer Interface in Java with Examples
- LongFunction Interface in Java with Examples
- IntFunction Interface in Java with Examples
- ToDoubleFunction Interface in Java with Examples
- DoubleFunction Interface in Java with Examples
- ToIntFunction Interface in Java with Examples
- LongToIntFunction Interface in Java with Examples
- ToLongFunction Interface in Java with Examples
- LongToDoubleFunction Interface in Java with Examples
- ToLongBiFunction Interface in Java with Examples
- ToIntBiFunction Interface in Java with Examples
- ToDoubleBiFunction Interface in Java with Examples
- DoubleToLongFunction Interface in Java with Examples
- IntToDoubleFunction Interface in Java with Examples
- IntToLongFunction Interface in Java with Examples
- DoubleToIntFunction Interface in Java with Example
- ArrayDeque removeIf() method in Java with Examples
FAQs on Java 8
Q1: What are the features of java8?
- default and static methods
- Functional Interfaces and Lambda Expressions
- Collection API
- Java Time API
- forEach() method
- Concurrency API
- Java Stream API
Q2: What advantages does Java 8 bring?
- Code is more concise and readable
- Code is more reusable
- Code is more testable and maintainable
- Code is now both callable and concurrent
- Users can write parallel code
- Users can write database-like operations
- Applications now perform better
- Code is far more productive
Q3: What is a functional interface?
A functional interface is an interface that contains just one abstract method.
Q4: How are functional interfaces and Lambda Expressions related?
Lambda expressions are applied only to the functional interface’s abstract method.