You can create an instance for the Runtime class and use the totalmemory() method in it to know the total amount of memory in the Java virtual machine as well as you can use the freeMemory() method which returns the amount of free memory in the Java Virtual Machine. If there are any queries you can contact me here. Thank you.
Joined: Sep 06, 2009
Runtime class is available in java.lang package
Joined: Nov 25, 2007
Functions from class java.lang.Runtime freeMemory() returns the amount of free memory in the Java Virtual Machine.
totalmemory() returns the total amount of memory in the Java virtual machine.
Lets take an example:
In above code class employee have two variables declared of type int and float. If I create object of class Employee one object will occupy total 8 bytes of memory. Similarly, if I designed whole application, can I directly calculate how much memory my whole application will occupy.