The base data type is placed on the stack or in the heap, depending on the location of the base type declaration.
A: The variable declared in the method, that is, the variable is a local variable, each time the program calls the method, the system will establish a method stack for the method, the variables declared in the method is placed in the method stack, when the method end system will release the method stack, corresponding to the method declaration of the variable with the destruction of the stack end, This is why local variables can only be valid in a method
A variable declared in a method can be a variable of a primitive type, or a variable of a reference type.
(1) When the declaration is a basic type of variable, its variable name and value (variable name and value are two concepts) is placed in the method stack
(2) When a reference variable is declared, the declared variable (which is actually stored in the method as a memory address value) is placed in the stack of the method, and the object to which it points is placed in the heap class store.
Two: A variable declared in a class is a member variable, also called a global variable, placed in the heap (because the global variable is not destroyed with the end of a method execution).
A variable declared in a class can be a variable of a primitive type and a variable of a reference type.
(1) When declaring a variable of the base type whose variable name and its value are placed in heap memory
(2) When referencing a type, the variable it declares will still store a memory address value that points to the referenced object. Reference variable names and corresponding objects are still stored in the appropriate heap
Basic data type storage location in Java