Because in the second line, Character.MAX_VALUE
is concatenated with the String.
As the JLS states:
The string concatenation operator + (§15.18.1), which, when given a String operand and an integral operand, will convert the integral operand to a String representing its value in decimal form, and then produce a newly created String that is the concatenation of the two strings
As Character.MAX_VALUE
is not printable, you don't see it.
In the third case, your doing a substraction with an int
, thus the whole expression is casted to int
and it prints an int
value.
Also as the JLS states:
The binary + operator performs addition when applied to two operands of numeric type, producing the sum of the operands.
[...]
Binary numeric promotion is performed on the operands (§5.6.2).
When an operator applies binary numeric promotion to a pair of operands, each of which must denote a value that is convertible to a numeric type, the following rules apply, in order:
[...]
Widening primitive conversion (§5.1.2) is applied to convert either or both operands as specified by the following rules:
If either operand is of type double, the other is converted to double.
Otherwise, if either operand is of type float, the other is converted to float.
Otherwise, if either operand is of type long, the other is converted to long.
Otherwise, both operands are converted to type int.
If you've done
System.out.println("Character Max Value: "+(Character.MAX_VALUE+0));
It would print Character Max Value: 65535