1 ImportJava.text.DecimalFormat;2 3 Public classMain {4 /**5 * Display JVM total memory, JVM maximum memory and total free memory6 */7 Public voiddisplayavailablememory () {8DecimalFormat DF =NewDecimalFormat ("0.00″);9 Ten //show JVM Total Memory One LongTotalmem =runtime.getruntime (). TotalMemory (); ASystem.out.println (Df.format (totalmem 1000000F) +"MB"); - //shows the maximum memory that the JVM is trying to use - LongMaxMem =runtime.getruntime (). MaxMemory (); theSystem.out.println (Df.format (maxMem 1000000F) +"MB"); - //Free Memory - LongFreemem =runtime.getruntime (). Freememory (); -System.out.println (Df.format (freemem 1000000F) +"MB"); + } - + /** A * Starts the program at * - * @paramargs the command line arguments - */ - Public Static voidMain (string[] args) { - NewMain (). Displayavailablememory (); - } in}
Java obtains the memory that the JVM consumes and the available memory information of the system