Display the maximum amount of memory in Java

Java 8Object Oriented ProgrammingProgramming

In order to display the maximum amount of memory in Java, we use the maxMemory() method. It is a method of the java.lang.Runtime Class. It returns the maximum amount of memory that the Java Virtual Machine will try to use.

Declaration − The java.lang.Runtime.maxMemory() method is declared as follows −

public long maxMemory()

Let us see a program to display the maximum amount of memory in Java −

Example

 Live Demo

public class Example {
   public static void main(String[] args) {
      // print statement at the start of the program
      System.out.println("Start...");
      // displays the maximum memory
      System.out.println(Runtime.getRuntime().maxMemory());
   }
}

Output

Start...
119537664
raja
Published on 08-Jan-2019 11:55:06
Advertisements