Reference passing in Java (same for JS)

Source: Internet
Author: User

1 data types in Java:

There are 8 basic data types, namely: Byte (1), Boolean (1), char (2), short (2), int (4), Long (8), float (4), double (8) The number of bytes represented in parentheses
There are 3 types of reference: class reference, interface reference, array reference

2 How to pass in Java: and. Address delivery.

1) Value passing:

such as the following methods
public void Add (int a) {
int b = A;
}
This can be thought of as a value pass, A is a basic data type, and he passes his value to B.

2) Address delivery:

public void Add (Object obj) {
Object objtest = obj;
}
This is the site pass, which is the reference pass, and obj is the reference data type, which assigns the value of the address of the object in his stack to the heap to objtest.
At this point, there are two references to one of the object objects in the heap

Summary:
If it is a basic data type, the actual value is passed.
If it is a reference data type, the address value of the reference is passed.

Reference passing in Java (same for JS)

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.