How to find total Memory, free Memory and max Memory from Java Runtime?
In this post, we will see how to find total Memory, free Memory and max Memory from Java Runtime. Here, we will use Runtime class to get this information. Every Java application has a single instance of class Runtime that allows the application to interface with the environment in which the application is running. The current runtime can be obtained from the getRuntime method. An application cannot create its own instance of this class. package basics ; import java.util.ArrayList ; import java.util.List ; public class MainApp { public static void main ( String [] args ) { Runtime runtime = Runtime . getRuntime (); System . out . println ( "runtime.totalMemory " + runtime . totalMemory ()); System . out . println ( "runtime.freeMemory " + runtime . freeMemory ()); System . out . println ( "runtime.maxMemory " + runtime . maxMemory ()); runtime . gc (); long m1 = runtime . freeMemory (); List < Strin...