Top 10 Java 8 Tutorials, Classes, and Courses in 2025 - Best of Lot [UPDATED]

Hello guys, if you want to learn Java 8, in a particular lambda expression, Stream API, method reference, and new Date and Time API, and looking for the best resources then you have come to the right place. Earlier, I have shared the best  Spring Framework courses and free Java courses and today, I am going to share the best tutorials to learn Java 8 features. It's a long time since Java 8 was released, and there are so many Java 8 tutorials are written by Oracle, Java bloggers, and other people, but which should you read? Which tutorials are worth your time? 

How to Convert String to LocalDate, LocalTime, LocalDateTime and ZonedDateTime in Java? Example Tutorial

The JDK 8 added a new Date and Time API (JSR 310) which introduces new date and time classes like LocalDateLocalTime, LocalDateTime, and ZonedDateTime. Now, if you have a String e.g. "2016-12-14 03:30" then how do parse it to LocalDate, LocalTime, LocalDateTime and ZonedDateTime? Similarly, if you have an instance of those classes how you can format to the String you want e.g. in dd/MM/yyyy format, or USA or UK format? Well, Java 8 provides a utility class called DateTimeFormatter which can be used to parse/format dates in Java 8. It also provides several built-in formatter e.g. ISO date format and other to facilitate formatting of dates to String.

How to convert JSON to Map in Java 8 without using third party libraries like Jackson or Gson

Hello guys, If you are working with JSON data then you may know that JSON is collection of key value pairs and that's why many times, you also need to convert them into a Map in Java. While there are many Java libraries like Jackson and Gson which provides support of parsing JSON to Java objects, there is not much support for JSON parsing or manipulation on standard JDK. While JSON parsing is still a long overdue, starting with JDK 8u60+ the built-in Nashorn engine is capable to convert JSON content into java.util.Map. No external dependencies are required for parsing JSON in to Map as you will learn in this article. 

How to remove duplicates from Collections or Stream in Java? Stream distinct() Example

Hello guys, if you wonder how to remove duplicates from Stream in Java, don't worry. You can use the Stream.distinct() method to remove duplicates from a Stream in Java 8 and beyond. The distinct() method behaves like the distinct clause of SQL, which eliminates duplicate rows from the result set. The distinct() is also a standard method, which means it will return a new Stream without duplicates, which can be used for further processing. Like other methods of Stream class, I mean, map(), flatmap(), or filter(), distinct() is also lazy, and it will not remove duplicate elements until you call a terminal method on Streams like collect or forEach().  

Java 8 Stream.filter() example Example with Null and Empty String

The filter() is a method on Stream class, which accepts a Predicate (a functional interface with a method which return boolean) and returns a stream consisting of the elements of this stream that match the given predicate. For example, if stream is obtained from a list containing "SONY", "APPLE" and "GOOGLE" and predicate is elements with length greater than 4, then filter will return another stream containing only APPLE and GOOGLE, leaving SONY out because its length is not greater than 4. Java 8 provides advanced filtering capability using lambdas and predicates. 

Difference between Abstract class and Interface in Java 8? Answer

Ever since JDK 8 has allowed concrete (non-abstract) methods on the interface like default and static methods, many of my readers have asked me how should they answer the classical abstract class vs interface questions. Earlier, an interface cannot have any concrete methods and that was the main difference between abstract class and interface but now that is not the case. In this post, I'll revisit this hugely popular Java interview question in light of Java 8 changes. This is also a popular Java interview question and knowing the difference will help you to answer this question in a real interview.

How to sort HashMap by values in Java 8 [using Lambdas and Stream] - Example Tutorial

In the past, I have shown you how to sort a HashMap by values in Java, but that was using traditional techniques of the pre-Java 8 world. Now the time has changed and Java has evolved into a programming language that can also do functional programming. How can you, a Java Programmer take advantage of that fact to do your day-to-day task better like how do you sort a Map by values in Java using lambda expressions and Stream API. That's what you are going to learn in this article. It will serve two purposes, first, it will tell you a new way to sort a Map by values in Java, and, second and more important it will introduce you to essential Java 8 features like Lambda Expression and Streams, which every Java Programmer should learn.

Java 8 StringJoiner Example - How to join multiple Strings with delimiter in Java?

While everyone was looking at the lambda expression and Stream API, JDK quietly sneaked some of the exciting methods on its API. There are a lot of hidden gems on JDK 8 and I have uncovered many of them already in this blog and today we'll talk about one of such gems which you can use in your day-to-day programming activities like joining much String together. The Java 8 has added a new class called StringJoiner to join Strings. The java.util.StringJoiner can be used to join any number of arbitrary String, a list of String, or an array of String in Java. You can choose any delimiter to join String like comma, pipe, colon, or semi-colon. This class also allows you to specify a prefix and suffix while joining two or more String in Java.

How to Join Multiple Strings in Java 8 - String join() Example

Hello guys, I have been writing about the new features of Java SE 8 for quite some time. Initially, my focus areas on much talked about lambda expressions and streams, but slowly I realized that Java 8 is not just about them, it's much more than that. It has many more new features and API enhancements that will help Java developers in their day-to-day job as much as lambdas and streams. One of such less talked features is the ability to join multiple String objects into one separated with any delimiter. It has added a class called StringJoiner in java.util package which we have seen earlier, but it has also added a new method on String class, the join() method, which finally allows you to join Strings in Java.

How to Compare and Sort String by their length in Java? Example

One of the common programming tasks is to compare String, sometimes by their value and sometimes by their length. The natural way to compare String is the lexicographic way, which is implemented in the compareTo() method of String class, but sometimes you need to compare String by their length. You cannot use the default compareTo() method for that task, you need to write your own custom Comparator, which can compare String by length. Don't worry, It's easy to compare multiple String by their length, all you need to do is write a Comparator implementation which calculates their length using the length() method and compares them.

Top 15 Java 8 Stream and Functional Programming Interview Questions Answers

The JDK 8 release has changed the way we write Java. With new functional programming idioms and a powerful Stream API, most of the new Java code is written in a functional style. This also means that Stream and Functional programming-related questions are increasing on Java interviews. If you are not familiar with Java 8 changes, then it's difficult to crack a Java interview nowadays. Though it's not stated anywhere, most of the companies, particularly Investment banks like Barclays, Citi, and Goldman Sachs, now expect Java developers to know at least Java 8, which is also good, right? Java 19 is already out, and we are looking forward to Java 21 in a couple of months, it makes sense to know at least Java 8 changes.

How to replace Anonymous Class to Lambda Expression in Java 8? Example Tutorial

Hello guys, you may be thinking why I am talking about Anonymous class now when many Java programmers have already switched to Java 8 and many have already moved on from Anonymous class to Lambda expression in? Well, I am doing it because I am seeing many Java programmers who find it difficult to write and read code using lambda expression in new Java 8 way. It's also my own experience that if you know the problem first, you can better understand the solution (lambda expression). Some of you might remember, the opening scene of MI 2 (Mission Impossible 2), when Nekhorovich says to Dimitri that "Every search for a hero must begin with something that every hero requires, a villain. Therefore, in our search for a hero, Belairiform, we created the monster, Chimera"

Top 5 Functional Interface Every Java Developer Should Learn

Hello guys, functional interface in Java are an important concept but not many developer pay enough attention to them. They learn lambda and method reference but the functional interface from java.util.function package. While its not really possible to learn all the functional interfaces on that package but you can learn a few more commonly used ones like Predicate, Supplier, Consumer etc and that's what you will learn in this article.  But, before we get to the top 5 functional interfaces that every Java developer should learn, let me tell you a bit about what Java really is. 

Top 5 Books to Learn Java 8 and Functional Programming - Best of Lot

Hello guys, recently, I asked my followers on Twitter which Java version they are using in production, and most of them said Java 8 and Java 11. This is not surprising at all because many of the Java and Spring Boot projects I have worked on also using Java 8 in production. After close to 7 years of Java 8 release, it is still the most used Java version in production which is not surprising though. Even though we now have Java 20 but many programmers are yet to learn Java 8 and I often receive queries like which books to read or which online courses to join to learn essential Java 8 features like lambda expression, stream, and functional programming. 

Java 8 Optional isPresent(), OrElse() and get() Examples

The Optional class in Java is one of many goodies we have got from the Java 8 release. If you use it correctly, Optional can result in clean code and can also help you to avoid NullPointerException which has bothered Java developers from its inception. Even though many of us have used null to indicate the absence of something, the big problem is that if you call a method or access a field on the null object (except static fields), you will get a NullPointerException and your whole program may crash. 

Default Methods and Multiple Inheritance in Java 8

Ever since Java 8 introduced default and static methods in JDK 8, it's become possible to define non-abstract methods in interfaces. Since Java, one class can implement multiple interfaces and because there can be concrete methods in interfaces, the diamond problem has surfaced again. What will happen if two interfaces have methods o the same name and a Java class inherit from it? Many Java programmer also asks me the question that, is Java 8 is also supporting multiple inheritances of classes? Well, it's not but the doubt is genuine because the interface with methods is similar to an abstract class or in that any Class in Java.

10 Examples of Collectors + Stream in Java 8 - groupingBy(), toList(), toMap()

As the name suggests, the Collectors class is used to collect elements of a Stream into Collection. It acts as a bridge between Stream and Collection, and you can use it to convert a Stream into different types of collections like List, Set, Map in Java using Collectors' toList(), toSet(), and toMap() method. Btw, Collector is not just limited to collection stream pipeline results into various collection class, it even provides functionalities to join String, group by, partition by, and several other reduction operators to return a meaningful result. It's often used along with the collect() method of Stream class which accepts Collectors. In this article, you will learn how to effectively use java.util.stream.Collectors in Java by following some hands-on examples.

How to use Spliterator in Java 8 - Example Tutorial

Hello friends, we are here today again on the journey of Java. And today, we are gonna learn about SplitIterator class from Stream package that may not be used in your day-to-day life but can be very useful to know as Java internally does use this with both normal streams and parallel streamsAs always, let’s take an example of a situation. I will present you with a situation and you guys can think about it. So, let’s say we have an array with 50k records in it. Now, these all records need to be modified, let’s say they are strings and we need to append the string with a name. Now, traversing the array sequentially would be time-consuming. Any innovative ideas my friends?

How to read a File line by line in Java 8 ? BufferedReader lines() + Stream Examples

Hello guy, if you are wondering how to read a file line by line in Java but not sure which class to use then you have come to the right place. Earlier, I have showed you how to read Excel file in Java using Apache POI API and in this article, I am going to tell you about a useful method from BufferedReader class, the lines() method which can be used to read a file line by line. The BufferedReader.lines() is kind of interesting, letting you turn a BufferedReader into a java.util.Stream in Java 8. This is a very powerful thing as it allows you to tread a file as a stream and then you can apply all sorts of Stream methods like map, count, flatMap, filter, distinct, etc to apply the powerful transformation. We will actually see examples of those in this article by finding out the longest line from the file and printing each line of the file.

How to Convert a List to Map in Java 8 - Example Tutorial

One of the common tasks in Java programming is to convert a list to a map and I have written about this in the past and today we'll see how Java 8 makes this task easier. Btw, be it Java 7 or Java 8, you need to keep something in mind while converting a list to a map because they are two different data structures and have completely different properties. For example, the List interface in Java allows duplicate elements but keys in a Map must be unique, the value can be duplicated but a duplicate key may cause a problem in Java 8. This means a List with duplicates cannot be directly converted into Map without handling the duplicate values properly.