Here you can find the source of totalMemory()
public static long totalMemory()
//package com.java2s; public class Main { /**/*from w w w .j a va2s . c om*/ * Returns the total amount of memory in the Java virtual machine. * The value returned by this method may vary over time, depending on * the host environment. * <p> * Note that the amount of memory required to hold an object of any * given type may be implementation-dependent. * * @return the total amount of memory currently available for current * and future objects, measured in bytes. */ public static long totalMemory() { return Runtime.getRuntime().totalMemory(); } }