Parallelism Example in Java Stream API

I am going to show you how to work with parallel stream in Java 8 or higher version of Java. In parallel computing a task is divided into sub-tasks and these sub-tasks are computed parallelly in each separate threads and finally the result of the solution for each sub-tasks is combined. One of the features for computing parallelism is to use Java’s join/fork framework, where you need to mention how the particular task will be sub-divided or partitioned into sub-tasks. The main difficulty for parallel computing in applications is the…

Continue

Python Client for Apache Kafka Producer and Consumer

Introduction In this tutorial I am going to show you how to use Python client to work with Apache kafka distributed stream processing system. I will create Kafka producer and consumer examples using Python language. KafkaConsumer is a high-level message consumer that consumes records from a kafka cluster. The consumer is not thread safe and should not be shared across threads.

Continue

How to find unique strings or objects using Java stream API

Introduction In this tutorial we will see an example on how to find unique strings or objects using Java stream API. Stream API was introduced in Java 8 and we are going to see how to use this stream API to remove duplicates from strings or objects. Java stream API has a method distinct() that removes duplicates and returns unique strings from a list of strings. But for objects we cannot directly apply this distinct() method directly to find out unique elements from a list of objects. Therefore we will…

Continue

Event Driven Streaming using Spring Cloud Stream and Apache Kafka

In this tutorial we will see an example of event driven streaming using Spring Cloud Stream and Apache Kafka streaming platform. How do we deal with some events, such as, a new user has registered to a portal, an order was placed, a file has been uploaded etc? Let’s say when an order was placed then we need a call to process payment, a call to reserve inventory, a call to begin the process of packaging, picking and shipping the product. For a few orders it’s not a big deal…

Continue

Convert List of Map Objects into List of Objects using Java Stream

Introduction Here I will show you how to convert List of Map objects into List of objects using Java 8’s or later’s Stream API. The List of Map objects can be found as a result of selecting multiple records from database table or any other sources. Then you may need to convert into List of objects to make it better readability for further using in the application code.

Continue

Collect and Convert Objects using Lambda Expression in Java 8

Introduction In this tutorial, I will show you how you are going to collect and convert objects using lambda expression in Java 8 stream API. We will collect objects and map to another custom objects using Java 8 stream API with the help of Lambda Expression. Suppose you have entity classes generated from your database tables and after fetching data from database tables you want to apply some logic and want to map to custom Data Transfer Objects.

Continue

How to read input through keyboard in Java

This tutorial shows how to read input from keyword using Java programming language. For example if your database connection string changes then you don’t need to worry because for any database connection string like username and password, this will still work. This is a simple example, you can customize as per your need. You can also apply validation on each user’s input. Basic idea behind this example how you can read input from keyboard in Java.

Continue