How to take Heap dumps

Heap dumps provide information about the contents of JVM Heap. They are very helpful to know which object are occupying memory and the their links to the root objects. Let’s see different options to take Heap dumps Using command line option on OOME This has been discussed in detail here Using jmap jmap is a […]

Continue reading


How to enable Garbage Collection logs

Monitoring GC activity is critical to Application performance monitoring. JVM provides a very low overhead solution to enable the GC logging. Lets see how to enable Garbage collection logs GC logs can be enabled by adding following flags while starting your Java application -verbose:gc -> enables verbose gc mode -XX:+PrintGCDetails -> prints the gc details […]

Continue reading


How to read Jar files in Java

Jar files are ways of packaging Java classes and sources at times. We might at times need to read the Jar files and process the contents. Let’s see how to read Jar Files in Java Let’s quickly see the code

To read a Jar file, we need to use JarInputStream. Each Entry within a […]

Continue reading


How to read from command line in Java

Reading from command line to get User input is a common task. Let’s see how to do it in Java Java provides java.util.Scanner class to help read from Console. Let’s see the code that shall take name and age as input and print it back.

We initialize Scanner with System.in to set command line […]

Continue reading


How to implement LRU Cache in Java

Caching is an important need in most of Applications. Let’s see how to implement an LRU cache in Java. LinkedHashMap is the key to implement, which provides a way to achieve the LRU functionality. Let’s see the code

The key to achieve LRU functionality is to implement removeEldestEntry() API. We maintain a variable which […]

Continue reading