The Java heap holds new objects ( each object contains a corresponding class information, "class information is stored in the method area"), the heap allocates memory, the virtual machine's automatic garbage collector is managed, and the stack memory is only visible to the thread to which it belongs.
The Java stack holds some basic data types (Int,long,byte,double,float,char,boolean,short) and reference variables, and heap memory is visible to all threads.
Exception error
If the stack memory does not have space to store method calls and local variables, the JVM throws Java.lang.StackOverFlowError.
And if the heap memory does not have space available to store the generated objects, the JVM throws Java.lang.OutOfMemoryError.
Space size
The memory of the stack is much smaller than the heap memory, and if you use recursion, your stack will soon be filled. If recursion does not jump out in time, stackoverflowerror problem is likely to occur.
You can set the stack memory size with the-XSS option. The-XMS option sets the size at which the heap starts, and the-XMX option sets the maximum value for the heap.
Method Area:
Also called the static zone, like the heap, is shared by all threads. It is used to store data such as class information, constants, static variables, instant compiler compiled code, etc. that have been loaded by the virtual machine
Java stack constant pool