Skip to main content

Posts

Showing posts from August, 2020

Appendix A: Operator Precedence in Java

  Appendix A: Operator Precedence in Java Java has well-defined rules for specifying the order in which the operators in an expression are evaluated when the expression has several operators. For example, multiplication and division have a higher precedence than addition and subtraction. Precedence rules can be overridden by explicit parentheses. Precedence order.  When two operators share an operand the operator with the higher  precedence  goes first. For example, 1 + 2 * 3 is treated as 1 + (2 * 3), whereas 1 * 2 + 3 is treated as (1 * 2) + 3 since multiplication has a higher precedence than addition. Associativity.  When an expression has two operators with the same precedence, the expression is evaluated according to its  associativity . For example  x = y = z = 17  is treated as  x = (y = (z = 17)) , leaving all three variables with the value 17, since the  =  operator has right-to-left associativity (and an assignment statement evaluates to the value on the right hand side). On