Single Responsibility Principle (SRP)| SOLID Principles

In this tutorial, I am going to discuss the Single Responsibility Principle of SOLID design principles.

I am going to discuss what is Single Responsibility Principle? How does this principle help us to write clean and maintainable code?

SOLID principles are made popular by Robert C. Martin. You can read his amazing book clean architecture.

Single Responsibility Principle

This principle states that a class should have only one reason to change.

Multiple reasons for change indicate a class has many responsibilities. A class that has many responsibilities is harder to maintain and also it increases the possibility of bugs.

To understand this principle, let’s take an example.

Different Ways to Capture Java Heap Dumps

In this tutorial, I am going to discuss what is java heap dump and what are the different ways to capture a java heap dumps.

What is a Heap Dump?

A heap dump is the snapshot of all the objects in the JVM at a certain moment. In simple words, It is the snapshot of the java memory.

The heap dump is useful in debugging java memory-leak issue and out-of-memory error in java applications. Heap dump is capture/store in binary format (hprof) files.

Once heap dump is taken it can be analyzed through heap analyzer tools such as Eclipse memory analyzer tool (MAT), JVisualVM, HeapHero etc. In this tutorial, i am only going to discuss how to generate java heap dumps.

How to Create Immutable Class in Java

In this tutorial, I am going to discuss what is immutable classes in java? How to create custom immutable class in java.

What is immutable class?

Immutable class means, once you created an object of a class you can’t change it’s state or attribute value. In Java, all the wrapper classes like Boolean, Short, Integer, Long, Float, Double, Byte, Char and String classes are the immutable class.

In Effective java, Joshua Bloch makes this compelling recommendation.


“Classes should be immutable unless there’s a very good reason to make them mutableā€¦.If a class cannot be made immutable, limit its mutability as much as possible.”