Saturday, 8 June 2013

Java code to display memory satus

Code
-----------
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());
}
}

Sample output
-------------------------
Free memory: 15964992
Total memory: 16252928
Max memory: 259522560



Explanation
-----------------
Memory is given in the form of bytes

No comments:

Post a Comment