The ASCII value of a is 97.
When i = 0, i + 'a' = 0 + 97 => When cast into char, it will be a
When i = 1, i + 'a' = 1 + 97 => When cast into char, it will be b
When i = 2, i + 'a' = 2 + 97 => When cast into char, it will be c
...and so on
Answer from Arvind Kumar Avinash on Stack OverflowThe ASCII value of a is 97.
When i = 0, i + 'a' = 0 + 97 => When cast into char, it will be a
When i = 1, i + 'a' = 1 + 97 => When cast into char, it will be b
When i = 2, i + 'a' = 2 + 97 => When cast into char, it will be c
...and so on
Java char is a 16-bit integral type. 'a' is the same as 97, which you can see with System.out.println((int) 'a'); - it follows that 98 is 'b' and so on across the entire ASCII table.
In Java, char is a numeric type. When you add 1 to a char, you get to the next unicode code point. In case of 'A', the next code point is 'B':
char x='A';
x+=1;
System.out.println(x);
Note that you cannot use x=x+1 because it causes an implicit narrowing conversion. You need to use either x++ or x+=1 instead.
char is a numeric type (2 bytes long), and is also the only unsigned numeric primitive type in Java.
You can also do:
int foo = 'A';
What is special here is that you initialize the char with a character constant instead of a number. What is also special about it is its string representation, as you could witness. You can use Character.digit(c, 10) to get its numeric value (as an int, since 2 ^ 16 - 1 is not representable by a short!).