Is there a pointer in java?

Source: Internet
Author: User
Tags java reference

People who have learned c/c ++ and then learn java often have this tangle in mind. Is there any pointer in java?
If you must select either yes or no, OK and java has no pointer.

So, the reference in java and the pointer in c/c ++ (unless otherwise stated, the pointer in the following article refers to the pointer in c/c ++) what is the tangle?

Before starting, let's talk about the reference of c/c ++. It is totally different from the reference of java, and the reference of c/c ++ is the same memory name. Java references point to an object, which also occupies memory.

First, list some common operations that can be performed on pointers:
1. point to an object, such as Person * p = new Person ....; Int * iv = new int ....
2. perform operations on the object indicated by the pointer: P-> getAge (); (* p). getAge ();
3. Obtain the address value stored in the pointer.
4. Point the pointer to another object: Person * p1 = new Person ...; P = p1; however, * p = p1 cannot be used to assign values.
5. delete the new space, delete p1;
6. Other operations

This is enough. Let's take a look at the operations that java references can do.
A. point to an object, such as Person p = new Person...
B. Call the object method, p. getAge ();
C. Point to another object, Person p1 = new Person ...; P = p1;
OK, that's all.

For a and 1, their functions are similar, but java references cannot point to a basic variable ..
For B, java references and pointers are different. In this regard, java reference is more like a pointer to be referenced (dereference); or in java. to some extent, the operator is equivalent to the pointer-> operator. If so, we can no longer reference the java reference.
C and 4 are similar.

In addition, we cannot obtain the address of the Reference Memory in java, we cannot delete, there are many ......

In summary, I think that java references can be regarded as a pointer with limited functionality (or a castrated pointer ). On the other hand, can a function still be called a pointer if it is so limited? After learning about the differences and links between pointers and java references, do you still need to find out if there are any pointers in java!

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.