What is Java Stream

Java streams are a feature introduced in Java 8 that allows developers to perform functional-style operations on collections of data. Streams are designed to make it easier to write more concise, declarative code for manipulating collections, and to take advantage of multi-core processors for improved performance.

Unit Test with Mono and Flux

Unit testing with Mono and Flux in Reactor Java is straightforward and involves the use of the StepVerifier class. The StepVerifier is a testing utility that can be used to verify the behavior of reactive streams.

Non-Blocking vs Reactive

Non-Blocking and Reactive are related concepts in the context of asynchronous programming, but they refer to different aspects of the programming model. This entry explains what each means and how they are different. Disclaimer: This blog was written by ChatGPT with the image by MidJourney.

Java Streams Code Snippets

What is a Java Stream?

Java Stream is a sequence of elements supporting the sequential and parallel aggregate operation. This example shows an aggregate operation using Stream and IntStream

int sum = widgets.stream()
                 .filter(w -> w.getColor() == RED)
                 .mapToInt(w -> w.getWeight())
                 .sum();

In this example (from Oracle Stream doc), widgets is a Collection<Widget>. A stream of Widget objects was created via Collection.stream(), filter it to product a stream containing only the red widgets, and then transform it into a stream of int values representing the weight of each red widget. Finally this stream is summed to produce a total weight.

 

This post lists Java Streams code snippets that I find very useful

Lombok Tips

What is Lombok?

In their own word,

Project Lombok is a java library that automatically plugs into your editor and build tools, spicing up your java. Never write another getter or equals method again, with one annotation your class has a fully featured builder, Automate your logging variables, and much more

Why Use Lombok

  • Reduce boilerplate code
  • Increase readability
  • Reduce work for unit test code coverage

When to NOT use Lombok?

  • More complex entity classes (non-POJO classes)