Language Random: Java's Type Promotion Rules
Another interesting thing I learned about Java!:O
When Java evaluates an expression, Java promotes the different types within the expression so that they are all converted to the same type. The rules explained briefly in "Java A Beginner's Guide" by Herber Schildt:
First, all char, byte, and short values are promoted to int. Then, if one operand is a long, the whole expression is promoted to long. If one operand is a float operand, the entire expression is promoted to float. If any of the operands is double, the result is double.
byte_var = byte_var * byte_var;
This will create a compile time error. To fix this you have to cast the result of the expression to match the type of the variable it will be assigned to, like this:
byte_var = (byte)(byte_var * byte_var);