-1

I need to get the total ram size of the computer using java. I've tried this:

package test;

import java.lang.management.ManagementFactory;

public class test1 {

    public static void main(String[] args) {

        com.sun.management.OperatingSystemMXBean mxbean = 
            (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();

        float a = mxbean.getTotalPhysicalMemorySize();
        System.out.println(a + " bytes");

    }
}

And I have an error:

Access restriction: The type OperatingSystemMXBean is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/lib/rt.jar

Marvin
  • 13,325
  • 3
  • 51
  • 57

1 Answers1

0

This is just Eclipse trying to discourage you from using the internal com.sun packages. You can make the error go away by changing your preferences:

Preferences
 > Java
  > Compiler
   > Errors/Warnings
    > Deprecated and restricted API
     > Forbidden reference (access rules)

Change this value to Warning or Ignore, but make sure to read up on It is a bad practice to use Sun's proprietary Java classes? to understand what you are doing.

Community
  • 1
  • 1
Marvin
  • 13,325
  • 3
  • 51
  • 57