Whether there are pointers in Java, and note the differences between references and pointers

Source: Internet
Author: User

references in Java work like pointers, but there are differences: ()
(1) The pointer must point to a memory address, if you do not specify when you define, it will be random (it is likely to create a security risk) but the reference is defined by the default point is empty.

(2) The pointer can be manipulated at will, but the reference can never be manipulated, always point to the object's first address, or change the object that the reference points to.

(3) reference reduces the flexibility of the pointer but more secure and easy to operate.

(4) Reference is a controlled, safe, castrated version of the pointer. Safe, of course, has lost a certain function, but the advantages outweigh the disadvantages.
(5) There is no pointer in Java, but there is a pointer-like thing, reference! For example: String Str=new string ("Helloworld"),
STR is the reference

(6) There is no pointer in Java, but there is a reference, such as Object obj, which is a reference to an object class, has some function of the pointer, but does not allow
int *p = &a;
p + = 2;
Other areas of memory are not mistakenly manipulated.

(7) A reference is just a pointer to the use of a small number of references are not assigned to use when the exception is thrown, null pointer exception can not change the value of the parameter, can only change the parameters

The value of the property is clearly telling us that the reference is the pointer.

Whether there are pointers in Java, and note the differences between references and pointers

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.