public class TestChar
{
public static void main(String[] args)
{
byte A = 1;
byte B = \u0041;
System.out.println(B);
}
}
The above code compiles and prints 1. But I noticed that if the value of �A�
(can vary from �128 to 127) changes, printed value of B also changes accordingly ie the printed value of B is exactly same as the value of variable �A�.
Actually B has Unicode value that represents character A (\u0041) & byte variable A is referring to value 1 & this is the value printed for variable B.
However if byte B is assigned Unicode value of numbers (0 to 9) ie from \u0030 to \u0039, it prints the no.s 0 to 9 correspondingly.
The same thing happens in following cases.
byte B =3;
byte x=\u0042; // as this represents Unicode value of letter B
System.out.pritln(x); //prints 3
byte Z=8;
byte x=\005A; // this represents Unicode value of Z
System.out.pritln(x); //prints 8
This is true for letters from A to Z with Unicode value ranging from \u0041 to \005A & a to z with Unicode values ranging from \0061 to \007A.
Why is this happening here?