Guide · Open source
How to use java8-tutorial: Learn Java 8 Lambdas and Streams
Updated · written with AI from the project's own documentation and checked against our catalogue data
The java8-tutorial repository by winterbe is a written guide, not a program, that walks through the new language and library features added in Java 8. Each section pairs a short explanation with small commented code samples. After working through it, you should be able to read and write Java 8 code using default methods, lambda expressions, method references, streams and the new Date API.
Quick start
- 1Open the tutorial. Read the guide online or clone the repository with git clone https://github.com/winterbe/java8-tutorial.
- 2Install Java. Make sure Java 8 or a later version is installed so you can run the examples.
- 3Read the default methods and lambda sections. Work through the first sections to see how interfaces and lambda syntax changed in Java 8.
- 4Study functional interfaces and method references. Learn how a single abstract method interface works with lambdas and the :: syntax.
- 5Practice streams and the Date API. Read the streams, Optionals and Date API sections and try the commented samples in your own project.
Get the tutorial and what you need to run the examples
The tutorial is read online, and the README also gives a command to clone the repository to your own machine if you want a local copy: git clone https://github.com/winterbe/java8-tutorial.
You need Java installed to run the examples. The source says Java 8 or later is needed for running the examples. The guide itself is written as a read-through, so you do not install it the way you would a software tool.
git clone https://github.com/winterbe/java8-tutorialLearn default methods and lambda expressions
Default methods let an interface include a non-abstract method implementation using the default keyword, so concrete classes only have to implement the abstract method. Lambda expressions replace verbose anonymous classes with a shorter syntax. The tutorial shows how a sort call that once needed an anonymous Comparator shrinks step by step into a single line such as names.sort((a, b) -> b.compareTo(a)).
- Start with the Formula interface example to see a default method in use.
- Compare the anonymous Comparator with the lambda version to see the reduction in code.
- Note that the compiler can infer parameter types, so you can usually leave them out.
names.sort((a, b) -> b.compareTo(a));Understand functional interfaces and method references
A functional interface contains exactly one abstract method, and each lambda of that type is matched to that method. The tutorial recommends adding the @FunctionalInterface annotation, which makes the compiler report an error if a second abstract method is added, though the code is still valid without it.
Method references using the :: keyword let you pass a static method, an object method or a constructor where a lambda would go. The tutorial shows Integer::valueOf, something::startsWith and Person::new as examples.
Converter<String, Integer> converter = Integer::valueOf;Work with lambda scopes
Lambdas can read local variables from the enclosing scope, but those variables must be effectively final. Writing to a local variable from inside a lambda is not allowed. Instance fields and static variables can be both read and written from within a lambda.
- Local variables: read-only, must be implicitly final.
- Instance fields and static variables: read and write access.
Use streams, Optionals and the Date API
The tutorial covers the new API surface, including streams with filter, sorted, map, match, count and reduce operations, parallel streams, Optionals, map extensions and the Date API with Clock, Timezones, LocalTime, LocalDate and LocalDateTime. Each part has its own short commented example that you can read in sequence.
Use the table of contents on the source page to jump to a topic you need, such as Streams or Date API, instead of reading from start to finish.
What people use it for
- Updating older Java code that was written before Java 8 to use lambdas and streams.
- Learning Java 8 features through short, commented code samples as a student.
- Refreshing your memory on lambda expressions and streams before a project or interview.
- Looking up how the Date API such as LocalDate and LocalDateTime is used in Java 8.
Frequently asked questions
Is java8-tutorial free to use?
Yes. The project is licensed under the MIT licence, and the tutorial is available to read online or clone from GitHub.
What do I need to run the java8-tutorial examples?
You need Java installed. The source says Java 8 or later is needed to run the examples.
How do I install java8-tutorial?
There is nothing to install. It is a written guide. If you want a local copy, run git clone https://github.com/winterbe/java8-tutorial.
Is java8-tutorial still good for learning current Java?
It covers Java 8 features only. The README points readers to a separate Java 11 tutorial by the same author for features added in Java 9, 10 and 11.
What are good alternatives to java8-tutorial?
The source lists the Oracle Java tutorials and Baeldung Java 8 articles as comparable resources. Choose based on whether you want a short commented guide or a broader reference.
Who should not use this guide?
People who need the latest Java features, and people who want a software tool to install, should look elsewhere, since this is a guide to read rather than an application.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
This guide is a good fit for Java developers maintaining older code, students who want short commented examples, and experienced developers who need a quick refresher on lambdas and streams. If you need features from Java 9 and later, or a tool to install, pick the Java 11 tutorial the author recommends or another resource instead.
Install options & downloads