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.