If you want to know the free memory and the total memory available in the Java runtime environment then you can use the following code snippet to check.
package org.kodejava.example.lang;
public class MemoryExample {
public static void main(String[] args) {
long freeMemory = Runtime.getRuntime().freeMemory();
long totalMemory = Runtime.getRuntime().totalMemory();
System.out.println("Free Memory = " + freeMemory);
System.out.println("Total Memory = " + totalMemory);
}
}
Here is the result of the code snippet above:
Free Memory = 252054480
Total Memory = 257425408
Latest posts by Wayan (see all)
- How do I install Calibri font in Ubuntu? - January 24, 2021
- How do I create a generic class in Java? - January 1, 2021
- How do I convert java.util.TimeZone to java.time.ZoneId? - April 25, 2020