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.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 = 1018439896
Total Memory = 1029177344
Latest posts by Wayan (see all)
- How do I use Proxy class to configure HTTP and SOCKS proxies in Java? - March 27, 2025
- How do I retrieve network interface information using NetworkInterface in Java? - March 26, 2025
- How do I work with InetAddress to resolve IP addresses in Java? - March 25, 2025