Get Total Amount of Memory, Max Memory and Amount of Free Memory in the JVM

This code example shows how to display the total amount of memory the Java Virtual Machine uses, the maximum amount of memory the JVM will attempt to use and
also the total amount of free memory in the JVM.
It is done through calling the methods totalMemory(), maxMemory() and freeMemory() of the Runtime class.
To obtain an instance of the Runtime class we call the static method getRuntime().
The amount of memory from the different methods are returned in bytes, so we round the numbers by creating an instance of the DecimalFormat class and call the method format() for every value.

The output from the code could look something like this:

Search for more Java info on this site here:
Custom Search

Any thoughts or questions?