There are three concepts:
Maximum Memory (Runtime.getRuntime().maxMemory()) Total Memory and (Runtime.getRuntime().totalMemory()) Free Memory (Runtime.getRunTime().freeMemory()) The first is the maximum memory the JVM can ask to the OS before an OutOfMemoryError happens. You can change that with the command line parameters of java o javaw
The second is the total amount of memory of that is allocated at this moment. Because the JVM does not allocate all memory just because you said in the command line parameters that you might use it all.
The third is the amount of memory that is free from the total allocated memory.
You can
test this by enably the gc statics in the command line and you will see what the garbage collector does when the VM needs to allocate more and ask it to the OS, but it will nos ask more than what you specified for maximum memory parameter.