Here you can find the source of getMemoryUsage()
public static String getMemoryUsage()
//package com.java2s; public class Main { public static String getMemoryUsage() { Runtime rt = Runtime.getRuntime(); long total = rt.totalMemory() / (1024 * 1024); long free = rt.freeMemory() / (1024 * 1024); return String.format("Used: %d MB, Free: %d MB, Total: %d MB", total - free, free, total); }/*from w w w .j av a 2 s . co m*/ }