posted 18 years ago
"Heap size" is a property of a process, not of a machine. I'm not sure whether you're asking how to get the total memory available to a Java process, or how to find out the total memory available on a machine. The answer to the first question is the method Runtime.maxMemory(); "Runtime.getRuntime().maxMemory()" is the maximum number of bytes available for the Java heap. As far as the Java program is concerned, that's all the memory available on the machine.
If you're asking how to really find out the physical RAM size on the host computer: there's no way to do this built into Java, and of course there's no OS-independent way to do it outside of Java, either. If you only need to do this on a particular OS, you could, for example, use Runtime.exec() to run some system utility that reported this value.