Find Maximum Memory That JVM can use

You are here : Home / Core Java Tutorials

In this core java tutorial we will Find Maximum Memory That  JVM (Java virtual machine) Attempts To Use in java.


About maxMemory() method of java.lang.Runtime class in java >
  • maxMemory() method of Runtime class returns maximum amount of memory that the JVM (Java virtual machine) will try to use.
  • maxMemory() is the native method in java.

Example/program to Find Maximum Memory That
JVM (Java virtual machine) Attempts To Use >
/**
* Example/program to Find Maximum Memory That
* JVM (Java virtual machine) AttemptsToUseExample
*/
public class FindMaximumMemoryThatJVMAttemptsToUseExample{
   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();
     
     /**
     * maxMemory() method of Runtime class returns maximum amount
     * of memory that the JVM (Java virtual machine) will try to use
     *
     * maxMemory() is the native method.
     *
     */
    
       long maximumMemoryThatJVMAttemptsToUse = runtime.maxMemory();
      
       System.out.println("Maximum Memory That "
                 + "JVM (Java virtual machine) will try to use "
             + "in bytes = "+ maximumMemoryThatJVMAttemptsToUse);
   }
}
/* output
Maximum Memory That JVM (Java virtual machine) will try to use in bytes = 3797417984
*/


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 Maximum Memory That  JVM (Java virtual machine) Attempts To Use in java.

RELATED LINKS>


Find out total number of available processors to JVM

Find Total Amount Of Memory In JVM

Find Free Memory Available In Java virtual machine

How to terminate JVM in java



Labels: Core Java JVM
eEdit
Must read for you :