Here you can find the source of getMemoryUsage()
public static double getMemoryUsage()
//package com.java2s; public class Main { static long startMemory; public final static int KILO = 1024; /**//from w w w . ja v a 2s . co m * Return the Difference (in MegaBytes) between the first sampled free memory and current * free memory * @return A positive number if there is less memory and a negative number if there is more */ public static double getMemoryUsage() { long diff = startMemory - Runtime.getRuntime().freeMemory(); return ConvertByteToMegaByte(diff); } public static double ConvertByteToMegaByte(long byteUnits) { return (double) byteUnits / (KILO * KILO); } }