How do I know the memory size in virtual machine?

Category: java.lang, viewed: 1712 time(s).

If you want to know the free memory and the total memory available in the Java runtime environment then you can use the following code.

 
package org.kodejava.example.lang;
 
public class MemoryExample
{
    public static void main(String[] args)
    {
        long freeMemory = Runtime.getRuntime().freeMemory();
        long totalMemory = Runtime.getRuntime().totalMemory();
 
        System.out.println("Free Memory = " + freeMemory);
        System.out.println("Total Memory = " + totalMemory);
    }
}
 
 
Bookmark this example!  

Most Viewed Examples

Google

100 Top & Latest


eXTReMe Tracker
visitor stats