Usually we define a variable of the basic data type, a reference to an object, and a live save for a function call uses the stack space in memory, while objects created by the new keyword and constructor are placed in the heap space; the literal amount of the program (literal) is 100, "Hello", which is written directly. And constants are placed in a static storage area. Stack space operation is the fastest but also very small, usually a large number of objects are placed in the heap space, the entire memory including the hard disk of virtual memory can be used as a heap space to use.
String str = new string ("Hello");
In the above statement, STR is placed on the stack, the string object created with new is placed on the heap, and the literal "hello" is placed in the static store. add: A newer version of Java uses a technique called escape analysis, where some local objects can be placed on the stack to enhance the object's operational performance.