2

I am writing a program in which i need to do a minimum system RAM validation. How do i go about calculating the RAM of the machine that is executing the code in its JVM ?

user434885
  • 1,948
  • 6
  • 28
  • 50
  • possible duplicate of [Using Java to get OS-level system information](http://stackoverflow.com/questions/25552/using-java-to-get-os-level-system-information) – Jim Garrison Feb 20 '12 at 06:31

2 Answers2

3

I think it is not possible with pure java at all.

Within the JVM you can only mesure the JVM-ram not the System RAM. http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/management/MemoryMXBean.html

You'll need a piece of native code.

Christian Kuetbach
  • 15,550
  • 4
  • 42
  • 78
3

You can have a look into Runtime class:

Runtime.getRuntime().maxMemory();

but from Runtime docs:

Returns the maximum amount of memory that the Java virtual machine will attempt to use. If there is no inherent limit then the value Long.MAX_VALUE will be returned

Kris
  • 5,600
  • 2
  • 26
  • 46
  • I've just found that there was a similar question already asked: http://stackoverflow.com/questions/25552/using-java-to-get-os-level-system-information – Kris Feb 17 '12 at 11:09