1 What is the difference between head and stack?
Stack (stack) and heap (head) are places where data is stored in memory, the difference is:
The 1 stack holds the basic type variables and objects applied, when released after the scope is exceeded, the heap holds the new out-of-sum objects and arrays;
2 heap can dynamically allocate the size of the memory, the God save time does not have to tell the compiler first, the Java garbage collector will automatically reclaim these unused data, and the existence of the stack of data size and lifetime must be deterministic, lack of flexibility. The stack is accessed faster than the heap, after the registers that are directly located on the CPU. Heap due to the dynamic allocation of memory at runtime, access speed is slow;
3 stacks of data can be shared, such as the literal 3, etc.; heap can not
4 stack is a linear set, its addition and deletion of element amount operation should be completed in the same paragraph, the stack is processed in a last-in, first-out manner, the stack address is continuous, can be accessed randomly.
Java-oop Stack