Summary and review of several interview knowledge points in Java

Source: Internet
Author: User

First, about value passing in Java

When passing a parameter to a method in Java, a parameter that passes either a primitive type argument or a reference type is a value pass! There is no delivery of reference types in Java!

For native types, their storage address is in the stack (stack), while the storage address of the object of the reference type is stored in the heap memory (heap).

The use of local variables in the method is actually the operation of the stack, and the stack is the first-in-one data structure, after the method call will be popped from the stack memory of the address of the variable.

For native data types, the value of the native data type is passed, and the object of the reference type is passed Addressvalue (the address of the object)

 Public classExample {PrivateString str =NewString ("Goodsss"); PrivateInteger i = 22; Private intAA = 0; Private Char[] ch = {' A ', ' B ', ' C '}; PrivateStu s =NewStu (111111);  Public Static voidMain (string[] args) {Example e=NewExample ();        E.change (E.STR,E.CH,E.I,E.AA,E.S);        System.out.println (E.STR);        System.out.println (e.ch);        System.out.println (E.I);        System.out.println (E.AA);    System.out.println (E.S.AAA); }    Private voidChange (String STRIII,Char[] Chaaa,integer Aaaaai,intA,stu s) {STRIII= "good"; Aaaaai=26; chaaa[0] = ' g '; AA= 11; S.AAA= 9999; }}classStu { PublicStu (intAA) {         This. aaa=AA; }     Public intAAA;}

Output Result:

Goodsss
Gbc
22
11
9999

The above example shows that the basic data type and the string value are passed directly by the value, which is equivalent to assigning their values to the variables in the method, so changing their values in the method will not modify them directly.

referring to the value of the object is passed when the reference address value, you can change the address value in the method to point to the object, it is equal to change the original address point to the object.

Summary and review of several interview knowledge points 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.