occursbecause the value of those arguments is not needed to allocate memory for the objectin which case
those arguments won't be evaluated. In contrast, when an array is created, the array dimension expressions
must be evaluated first to find out how much memory to allocateconsequently, array creation throws the
OutOfMemoryError after the dimension expressions are evaluated.
9.3.2. Expression Type
Every expression has a type. The type of an expression is determined by the types of its component parts and
the semantics of operators.
If an arithmetic or bit manipulation operator is applied to integer values, the result of the expression is of type
int unless one or both sides are long, in which case the result is long. The exception to this rule is that the
type of shift operator expressions are not affected by the type of the right-hand side. All integer operations are
performed in either int or long precision, so the smaller byte and short integer types are always
promoted to int before evaluation.
If either operand of an arithmetic operator is floating point, the operation is performed in floating-point
arithmetic. Such operations are done in float unless at least one operand is a double, in which case
double is used for the calculation and result.
A + operator is a String concatenation when either operand to + is of type String or if the left-hand side
of a += is a String.
When used in an expression, a char value is converted to an int by setting the top 16 bits to zero. For
example, the Unicode character \uffff would be treated as equivalent to the integer 0x0000ffff. This
treatment is different from the way a short with the value 0xffff would be treatedsign extension makes
the short equivalent to -1, and its int equivalent would be 0xffffffff.
The above are all examples of different type conversions that can occur within an expression, to determine the
type of that expression. The complete set of conversions is discussed next.
9.4. Type Conversions
The Java programming language is a strongly typed language, which means that it checks for type
compatibility at compile time in almost all cases. Incompatible assignments are prevented by forbidding
anything questionable. It also provides cast operations for times when the compatibility of a type can be
determined only at run time, or when you want to explicitly force a type conversion for primitive types that
would otherwise lose range, such as assigning a double to a float. You learned about type compatibility
and conversion for reference types on page 90. In this section you will learn about conversions as a whole, for
both primitive and reference types, and the contexts in which those conversions are automatically applied.
9.4.1. Implicit Type Conversions
Some kinds of conversions happen automatically, without any work on your partthese are implicit
conversions.
Any numeric value can be assigned to any numeric variable whose type supports a larger range of valuesa
widening primitive conversion. A char can be used wherever an int is valid. A floating-point value can be
assigned to any floating-point variable of equal or greater precision.