Java reference types and pointers to past life

Source: Internet
Author: User
Tags java reference

Learning Java knows that there is no pointer to this function in Java. But there is a concept that is similar to it, that is, "references".

They are similar because they point to a memory address, but there is a big difference between the concept and the role.

First of all, a pointer, the introduction of the pointer is C genius, some people say that the essence of C language is the pointer. The pointer represents an "address and type" for an "object or function". Operation at the memory level, its benefits on the one hand can apply for discontinuous data storage space on demand, in addition to the operation is faster. But the disadvantage is that improper operation or the programmer's implicit error in the design program can cause memory confusion and program crashes.

So Java does not have the concept of pointers, more precisely the weakening of the concept of pointers so that people try to forget the concept of pointers, and highlight the reference.

Because it refers to the idea of "everything is Object" in Java. A reference variable (often abbreviated as a reference) stores a reference to an object, where the actual object is stored somewhere in memory, whereas a reference variable stores the memory address of the object.

Reference variables will always hold memory addresses stored by some objects, unless the reference variable currently does not reference any objects. In this case, the reference variable stores a null reference, which is null. In addition, Java does not allow reference to basic variables. For pointers, it is illegal to initialize without initialization.

References cannot be computed, while pointers can, for example, perform the + + operation.

In general, references to C + + in Java are distinguished and functionally closer to C + + pointers.

Java reference types and pointers to past life

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.