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.”

Best Time to Buy and Sell Stock

How to get maximum profit by buying and selling a stock when at most one transaction is allowed?

In this problem, we have given an array of stock prices, the ith element represents the stock price on ith day.

If we are allowed to complete at most one transaction (i.e.,buy one and sell one share of the stock), design an algorithm to find the maximum profit.

Note that you cannot sell a stock before you buy one. If it’s not possible to achieve any profit return 0.

For example –

Example 1-

Input – { 9, 1, 6, 3, 7, 4}

Output – 6 (Buy on day 2 (1) and sell on day 5 (7))

Example 2-

Input – {5, 4, 3, 2, 1}

Output – 0 (It is not possible to do any transaction)