= = compares the values of two variables for equality, for a reference variable represents whether the storage address of two variables is the same in the heap, that is, whether the contents of the stack are the same
equals represents whether two variables are a reference to the same object, that is, whether the contents of the heap are the same
= = compares the addresses of 2 objects, while equals compares the contents of 2 objects.
Basic data types are placed inside the stack, so the basic data types can be compared with = =
When Equals is true, = = is not necessarily true
= = True to indicate that a, B is a no-reference to an instance of the same class
Equals is true to also indicate that a, B is a separate reference to a different instance of the same class, that is, the contents of different addresses in the heap are the same
Report:
When new is a pair of like classes, it creates a space in the heap and then points the space to your new handle, which is placed on the stack, like a list,
The CPU sends instructions to the stack to operate. (Stacks like a book's directory, heap like a detailed chapter in a book) are stored in the stack of the object's specific physical address.
The Java heap is a run-time data area in which the objects of the class allocate space. These objects are established through directives such as new, NewArray, Anewarray, and Multianewarray, and they do not require program code to be explicitly released. Heap is responsible for garbage collection, the advantage of the heap is the ability to dynamically allocate memory size, the lifetime does not have to tell the compiler beforehand, because it is at runtime to allocate memory dynamically, Java garbage collector will automatically take away these no longer use data. However, the disadvantage is that the access speed is slower due to the dynamic allocation of memory at run time.
The advantage of the stack is that the access speed is faster than the heap, after the register, the stack data can be shared . However, the disadvantage is that the size and lifetime of the data in the stack must be deterministic and inflexible. The stack mainly contains some basic types of variables (, Int,short,long,byte,float,double,boolean,char) and object handles.
= = and equals