-XX:+HeapDumpOnCtrlBreak
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=c:\temp\heapdump\
jmap can be found under bin folder of your JDK
First find out what is the PID of the java process, from which the dump will be generated. Then run from command line:
jmap -dump:file=c:\temp\heapdump\dump.bin PID
String name = ManagementFactory.getRuntimeMXBean().getName();
String pid = name.substring(0, name.indexOf("@"));
String[] cmd = {"jmap", "-dump:file=c:\\temp\\heapdump\\dump.bin", pid};
Process p = Runtime.getRuntime().exec(cmd);
ManagementFactory.getDiagnosticMXBean().dumpHeap("c:\\temp\\heapdump\\dump.bin", true);
jconsole can be found under bin folder of your JDK