Explicitly via jmap utility (Sun/Oracle Java 6 and newer, JRockit R28.0.0 and newer)
Java's jmap utility can connect to a running Java process and dump its Java heap:
jmap -dump:format=b,file=file_name.hprof <PID>
Hint: to learn the PID (process identifier) of running JVM, you can use jps or jconsole JDK utilities.
The benefit is that memory can be analyzed on demand with no additional configuration of JVM or Java application. You can dump memory of any running instance of JVM that supports this feature.