get Max Memory - Java java.lang

Java examples for java.lang:Runtime

Description

get Max Memory

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        System.out.println(getMaxMemory());
    }//w w  w .ja  v  a2 s .  c  o  m

    public static long getMaxMemory() {
        return bytesToMegabytes(Runtime.getRuntime().maxMemory());
    }

    private static long bytesToMegabytes(long bytes) {
        long MEGABYTE = 1024L * 1024L;
        return bytes / MEGABYTE;
    }
}

Related Tutorials