Get JVM Memory Details in Java

Yet another example on getting & printing free memory, max memory, total memory details in the output using Runtime class.


class MemoryDetails
public static void main(String args[])

// Create Runtime object
Runtime r=Runtime.getRuntime();

// Free memory in JVM
System.out.println("Free memory: "+r.freeMemory());

// Total memory in JVM
System.out.println("Total memory: "+r.totalMemory());

// Max memory JVM uses
System.out.println("Max memory: "+r.maxMemory());


Free memory: 15948296
Total memory: 16252928
Max memory: 259522560

Note: Memory is given in the form of bytes.

Posted by at on

Tags: java.lang,