Heap Space

Whenever we declare new variables and objects call new method declare a string or perform similar operations jvm designates memory to these operations from either stack memory or heap space.
Heap space. Including for java beginner so my recommendation to you is to learn these principles at the same time you learn the java language technicalities. To run an application in an optimal way jvm divides memory into stack and heap memory. When space allocated to the young generation gets filled a process called minor gc garbage collection is triggered by jvm to clean up space by removing unreferenced objects. When you compile it and launch with 12mb of java heap space java xmx12m oom it fails with the java lang outofmemoryerror.
Proper knowledge of the java vm heap space is critical. Java heap space message. With 13mb java heap space the program runs just fine.