J2EEOnline J2EE

Java Certification  «Prev  Next»
Lesson 8 Determining order of evaluation
ObjectiveDescribe how operator precedence and associativity is used.

Order of evaluation

Describe how operator precedence and associativity is used to determine the order in which expressions are evaluated.
The order of evaluation of Java expressions is dependent on the precedence and associativity of the operators used in the expression, and the use of parentheses. In general, the operands of expressions are evaluated in a left-to-right order before any operations are performed. The exceptions to this are expressions involving the &&, ||, and ternary operators.
Once an expression's operands are evaluated, the operators are applied according to operator precedence and associativity. The assignment operator is the only right-associative binary operator. Parentheses can be used to change the ordering imposed by precedence and associativity.
The following table shows the precedence of Java's operators. Higher-level operators take precedence over lower-level operators.
Operators at the same level are evaluated based on the order they appear and their associativity.
  1. Order of evaluation: The order in which expressions are evaluated.
  2. Precedence: The order in which operations are performed.

Operator precedence table
Operator precedence table
The following link contains a detailed description of Java operators and their precedence.
Java Operator Precedence
The Precedence program provides an example of how complex expressions are evaluated.