VOOZH about

URL: https://javarevisited.blogspot.com/search/label/Java 8

⇱ Javarevisited: Blog about Java Programming Tutorials, Examples, Design Patterns, Interview Questions and Answers, FIX Protocol, Tibco RV messaging, UNIX and Linux Commands, XML, SQL, MySQL, Oracle, jQuery, JavaScript,HTML, Multithreading, Collection, Error and Exception, Debugging, Best Practices and Practical tips from my experience.


Monday, October 13, 2025

5 Best Java 8 Lambda, Stream, and Functional Programming Books for Beginners and Experienced in 2025 [UPDATED]

If you follow Java updates, you may know that Java 13 was released, and Java 14 is on the way, but I often receive emails and queries asking about some good books to learn Java 8. Since Java 8 is very different from any other JDK release, in terms of language and API enhancement, you really need an excellent book to learn fundamentals. In short, based upon my 2 years of learning and reading Java 8 books, I can say that Java SE 8 for Really Impatient is hands down the best book to learn Java 8. It covers all the essential things released in JDK 8, not just lambda expression and streams but also new Date and Time API and several other minor enhancement yet crucial features, which often go unnoticed.

Friday, October 10, 2025

Top 10 Best Java 8 Tutorials, Courses, and Books for Beginners

It's been quite some time since Java 8 was released but the Java community is still buzzing with functional programming and lambda expression. Many developers, programmers, and bloggers have already shared lots of really good tutorials to learn lambda expressions, probably the biggest thing in Java world after Generic was introduced in Java 5. While the term "lambda expression" may sound abstract and academic, Java 8 Lambdas can have a big impact on how you program every day. Java 8 has not only introduced Lambda expressions but also Stream API, Functional interfaces, new Date and Time API, and default methods, which has completely changed the way you write your Java code. As a professional Java developer, you will have to learn Java 8 one day, and it's better to do it sooner than later.

Monday, July 14, 2025

How to Filter Stream and Collections in Java 8? Example Tutorial

Java 8 provides excellent features to support the filtering of elements in Java Collections. Prior to Java 8, the only better way to filter elements is by using a foreach loop or iterating over Collection using the Iterator and selecting the required object, leaving out rest. Though that approach work, it was very difficult to run them in parallel and take advantage of multiple CPUs available in modern-day servers. Java 8 provides Streams, which not only makes it easy to run any operation parallel but also supports lazy loading and lazy evaluation, which means as soon as the filtering condition is satisfied, it stooped doing work, doesn't matter how many objects the collection contains.

Thursday, July 3, 2025

[Solved] How to Implement Fibonacci Series with Memoization in Java 8? ConcurrentHashMap Caching Example

Hello guys, if you are wondering how to solve the Fibonacci series problem with memorization in Java then you have come to the right place. In the past, I have shared recursive and iterative Fibonacci series solution and in this article, I am going to show you how you can improve your solution using a technique called memorization which uses a cache to store the intermediate results. This is a very useful technique to solve Dynamic Programming problems like the Knapsack problem. The good thing about Java is that it provides rich libraries which have classes like ConcurrentHashMap which can be used as a cache to store these intermediary results instead of re-computing them. This can drastically reduce the time to calculate the Nth Fibonacci number.

Wednesday, June 25, 2025

StringJoiner.join() and String.join() Example in Java 8

Hello guys, joining multiple String literals or objects into one is a common programming requirement and you will often find situations where you need to convert a list of String or a Collection of String into a CSV String for your application. For a long time, JDK API has no way to join multiple String literals or objects together, which forces programmers to write hacks like looping through all String objects and manually joining them using String concatenation to create the final, joined String. Even though this approach worked, it was filled with errors and hacks like you need to be careful not to add delimiter before the first element and after the last element, which often caused issues, particularly in the case of beginners and junior Java developers.

Friday, February 21, 2025

Top 5 Free Udemy Courses to Learn Java 8 to Java 21 in 2025 [UPDATED]

Hello guys, if you are looking for some awesome resources, like books, tutorials, and courses to learn and master new features introduced in Java 8 and Java 16, then you have come to the right place. In the past, I have shared some of the best Java 8 tutorials and books, and in this article, I am going to share some of the best and some free Java 8, Java 9, to Java 16 courses from Udemy and Pluralsight with you. There are 2 free courses in this list that are pretty similar to many paid courses you usually buy, and many of these are made free for just promotional or educational purposes by their instructor. You can join these courses to learn JDK 8, 9, 10, 11, 12, 17, and JDK 21 features in a couple of days.

Wednesday, February 19, 2025

Top 5 Udemy Courses to learn Functional Programming in Java in 2025 - Best of Lot

Hello guys, if you remember, Java 8 changed the way we usually code in Java by introducing some Functional Programming concepts. It brings features like lambda expressions and Streams, which give birth to new patterns that result in clean code in Java. Now there is a better and more declarative way to write Java. If you use them correctly, then they can express the intent of the code better and thus making it easier to read and maintain. There is another bit which many people miss is the introduction of Functional programming concepts like the map, reduce, flatmap, and filter, which enable us to write more readable code in Java.

Saturday, October 5, 2024

How to find the first element in Stream in Java 8? findFirst() Example

In Java 8, you can use the Stream.findFirst() method to get the first element of Stream in Java. This is a terminal operation and is often used after applying several intermediate operations e.g. filter, mapping, flattening, etc. For example, if you have a List of String and you want to find the first String whose length is greater than 10, you can use the findFirst() method along with stream() and filter() to get that String. The stream() method gets the Stream from a List, which then allows you to apply several useful methods defined in the java.util.Stream class like filter(), map(), flatMap() etc.

Friday, October 4, 2024

10 Examples of Optional in Java 8

Null is bad, it can crash your program. Even its creator called it a billion-dollar mistake hence you should always try to avoid using nulls whenever you can. For example, you should not return a null String when you can return an empty String, similarly never return null collections when you can return an empty collection. I have shared many such tips in my earlier article, 10 tips to avoid NullPointerException and my reader liked that a lot. But, I wrote that article a couple of years ago when Java 8 was not around and there was no Optional, a new way to avoid NullPointerException in Java, but, things have changed now.

Thursday, July 18, 2024

How to sort a Map by keys in Java 8 - Example Tutorial

Hello Java friends, In the last article, I have shown you how to sort a Map by values in Java 8, and in this tutorial, you will learn how to sort a Map by keys like a HashMap, ConcurrentHashMap, LinkedHashMap, or even Hashtable. Theoretically, you cannot sort a Map because it doesn't provide any ordering guarantee. For example, when you iterate over a HashMap, you don't know in which order entries will be traversed because HashMap doesn't provide any ordering. Then, how can you sort a Map which doesn't support order? Well, you can't and that's why you only sort entries of HashMap but you don't store the result back into HasMap or any other Map which doesn't support ordering. If you do so, then sorting will be lost.

Monday, April 22, 2024

Top 50 Java 8 Stream, Lambda, and Functional Programming Interview Questions

Hello guys, if you are preparing for Java interviews and looking for some Java 8 Stream, Lambda Expression, and other Java 8 features then you have come to the right place. Earlier, I have shared 140+ Core Java interview questions, 50 Java Programs from Interviews and 20+ Spring Boot questions and in this article, I am going to share Stream, Lambda expression, and other Java 8 feature-based questions.  Java 8 features are now not remained as good to know features. They have been increasingly adopted by many organizations and most of the new development encourage developers to write code in Java 8 style to take full advantage of massive CPU power available in modern servers like HP 380 Gen 8 servers, also known as G8. 

Monday, April 8, 2024

How to Prepare for Java 8 Certifications - Oracle Java SE 8 Programmer 1 (1Z0-808) and II (1Z0-809)

Today one of my readers asked about what is the latest OCPJP or Oracle Java exams available and is there a Java certification available for Java SE 19 and Java SE 17?. This prompted me to browse through Oracle's certification website. During my casual browsing, I noticed that even though it's almost a year since Java SE 9 was released and 6 months since Java SE 20was released the latest Java certification is still the Java SE 17 certification. I know, you might be thinking about Java SE 11 certification, which is the latest Java certification available, but still many programmers are going for Java 8 because that's what they use in their production environment. 

How to Sort an HashMap by values in Java 8 - Example Tutorial

In the last article, I have shown you how to sort a Map in Java 8 by keys, and today, I'll teach you how to sort a Map by values using Java 8 features e.g. lambda expression, method reference, streams, and new methods added into the java.util.Comparator and Map.Entry classes. In order to sort any Map, like HashMap, Hashtable, LinkedHashMap, TreemMap, or even ConcurrentHashMap, you can first get a set of entries by using the entrySet() method and then you can get the stream by calling the stream() method. The entrySet()  method returns a Set which inherit the stream() method from the java.util.Collection class. Once you got the stream, you can just call the sorted() method which can sort all Map.Entry objects available in Stream using a Comparator.

How to Convert a Lambda Expression to Method Reference in Java 8?

If you have been coding in Java 8 then you may know that using method reference in place of lambda expression makes your code more readable, hence it is advised to replace lambda expression with method reference wherever possible. But, the big question is, how do you find whether you can replace a lambda with method reference? Yes, it's not that easy, especially if you have been using Java 8 only for a couple of months and struggling to get the functional programming concepts and idioms sorted in your head. Sometimes, IDEs like IntelliJ IDEA and Eclipse does offer some hints to convert lambda expression to method reference but it does make sense to learn the logic behind it, otherwise, it won't make sense.

Tuesday, September 26, 2023

Java 8 Compute(), ComputeIfAbsent() and ComputeIfPresent() Example Tutorial

Hello guys, if you have been doing Java development then you know that Java 8 brings a lot of changes not just on programming language part by introducing Lambda expression, default methods on interface, static method on interface but also on API  and SDK part like Stream API and new Date and Time API. But while those bigger changes get lot of coverage many small changes but very useful in day to day programming task doesn't get enough mention and many Java programmers are unaware of those. One of such enhancement was addition of compute(), computeIfAbsent(), and computeIfPresent() method in java.util.Map interface. Adding  a new method on an existing interface was not possible before Java 8 but new feature like default and static method on interface made it possible and Java designers take full advantage of these two feature to enhance and improve existing interface like Collection and Map. 

Tuesday, May 23, 2023

Java 8 Predicate Functional Interface Example [Tutorial]

In Java 8, there is a defined functional interface which is called Predicate. The Predicate interface receives an argument and based on specific condition it returns Boolean value. It can be helpful in testing and it’s located in java.util.Function package. This is one of the many pre-defined or built-in functional interface which JDK provides. A couple of important ones are Supplier which can be used to produce a value of T (any object) and Consumer which can consume and project like takes data and print to console. forEach() is a good example of method accepting Consumer interface. Similarly many method accept a Predicate and when they do you can simply pass a lambda which generates a boolean by checking a condition. 

Thursday, May 11, 2023

10 Examples of Joining String in Java - String.join vs StringJoiner

It's quite common in day to day programming to join Strings e.g. if you have an array or List of String let's say {Sony, Apple, Google} and you want to join them by a comma to produce another String "Sony, Apple, Google", there is not an easy way to do it in Java. You need to iterate through an array or list and then use a StringBuilder to append a comma after each element and finally to remove the last comma because you don't want a comma after the last element. A JavaScript-like Array.join() method or join() method of Android's TextUtils class is what you need in this situation. Still, you won't find any such method on String, StringBuffer, StringBuilder, Arrays, or Collections class until Java 8.

Monday, May 8, 2023

What is Method Reference in Java 8 Functional Programming? Example

Lambda expression allows you to reduce code compared to an anonymous class to pass behaviors to methods, method reference goes one step further. It reduces code written in a lambda expression to make it even more readable and concise. You use lambda expressions to create anonymous methods. Sometimes, however, a lambda expression does nothing but call an existing method. In those cases, it's often clearer to refer to the existing method by name. Method references enable you to do this; they are compact, easy-to-read lambda expressions for methods that already have a name. One of the most popular examples of method reference is List.forEach(System.out::println), which prints each element into the console. If you analyze this statement from the very beginning, you will understand how lambda expression and further method reference have reduced the number of lines of code.

What is String deduplication in Java? How to Save Memory from Duplicate String in Java 8? [Answer]

You might not be aware that Java 8 update 20 has introduced a new feature called "String deduplication" which can be used to save memory from duplicate String objects in Java application, which can improve the performance of your Java application and prevent java.lang.OutOfMemoryError if your application makes heavy use of String. If you have profiled a Java application to check which object is taking the bulk of memory, you will often find char[] object at the top of the list, which is nothing but an internal character array used by String object. Some of the tools and profilers might show this as java.lang.String[] as well like Java Flight Recorder, but they are essentially pointing to the same problem i.e. a major portion of memory is occupied with String objects.

How to solve FizzBuzz Problem in Java 8? Stream.map() Example

FizzBuzz is one of the most famous programming questions from interviews, which is generally used to weed out programmers who can't program. The problem is deceptively simple but you can't solve it if you don't know how to build programming logic. I love it just for its simplicity. Now coming back to the second part of this article, Java 8. It's been more than a year, I think it was March 18 last year when Java 8 was first released and to date, the most common question I have got is, how to learn new features of Java 8? like Optional, lambda expression, or Stream. I think the best way to learn Java 8 new features is the same as the best way to learn any new programming language like solving common coding problems, implementing data structure, common algorithms, and implementing famous design patterns.
Subscribe to: Posts ( Atom )

Search This Blog

Preparing for Java and Spring Boot Interview?

Get New Blog Posts on Your Email

Followers

Categories

Blog Archive