Tuesday, June 19, 2012

How to get RAM size using java?

package com.demo.memoryheap;

import java.lang.management.ManagementFactory;

/**
 * @author abdul
 *
 */
public class FreeMemoryUsingMxBean {

    /**
     * @param args
     */
    public static void main(String[] args) {
        com.sun.management.OperatingSystemMXBean mxbean = (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
       
        System.out.println("Total Memory in MB: " + mxbean.getTotalPhysicalMemorySize()/(1024*1024));
       
        System.out.println("Free Memory in MB: " + mxbean.getFreePhysicalMemorySize()/(1024*1024));
    }
}

Note : If you get access restriction error while working on Eclipse , check this :
Access Restriction issue

1 comment:

  1. My Arcus offer java training with 100% placement. Our java training course that includes fundamentals and advance java training program with high priority jobs. java j2ee training with placement having more exposure in most of the industry nowadays in depth manner of java

    java training in chennai

    ReplyDelete

How TOPT Works: Generating OTPs Without Internet Connection

Introduction Have you ever wondered how authentication apps like RSA Authenticator generate One-Time Passwords (OTPs) without requiring an i...