How to use map(), filter() and reduce() methods on java8 stream.

map(), reduce() and filter() are intermediate operations to transforming and filtering the elements. With these three methods we can do a lot, so its worth knowing them intimately.

These three methods we can apply only on stream. In our last article, we have already discussed about Stream in java. So once you have a stream object, you can use variety of methods to transform it into another stream object.

1. Map():
=====

In simple words, the map() method is used to transform one object into another object. It takes a lambda…


Sequential Stream vs Parallel Stream in java

In this article we will learn java 8 stream with example.

What is Stream in java?
A Stream is not a data structure instead it takes input from the collection , Arrays.
A Stream in java is a sequence of objects which operates on data source such as an array or collection. Stream also supports many aggregate operations like filter, map, limit and reduce to customize the original data into a different form according to the need.

Sequential Stream:
===========
Sequential stream are non-parallel streams that use only single thread to process the pipelining. It…


Optional was introduced in jdk8. It is a public final class and used to avoid NullPointerException in Java application.

It is a public final class which is used to avoid NullPointerException in java application. It was introduced in Java8. As we know java is an object oriented programming language . So sometime object contain some value or sometime null. To avoid NullPointerException we can use Optional class.

Okay, Lets create one java class to check usage of Optional class in java application.

First I will create one model class i.e. User.java. It containing 3 fields id, name and city.

There…


As we know set will never contain duplicate elements.
But how in java Set interface implemented class HashSet achieve this uniqueness. In this post, we will discuss about this.

HashSet uses HashMap internally to store it’s objects. Every constructor of HashSet class internally creates one HashMap object.

/**
* Constructs a new, empty set; the backing HashMap instance has
* default initial capacity (16) and load factor (0.75).
*/
public HashSet() {
map = new HashMap<>();
}

Whenever you create a HashSet object, one HashMap object associated with it is also created. …


How Spring Boot Transaction Management Works with the @Transactional annotation and Propagation types.

The process of combining related operations into single unit and executing them by applying do everything or nothing principle is called Transaction Management.

We execute sensitive logics like ticket booking, transfer money and etc. logics by enabling transaction management support.

TRANSACTION PROPAGATION TYPE :

1. REQUIRED
2. SUPPORTS
3. MANDATORY
4. REQUIRES_NEW
5. NOT_SUPPORTED
6. NEVER
7. NESTED

1. REQUIRED :
========

  • If the addMessage() is called directly then it will create its own Transaction.
  • If the add message is called from another service –
    a. If…


In this story we will learn how to use Profiles in Spring Boot Application.

Every enterprise application has many environments, like:

Dev | Test | Stage | Prod | UAT / Pre-Prod

Each environment requires a configurations that is specific to them. These environments host specific configurations called Profiles.

In this story I will create a simple spring boot project and will demonstrate how to setup Profiles for your Spring Boot application.

Let’s start with setting up a Spring Boot application from the https://start.spring.io/

Now Click On Generate then zip file of source code will be generated . …


Most Expected Interview questions.

1. Q : WHAT IS HIBERNATE ?

ANS : It is an open source, light weight, non-invasive, java based ORM Framework. To develop Object based Database Software independent O-R Mapping, persistence logic in all kind of java, JEE and Java Framework apps.

2. Q : WHAT ARE THE MAIN FEATURES OF HIBERNATE?

ANS :

1. Hibernate gives HQL (Hibernate Query Language) as DataBase Software Independent.

2. Hibernate supports lazy loading.

3. Allows to develop objects based persistence logic in standalone environment and also in web application environment.

4. Does not need the heavy weight containers …


In this article, You’ll learn how to upload files using spring boot rest API.

  • Uploading files are very common tasks. For which developers need to write code in their applications.
  • We’ll first build the REST API for uploading file, and then test those API using Postman.

First Create Spring Boot Project Using Start.spring.io

FileUpload Project

Now, Let’s configure our Spring Boot application to enable Multipart file uploads, and define the maximum file size that can be uploaded. We’ll also configure the directory into which all the uploaded files will be stored.

Open src/main/resources/application.properties file, and add the following properties to it -

Gain Java Knowledge

The Java programming language is one of the most popular languages today. Stay up to date with news, certifications, free learning resources and much more.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store