my friend tried to print out a char variable without initialization. However, instead of showing up nothing, the screen showed up a letter 'a'.
and I asked him to initialized that variable like char c= '\u0000' and print it out again. But, it is still showing up as a letter 'a'.
however when he compared char c with real letter 'a', the result is false.
the code is
class Char_a
{
public static void main(String[] args)
{
char [] c=new char [5];
for (int x=0 ; x<=4 ; x++ )
{
System.out.println("c["+x+"]="+c[x]);
}
char [] c2= {'\u0000'};
System.out.println("c2[0]="+c2[0]);
System.out.println("c2[0]==c[0]"+(c2[0]==c[0]));
System.out.println("'a'==c[0]"+('a'==c[0]));
}
}
his java version is 1.8.0_40 Jave (TM) SE Runtime Environment (build 1.8.0_40-b26) Java HotSpot (TM) 64 -Bit Server VM (build 25.40 -b25. mixed mode)
my friend just curious about why his char default value is showing up like letter 'a' even it is not same as the real letter 'a'.
and this is what he sees in his computer (Q.Q I cant post a picture..
but his result is kind of like
c[0]=a
c[1]=a
c[2]=a
c[3]=a
c[4]=a
c2[0]=a
c2[0]==c[0] true
'a' == c[0] false
and this is in my computer which is what you suppose to see
c[0]=
c[1]=
c[2]=
c[3]=
c[4]=
c2[0]=
c2[0]==c[0] true
'a' == c[0] false