How to convert StackTrace to String

We are all used to print stacktraces to console or in log files. At times we have a need to convert Stacktrace to String to send to another logging system or for related purpose. Let’s see what are the options available to achieve this Option 1 : Using a PrintWriter

The printStackTrace() API takes […]

Continue reading

How to execute native commands and external programs from Java

Many time we need to use native commands or other programs like Perl or Python scripts from Java. In this post let us explore how can we achieve this. To explain we shall use simple ls command and print it’s output. We can execute external programs using Runtime class. Let’s see the code

The […]

Continue reading

How HashMap works in Java?

HashMap is an implementation of Map interface, which maps keys to values. A Map cannot contain duplicate keys. We know we can put and get Key-values into HashMap. So, how does HashMap actually works in Java. This post explores a bit about the internal working. Before we jump into details, let’s see some basic terminology […]

Continue reading

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