Difference between Heap and Stack
Reference:
-
http://javarevisited.blogspot.com.au/2013/01/difference-between-stack-and-heap-java.html
-
https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-2.html#jvms-2.3.4
-
http://www.codescream.com/ContentDisplay?targetContent=StackAndHeap
-
stack memory is used to store local variable and function call.(primitive type value also store in stack)
-
heap memory is used to store objects.
3.If there is no memory left in the stack for storing function call or local variable. JVM throw java.lang.StackOverFlowError
4.If there is no memory left in the heap for creating an Object,JVM throw java.lang.OutOfMemoryError
5.size of stack memory is a lot lesser than the size of heap.
6.Variables stored in stack are only visible to the owner Thread,While objects created in the heap are visible to all Thread. in other words,stack memory is kind of private memory of Java Threads while heap memory is shared among all threads.
###2.3Primitive Types and Values The primitive data types are:numberic types,and boolean type.
The numberic types consist of the integral types and the floating-point types.
The intergral types are:
- byte,8-bit,from -128 to 127,inclusive
- short,16-bit,from -32768 to 32767,inclusive
- int ,32-bit,from -2的31次方到2的31次方-1
- long,64-bit,
- char,16bit.from 0 to 65535
The Ploating-point types are
- float,32-bit
- double,64-bit
What is the heap
The heap is the location where objects/class-instance are stored.It is much larger than the stack is and its value last longer than those in the stack. Anything created with the new operator will end up on the heap,and will be pointed to by one or more stack references or references in other heap objects.This memory is managed by GC.