What is java reference
1. First, you have to understand what a variable is. The essence of a variable is a small memory unit. This small piece of memory stores the value of the variable
For example, int a = 1;
a is the name of the variable, and 1 is the value of the variable.
When a variable points to an object, the variable is called a reference variable (recommended tutorial: java tutorial )
For example A a =new A();
a is a reference variable. It points to an A object. It can also be said that it refers to an A object. We operate the A object by manipulating this a. At this time, the value of variable a is the address of the object it refers to
The reference data type is one of the two major data types of Java
The reference data type is created when , first allocate a piece of memory to its reference (handle) on the stack, and the specific information of the object is stored in the heap memory, and then the reference on the stack points to the address of the object in the heap.
Reference data types include: classes, interface types, array types, enumeration types, annotation types, string types;
java another big data Types are basic data types, including numeric, character and Boolean.
When a basic data type is created, a memory is allocated to it on the stack, and the value is stored directly on the stack;
is the alias of this data, just like a person's nickname Similarly, when you deal with this nickname, you are dealing with the individual itself equivalent to the reference in C, that is, &, which stores the instance address of a certain class
The above is the detailed content of what is java reference. For more information, please follow other related articles on the PHP Chinese website!