Find Free Memory Available In Java virtual machine

You are here : Home / Core Java Tutorials

In this core java tutorial we will Find Free Memory Available In JVM (Java virtual machine) In your System in java.


About freeMemory() method of java.lang.Runtime class in java >
  • freeMemory() method of Runtime class returns the total amount of free memory in the JVM (Java virtual machine).
  • freeMemory() is the native method in java.

finalize method in java - 13 salient features



Example/program to Find Free Memory Available In JVM (Java virtual machine) In your System >
/**
* Example/program to Find Free Memory Available In
* JVM (Java virtual machine) In your System
*/
public class FreeMemoryAvailableInJavaVirtualMachineExample{
   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();
     
     /**
     * freeMemory() method of Runtime class returns the total
     * amount of free memory in the JVM (Java virtual machine).
     *
     * freeMemory() is the native method.
     *
     * Calling gc (garabage collector) may result in
     * increasing free memory in java.
     */
    
       long freeMemoryAvailableInJVM = runtime.freeMemory();
      
       System.out.println("Total amount of free memory available in the "
             + "JVM (Java virtual machine) in bytes = "+ freeMemoryAvailableInJVM);
   }
}
/* output
Total amount of free memory available in the JVM (Java virtual machine) in bytes = 253398664
*/


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 Free Memory Available In JVM (Java virtual machine) In your System in java.

RELATED LINKS>


Why finalize method is protected in java - An explanation with programs

Find out total number of available processors to JVM

Find Total Amount Of Memory In JVM

Find Free Memory Available In Java virtual machine

Find Maximum Memory That JVM can use

How to terminate JVM in java


Labels: Core Java JVM
eEdit
Must read for you :