Guide to Java 8 Comparator.comparing() 1. Overview Java 8 introduced several enhancements to the Comparator interface, including a handful of static functions that are of great utility when coming up with a sort order for collections. Java 8 lambdas can be leveraged effectively with the Comparator interface as well. A… Continue Reading java-8-comparator-comparing

Java 8 Stream findFirst() vs. findAny() 1. Introduction The Java 8 Stream API introduced two methods that are often being misunderstood: findAny() and findFirst(). In this quick tutorial, we will be looking at the difference between these two methods and when to use them. Further reading: Filtering a Stream of… Continue Reading java-stream-findfirst-vs-findany

Get the Current Date, Time and Timestamp in Java 8 1. Introduction This quick article describes how we may get the current date, current time and current time stamp in Java 8. 2. Current Date First, let’s use java.time.LocalDate to get the current system date: LocalDate localDate =; To… Continue Reading current-date-time-and-timestamp-in-java-8

Throw Exception in Optional in Java 8 1. Introduction In this tutorial, we’re going to show how to throw a custom exception when an Optional is empty. If you want to go deeper into Optional, take a look at our full guide, here. 2. Optional.orElseThrow Simply put, if the value is present, then isPresent() would return… Continue Reading java-optional-throw-exception

Java Optional – orElse() vs orElseGet() 1. Introduction The API of Optional typically has two methods that can cause confusion: orElse() and orElseGet(). In this quick tutorial, we’ll look at the difference between those two and explore when to use each one. 2. Signatures Let’s first start with the basics by looking… Continue Reading java-optional-or-else-vs-or-else-get

Survey Results – Java 8, Spring 4 and Spring Boot Adoption Here are the results of the new Java 8 / Spring 4 / Spring Boot Adoption Survey: (over 1500 votes) — Baeldung (@baeldung) June 1, 2015 Java developers are a dynamic, ever changing bunch. Over the past couple… Continue Reading java-8-spring-4-and-spring-boot-adoption

Functional Interfaces in Java 8 1. Introduction This article is a guide to different functional interfaces present in Java 8, their general use cases and usage in the standard JDK library. Further reading: Iterable to Stream in Java The article explains how to convert an Iterable to Stream and why… Continue Reading java-8-functional-interfaces