java中需要注意的地方,包含方法传递参数等

import java.util.*;
import java.lang.*;
public class TestXLmain {

public TestXLmain() {
super();
// TODO Auto-generated constructor stub
}

public static void main(String[] args){


//考察 Integer,int 等的区别 。。
int i = 2;

Boolean a[] = new Boolean[4];
System.out.println(a[i]);//null

Integer b[] = new Integer[4];
System.out.println(b[i]);//null

int c[] = new int[4];
System.out.println(c[i]);//0

Boolean d[] = new Boolean[4];
d[i] = new Boolean(true) ;
System.out.println(d[i]);//true

String f[] = new String[4];
// f[i] = new String() ;
System.out.println(f[i]);//null

Integer e[] = new Integer[4];
e[i] = new Integer(2);
System.out.println(e[i]);//2
System.out.println(e[i].toString());//2
System.out.println(new Integer(2));//2
char[] ch = new char[]{'c','d'};
System.out.println(new String(ch));//cd

String dd = new String();
dd.length() ;

TestXLmain txlmain = new TestXLmain();

//----------- 001
txlmain.swap() ;

//----------- 002
String temp0 = "hello " ;
String temp1 = "world " ;
txlmain.swap(temp0, temp1) ;
System.out.println("temp0=="+temp0+",temp1=="+temp1);//temp0==hello ,temp1==world


//----------- 003
String[] tempA = new String[]{"hello ","world "} ;
txlmain.swap(tempA) ;
System.out.println("tempA[0]=="+tempA[0]+",tempA[1]=="+tempA[1]);//tempA[0]==world ,tempA[1]==hello


//----------- 004
int tem0 = 2 ,tem1 = 5;
txlmain.swap(tem0,tem1) ;
System.out.println("tem0=="+tem0+",tem1=="+tem1);//tem0==2,tem1==5


//----------- 005
int[] tempAI = new int[]{2,5} ;
txlmain.swap(tempAI) ;
System.out.println("tempAI[0]=="+tempAI[0]+",tempAI[1]=="+tempAI[1]);//tempAI[0]==5,tempAI[1]==2

//------------ 006
Integer tempI0 = new Integer(2) , tempI1 = new Integer(5) ;
txlmain.swap(tempI0,tempI1) ;
System.out.println("tempI0=="+tempI0+",tempI1=="+tempI1);//tempI0==2,tempI1==5


Integer[] tempIn = new Integer[]{new Integer(2),new Integer(5)};
txlmain.swap(tempIn) ;
System.out.println("tempIn[0]=="+tempIn[0]+",tempIn[1]=="+tempIn[1]);//tempIn[0]==5,tempIn[1]==2


String ta = "100" ;
String tb = new String("100") ;
String tc = "100" ;//常量池
System.out.println(ta==tb);//false
System.out.println(ta==tc);//true
System.out.println(tb==tc);//false

System.out.println(ta.equals(tb));//true
System.out.println(ta.equals(tc));//true
System.out.println(tb.equals(tc));//true

/// "equal" 与 "==" 的区别
// 比较unicode编码 与 比较地址 的区别 。


XlClass xlClass1 = new XlClass("深圳");
XlClass xlClass2 = new XlClass("广州");
txlmain.swap(xlClass1,xlClass2);
System.out.println("xlClass1="+xlClass1.getName()+",xlClass2="+xlClass2.getName());//xlClass1=深圳,xlClass2=广州


XlClass xlClass3 = new XlClass("深圳");
XlClass xlClass4 = new XlClass("广州");
txlmain.swap2(xlClass3,xlClass4);
System.out.println("xlClass3="+xlClass3.getName()+",xlClass4="+xlClass4.getName());


XlClass[] xlClass5 = new XlClass[]{new XlClass("深圳"),new XlClass("广州")} ;
txlmain.swap3(xlClass5);
System.out.println("xlClass5[0]="+xlClass5[0].getName()+",xlClass5[1]="+xlClass5[1].getName());


Integer[] tempITest1 = new Integer[]{new Integer(2),new Integer(5)};
Integer[] tempITest2 = new Integer[]{new Integer(6),new Integer(8)};
txlmain.swap2(tempITest1,tempITest2) ;


for(int m = 0 ; m < tempITest1.length ; m++){
System.out.println("tempITest1["+m+"]=" + tempITest1[m] );
System.out.println("tempITest2["+m+"]=" + tempITest2[m] );
}

}

//字符串的 swap ,
//Vector 的swap。

public void swap(){

int int1, int2 ;
String str1 , str2 ;
String[] strA = new String[2];
Vector vec1 = new Vector(), vec2 = new Vector() , vec3 = new Vector(), vec4 = new Vector() ;


int1 = 1 ;
int2 = int1 ;
int1 = 3 ;
System.out.println("int1="+int1+",int2="+int2);


str1 = "字符串1" ;
str2 = str1 ;
str1 = "改变字符串1" ;//效果就如 new一个新的。见vec3 = new Vector() ;
System.out.println("str1="+str1+",str2="+str2);


String str3 = "字符串3" ;
String str4 = "字符串4" ;
String tr ;
tr = str3;
str3 = str4 ;
str4 = tr ;
System.out.println("tr="+tr+",str3="+str3+",str4="+str4);


strA[0] = "字符数组1" ;
strA[1] = strA[0] ;
strA[0] = "改变字符数组1" ;
System.out.println("strA[0]="+strA[0]+",strA[1]="+strA[1]);


String[] strB = new String[]{"字符数组3","字符数组4"} ;
String sr ;
sr = strB[0] ;
strB[0] = strB[1] ;
strB[1] = sr ;
System.out.println("sr="+sr+",strB[0]="+strB[0]+",strB[1]="+strB[1]);


vec1.addElement("vector1") ;
vec2 = vec1 ;
vec1.setElementAt("改变vector1",0) ;
System.out.println("vec1[0]="+vec1.elementAt(0)+",vec2[1]="+vec2.elementAt(0));


vec3.addElement("vector3") ;
vec4 = vec3 ;
vec3 = new Vector() ;
vec3.addElement("新vector3") ;
System.out.println("vec3[0]="+vec3.elementAt(0)+",vec4[1]="+vec4.elementAt(0));


//【关键看 是否new了一个新的对象】

}


public void swap(String temp0_, String temp1_){

String str_temp ;

str_temp = temp0_ ;
temp0_ = temp1_ ;
temp1_ = str_temp ;

System.out.println("str_temp = " + str_temp );
System.out.println("temp0_ = " + temp0_ );
System.out.println("temp1_ = " + temp1_ );
}

public void swap(String[] tempA_){

String str_temp ;

str_temp = tempA_[0] ;
tempA_[0] = tempA_[1] ;
tempA_[1] = str_temp ;

System.out.println("str_temp = " + str_temp );
System.out.println("tempA_[0] = " + tempA_[0] );
System.out.println("tempA_[1] = " + tempA_[1] );

}

public void swap(int[] tempA_){

int temp ;

temp = tempA_[0] ;
tempA_[0] = tempA_[1] ;
tempA_[1] = temp ;

System.out.println("temp = " + temp );
System.out.println("tempA_[0] = " + tempA_[0] );
System.out.println("tempA_[1] = " + tempA_[1] );

}


public void swap(int k0 ,int k1){

int temp ;

temp = k0 ;
k0 = k1 ;
k1 = temp ;

System.out.println("temp = " + temp );
System.out.println("k0 = " + k0 );
System.out.println("k1 = " + k1 );

}

public void swap(Integer k0 ,Integer k1){

Integer temp ;

temp = k0 ;
k0 = k1 ;
k1 = temp ;

// k1.

System.out.println("Integer.temp = " + temp );
System.out.println("Integer.k0 = " + k0 );
System.out.println("Integer.k1 = " + k1 );

}

public void swap(Integer[] kI){

Integer temp ;

temp = kI[0] ;
kI[0] = kI[1] ;
kI[1] = temp ;

System.out.println("IntegerArray.temp = " + temp );
System.out.println("IntegerArray.kI[0] = " + kI[0] );
System.out.println("IntegerArray.kI[1] = " + kI[1] );

}

public void swap2(Integer[] kI1,Integer[] kI2){

Integer[] temp ;

temp = kI1 ;
kI1 = kI2 ;
kI2 = temp ;

for(int m = 0 ; m < kI1.length ; m++){
System.out.println("kI1["+m+"]=" + kI1[m] );
System.out.println("kI2["+m+"]=" + kI2[m] );
// System.out.println("temp["+m+"]=" + temp[m] );
}

}


public void swap(Object o1, Object o2){

Object temp ;
temp = o1 ;
o1 = o2 ;
o2 = temp ;

System.out.println("o1.name = " + ((XlClass)o1).getName() );
System.out.println("o2.name = " + ((XlClass)o2).getName() );
System.out.println("temp = " + ((XlClass)temp).getName() );

}

public void swap2(Object o1, Object o2){

Object temp ;
temp = o1 ;
o1 = o2 ;
o2 = temp ;

((XlClass)o1).setName("西瓜") ;
((XlClass)o2).setName("橘子") ;

System.out.println("o1.name = " + ((XlClass)o1).getName() );
System.out.println("o2.name = " + ((XlClass)o2).getName() );

}

public void swap3(Object o[]){

Object temp ;
temp = o[0] ;
o[0] = o[1] ;
o[1] = temp ;


System.out.println("o1.name = " + ((XlClass)o[0]).getName() );
System.out.println("o2.name = " + ((XlClass)o[1]).getName() );
System.out.println("temp = " + ((XlClass)temp).getName() );

}
//考察的 关于传参的问题。


}

class XlClass{

String name = "";

public XlClass(String name){
this.name = name ;
}
public void setName(String name_){
this.name = name_ ;
}
public String getName(){
return name ;
}
}


//输出结果 :


null
null
0
true
null
2
2
2
cd

int1=3,int2=1
str1=改变字符串1,str2=字符串1
tr=字符串3,str3=字符串4,str4=字符串3
strA[0]=改变字符数组1,strA[1]=字符数组1
sr=字符数组3,strB[0]=字符数组4,strB[1]=字符数组3
vec1[0]=改变vector1,vec2[1]=改变vector1
vec3[0]=新vector3,vec4[1]=vector3
str_temp = hello
temp0_ = world
temp1_ = hello
temp0==hello ,temp1==world
str_temp = hello
tempA_[0] = world
tempA_[1] = hello
tempA[0]==world ,tempA[1]==hello
temp = 2
k0 = 5
k1 = 2
tem0==2,tem1==5
temp = 2
tempA_[0] = 5
tempA_[1] = 2
tempAI[0]==5,tempAI[1]==2
Integer.temp = 2
Integer.k0 = 5
Integer.k1 = 2
tempI0==2,tempI1==5
IntegerArray.temp = 2
IntegerArray.kI[0] = 5
IntegerArray.kI[1] = 2
tempIn[0]==5,tempIn[1]==2
false
true
false
true
true
true
o1.name = 广州
o2.name = 深圳
temp = 深圳
xlClass1=深圳,xlClass2=广州
o1.name = 西瓜
o2.name = 橘子
xlClass3=橘子,xlClass4=西瓜
o1.name = 广州
o2.name = 深圳
temp = 深圳
xlClass5[0]=广州,xlClass5[1]=深圳
kI1[0]=6
kI2[0]=2
kI1[1]=8
kI2[1]=5
tempITest1[0]=2
tempITest2[0]=6
tempITest1[1]=5
tempITest2[1]=8

理论 : 按照blog里面的另一篇文章 方法参数传递

待续 .......................................... 07/10/30

你可能感兴趣的:(java,F#,Blog)