The eight basic data types in Java are value passing (only the value is passed, the original variable has no relation, the original value does not change), but if the data is the object type then the reference is passed, as in the example below:
Package com.minimax.demo;public class test {public static void main (String[ ] args) { int a=10; system.out.println ("Before change (a)". A.. " +A); Change (a); System.out.println ("After change (a)". A.. " +A);//Summary: Java in the basic parameters of the transfer is the value of the transfer, that is, the passed parameter is a copy of the original value, regardless of whether the value passed in the method is changed or not has any relationship with the original data, will not have any effect stringbuffer str= New stringbuffer (); Str.append ("Zhangsan"); System.out.println ("Before change2 (str) ..." +str); Change2 (str); System.out.println ("After change2 (str) ..." +str); Private static void change2 (STRINGBUFFER STR2) {// todo auto-generated method stub//This is the transformation of the one//transformation one output is zhangsan,nihao//because at the time of the call Change2 (str2) method passed over Str is the object of reference, This reference holds the object's address in memory//and then into the Change2 (str2) method is to copy the address of the object stored by STR to STR2, then STR2 has the address to the//object You can then modify the contents of the object the address that Str saves is always unchanged//str2.append (", Nihao");//This retrofit two//Transformation method Two is because the use of new this keyword created a new object in the heap memory, naturally, will be assigned a new memory address//So STR2 has the new object memory address This str2 is a reference to the new object, you can manipulate the new object  , and the memory//address passed in the copy is not a bit , so the contents of the original object are not modified//So the final test result is   ZHANGSANSTR2 =new stringbuffer (); Str2.append (", Nihao");} Private static void change (Int b) {b=12;}}
This article is from "Wish You Happiness" blog, please be sure to keep this source http://zhunixingfu.blog.51cto.com/7430537/1628938
Whether Java is a value pass or a reference pass