Display Maximum Amount of Memory in Java



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
Updated on: 2020-06-25T14:55:44+05:30

250 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements