A Real-World Example of a Stream Collector

Java Stream's Collectors methods fit most use-cases. They allow returning either a Collection or a scalar. For the former, you use one of the toXXX() method, for the latter, one of the reducing() one.

Let's imagine an e-commerce platform that implements a shopping cart. The cart is modeled as the following:

Functional Programming Patterns With Java 8

It’s been four years since functional programming became feasible in Java. The means we have had four years to play with Java 8.

And we've played... and played. After developing several large enterprise projects that made heavy use of Lambdas and Streams, consulted many other projects in doing so, and taught these concepts to hundreds of developers as an independent trainer, I think it’s time to summarize patterns, best practices, and anti-patterns.

Backpressure in Akka Streams

“Reactive Streams”, whenever we come across these words, there are two things that come to our mind. The first is asynchronous stream processing and the second is non-blocking backpressure. In this blog, we are going to learn about the latter part.

Understanding Back Pressure

According to the English dictionary, back pressure means “Resistance or force opposing the desired flow of fluid through pipes”. To define it in our software context, in place of the flow of fluid we can say the flow of data  “Resistance or force opposing the desired flow of data through software

Bridge the Gap of Zip Operation

Despite Java not providing a zip operation, you don't need either 30 additional lines to implement it, nor a third party library. Simply compose a zipline through the existing Stream API.

Abstract

Java, from its 8th version onward, provides an easy way to query sequences of elements through its Stream Interface, which provides several operations out of the box. This set of operations is quite versatile but, as can be expected, it does not cover all the operations a programmer may require. One such operation is zip, as we can observe in one of the most visited posts about Java Streams in Stackoverfow: Zipping streams using JDK8 with lambda (java.util.stream.Streams.zip). Even 7 years later, we are now on Java 14 release and there is no zip operation for Streams yet.

Java14: Join Database Tables With Java 14’s New Record

Java14 Records in Joins

Did you know that you can join database tables into a Java Stream with Java 14's preview record feature? Read this short article and find out how it is done using the Speedment Stream ORM. We will start with how to set up your project.

You may also like: A First Look at Records in Java 14

Setup

Download Java 14. Go to the Speedment Initializer and download your project skeleton (including pom.xml). Modify the following lines in your pom.xml file.

Modifying Variables Inside Lambdas

Occasionally, we will run into a situation in which we want to modify a variable inside a Lambda expression, but when we try to do so, we get a compile-time error saying: 

A variable inside Lambda must be Final or Effective Final.

Java 8 Steaming (groupBy Example)

In this article, I would like to share few scenarios where we will see how the Java 8 Stream and related functions can be useful for reading a file and applying some aggregate functions, which we generally do in our day-to-day SQL/queries on the database side.

So, I am taking an example of employee CSV files, which is shown below:

Top Tutorials to Learn Java 9 Features in Depth

It’s been more than a year since JDK 9 was released, and if you haven't touched Java 9, this year is probably the best time to learn Java 9 and get yourself familiar with new features and enhancements on existing APIs. The highlight of JDK 9 release was Project Jigsaw or Module System.

The Java 9 Platform Module System allows Java to move forward by modularizing the JDK as well as adding modules as first-class citizens to Java, but that’s not the only thing to look forward, there are many small changes that are very useful in day-to-day coding.