Java mendapatkan penggunaan RAM

MemoryUsage heapMemoryUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
long maxMB = heapMemoryUsage.getMax()/(1024*1024);
long usedMB = heapMemoryUsage.getUsed()/(1024*1024);
JavaBeast