Typically for local variables I initialize them as late as I can. It's rare that I need a "dummy" value. However, if you do, you can use any value you like - it won't make any difference, if you're sure you're going to assign a value before reading it.
If you want the char equivalent of 0, it's just Unicode 0, which can be written as
char c = '\0';
That's also the default value for an instance (or static) variable of type char.
Apologies as I come from Python, but the Char datatype seems extremely pointless...
I'm just starting to learn Java, so can you shed some light on this?
Typically for local variables I initialize them as late as I can. It's rare that I need a "dummy" value. However, if you do, you can use any value you like - it won't make any difference, if you're sure you're going to assign a value before reading it.
If you want the char equivalent of 0, it's just Unicode 0, which can be written as
char c = '\0';
That's also the default value for an instance (or static) variable of type char.
Either you initialize the variable to something
char retChar = 'x';
or you leave it automatically initialized, which is
char retChar = '\0';
an ascii 0, the same as
char retChar = (char) 0;
What can one initialize char values to?
Sounds undecided between automatic initialisation, which means, you have no influence, or explicit initialisation. But you cannot change the default.
In Java, chars have a direct mapping to ints by UTF-16. For most common characters, though, casting a char value to an int yields its index on the ascii table. + isn't an operation on chars, but it is an operation for ints. Therefore, java is taking the 2 and after thinking "I can't add this", realizes it can add it if it casts it to an int.
As you can see in the table, '2' has a index of 50, thus 1 + 50 + 3 = 54.
Characters are, in fact, numbers. Computer transforms a char into an integer using a character set (charset). Charsets are tables which bind specified character to the specified integer, so your computer can transform it to binary and store it in memory. Later when needed, that number can get transformed back to character. Your compiler uses Unicode (a superset of ASCII, thanks Tom Blodget), so character '2' is actually decimal integer 50 (more info: http://unicode-table.com/en/, note that table uses hex numbers, so hex 32 is decimal 50). Since addition by default returns an integer, the character gets transformed and added, but never actually transformed back to its original form.
As for why it gives in error, it's probably because Java differs between types and your compiler (or whatever's throwing the error) is more strict. Don't take my word for that, you should probably look in the standard and your implementation. In C for example, that addition would always succeed.
Hope it clears things up a bit.