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 -


In this article, we will see how to Consume records/messages from Topic. Let’s get to it!

In last article, we discussed how to how to produce records/messages with Kafka brokers. In this article, we will see how to consume records/messages from Topic.

Now, before creating a Kafka producer in java, we need to define the essential Project dependencies. In our project, there will be three dependencies required:

Open URL start.spring.io and Create Maven Project with these three dependencies. Lombok is used to generate setter/getter methods.

So After Generating the project we will extract this file and will import kafka-consumer project into Eclipse.

Here In this project we will create one KafkaMessageListener Class that will be used to consume the message from topic. This class will be annotated with the annotation @KafkaListener(id = “my-listener”, topics=”MyTopic”)


In this article, we will see how to produce records/messages with Kafka brokers. Let’s get to it!

In last article, we discussed how to install Apache Kafka using Zookeeper on windows. In this article, we will see how to produce records/messages with Kafka brokers.

Now, before creating a Kafka producer in java, we need to define the essential Project dependencies. In our project, there will be three dependencies required:

Open start.spring.io and Create Maven Project with these three dependencies. Lombok is used to generate setter/getter methods.

So After Generating the project we will extract this. We will import this project into Eclipse.

Here In this project we will create one Rest Endpoint that will be used to publish the message on topic.

So, First we will create KafkaProducerConfig.java class in package com.example.kafkaproducer.config. …


Setting Up and Running Apache Kafka on Windows OS

Kafka Introduction :
— — — — — — — —
Apache Kafka is an open-source stream-processing software platform developed by the Apache Software Foundation, written in Scala and Java. The project aims to provide a unified, high-throughput, low-latency platform for handling real-time data feeds.

Apache Kafka is an event streaming platform. — — — — — — — — — — — — — — — — — —— To publish (write) and subscribe to (read) streams of events, including continuous import/export of your data from other systems. To store streams of events durably and reliably for as long…

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