How to programmatically check the amount of RAM allocated to a JVM?
<p>Suppose I have a JVM that is solely dedicate to run one program, how can I get the amount of RAM that is allocated to the JVM? </p>

<p>Let's say my computer has 4GB and I specify via JVM parameters that the max it should used is 2GB, then 2GB is the output that I should get.</p>

<p>Conversely, if I do not specify any parameters to the JVM, the output should be the default value, whatever it is.</p>