The heap stores all of the objects created by your java program.The heap's contents is monitored by the garbage collector,which frees memory from the heap when you stop using an object. This is in contrast with the stack, which stores primitive types…