Here you can find the source of getMaxMemory()
public static long getMaxMemory()
//package com.java2s; //License from project: Open Source License public class Main { public static long getMaxMemory() { return bytesToMegabytes(Runtime.getRuntime().maxMemory()); }/* w w w .j ava 2 s .c o m*/ private static long bytesToMegabytes(long bytes) { long MEGABYTE = 1024L * 1024L; return bytes / MEGABYTE; } }