Java Heap Memory

There are more than 4.5 billion JVM-enabled devices at present.

Java heap memory is required by JVM to create new object and if the objects which are created by JVM exceeds the heap size then memoryOutof Bound  exception will be thrown, Here are some codes to check the availble heap memory.

public class HeapMemory {

public static void main(String[] args) {

System.out.println("JVM Heap Size : " + Runtime.getRuntime().totalMemory()/ (1024 * 1024));

System.out.println("Memory Available (Maximum) in Mb : " + Runtime.getRuntime().maxMemory() / (1024 * 1024));

System.out.println("Free Memory Available in Mb : " + Runtime.getRuntime().freeMemory() / (1024 * 1024));

System.out.println("Total Memory Used in Mb : " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / (1024 * 1024));
}
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: