Senior Java Software Developer Interview Questions — part 4

Daniel Zielinski
4 min readApr 30, 2023

Part 1, Part 2, Part 3

1. How to detect reason of out of memory?

Auto dump refers to the feature of automatically generating a heap dump file when an OutOfMemoryError occurs. A heap dump is a snapshot of the JVM’s heap memory, which is used for storing objects.

When an OutOfMemoryError occurs in a Java application, it means that the JVM has run out of heap memory and is unable to allocate any more objects. This can happen due to various reasons such as a memory leak, inefficient garbage collection, or simply insufficient memory allocation for the JVM.

To enable auto dump in JVM, you can use the following JVM options:

-XX:+HeapDumpOnOutOfMemoryError — This option enables heap dump generation when an OutOfMemoryError occurs.

-XX:HeapDumpPath=<file_path> — This option specifies the file path where the heap dump should be generated.

For example, to enable auto dump in JVM and specify the heap dump file path, you can use the following command-line arguments:

java -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/path/to/heap_dump.hprof myApp

With this configuration, the JVM will automatically generate a heap dump file…

--

--