Java Reference
InDepth Information
thelatterassignmentbecausenoinformationislostwhenJavaconvertsfromatypewith
a smaller set of values to a type with a wider set of values.
Javasupportsthefollowingprimitivetypeconversionsviawideningconversionrules:
• Byteintegertoshortinteger,integer,longinteger,floatingpoint,ordoublepre
cision floatingpoint
• Short integer to integer, long integer, floatingpoint, or double precision
floatingpoint
• Character to integer, long integer, floatingpoint, or double precision floating
point
• Integer to long integer, floatingpoint, or double precision floatingpoint
• Long integer to floatingpoint or double precision floatingpoint
• Floatingpoint to double precision floatingpoint
Note
When converting from a smaller integer to a larger integer, Java copies the
smaller integer's sign bit into the extra bits of the larger integer.
Chapter2
discussesthewideningconversionrulesforperformingtypeconversionsin
the context of userdefined and array types.
Compound Expressions
A
compound expression
isasequenceofsimpleexpressionsandoperators,wherean
op
erator
(asequenceofinstructionssymbolicallyrepresentedinsourcecode)transforms
its
operand
expressionvalue(s)intoanothervalue.Forexample,
6
isacompoundex
pression consisting of operator

and integer literal
6
as its operand. This expression
transforms
6
intoitsnegativeequivalent.Similarly,
x+5
isacompoundexpressioncon
sisting ofvariable name
x
,integer literal
5
,andoperator
+
sandwiched between these
operands. Variable
x
's value is fetched and added to
5
when this expression is evalu
ated. The sum becomes the value of the expression.
Note
If
x
's type is byte integer or short integer, this variable's value is widened
to an integer. However, if
x
's type is long integer, floatingpoint, or double precision
floatingpoint,
5
is widened to the appropriate type. The addition operation is per
formed after the widening conversion takes place.
Javasuppliesawidevarietyofoperatorsthatareclassifiedbythenumberofoperands
theytake.A
unary operator
takesonlyoneoperand(unaryminus[

]isanexample),a
binary operator
takestwooperands(addition[
+
]isanexample),andJava'ssingle
tern
ary operator
(conditional [
?:
]) takes three operands.