Find Total Amount Of Memory In JVM

You are here : Home / Core Java Tutorials


In this core java tutorial we will Find Total Amount Of Memory In JVM (Java virtual machine) In your System
in java.

About totalMemory() method of java.lang.Runtime class in java >
  • totalMemory() method of Runtime class returns the total amount of memory in the JVM (Java virtual machine).
  • totalMemory() is the native method in java, so value returned by this method depends on the host environment.

Example/program to Find Total Amount Of Memory In
JVM (Java virtual machine) In your System >
/**
* Example/program to Find Total Amount Of Memory In
* JVM (Java virtual machine) In your System
*/
public class TotalAmountOfMemoryInJavaVirtualMachineExample{
   public static void main(String[] args) {
         
     /**
     * first we will get the java Runtime object using the
     * Runtime class's getRuntime() method in java.
     */
       Runtime runtime = Runtime.getRuntime();
     
     /**
     * totalMemory() method of Runtime class returns the total
     * amount of memory in the JVM (Java virtual machine).
     * totalMemory() is the native method, so value returned by this
     * method depends on the host environment.
     */
    
     long totalMemoryInJVM = runtime.totalMemory();
      
       System.out.println("Total amount of memory in the "
             + "JVM (Java virtual machine) in bytes = "+ totalMemoryInJVM);
   }
}
/* output
Total amount of memory in the JVM (Java virtual machine) in bytes = 257425408
*/



Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.

SUMMARY >
So in this core java tutorial we got the Total Amount Of Memory In JVM (Java virtual machine) In your System
in java.


RELATED LINKS>

Find out total number of available processors to JVM



Must read for you :
Labels:

No comments:

Post a Comment