Here you can find the source of getAvailableMemory()
public static long getAvailableMemory()
//package com.java2s; //License from project: Open Source License public class Main { public static long getAvailableMemory() { long freeMemory = Runtime.getRuntime().freeMemory(); return getMaximumMemory() - freeMemory; }//from ww w . j a v a2 s . c o m public static long getMaximumMemory() { long maximumMemory = Runtime.getRuntime().maxMemory(); long totalMemory = Runtime.getRuntime().totalMemory(); if ((maximumMemory <= 0) || (maximumMemory == Long.MAX_VALUE)) { // if maximum memory can not be determined or isn't defined, then default to the totalMemory maximumMemory = totalMemory; } return maximumMemory; } }