Java Expressions

Expressions are evaluated strictly left-to-right. For example, x + y + z is evaluated in the following order.

This order of evaluation is guaranteed. This can matter when the operands are results returned by embedded function calls.

The type of the result of an expression evaluation is determined as follows:

  int   +  int    =  int
  int   +  long   =  long

  float +  int    =  float
  float +  long   =  float

  float +  float  =  float
  float +  double =  double
where + represents any arithmetic or bit-wise operator.
  string  +   any type  =  string
  string  +=  any type  =  string
Any interger type less than 32 bits long is promoted to a 32-bit int before it takes part in the evaluation of an expression as follows:
byte:     top 24 bits filled with the value of the sign bit
short:    top 16 bits filled with the value of the sign bit
char:     top 16 bits set to zero

This page's parent within this Web Site. About this Web Site. Its home page. Email its Author.