Operator Precedence (Computer Programming)
Operator Precedence is the order that a set of operators will execute. Operators with higher precedence are evaluated before operators with a relatively lower precedence. When operators with same precedence found, all binary operators except for the assignment operators are evaluated in the left to right order. Assignment operators are evaluated right to left.
Parenthesis, square brackets or dots may use to change the default precedence of operators. Parenthesis is used to alter the precedence of al operation. It can be use to help clarify the meaning of an expression.
The precedence of the Java operators as follows.
Therefore following statement evaluations will give:
i. ++4 + ++4 => 10
ii. 5-- + 5-- =>10
iii. (5*4)/2 = 10
iv. 5 + 8 + 2 * 2 = 17
v. (5 + 8 + 2)*2 = 30
vi. 5 + 6 -11 + 8 * 5 + 4 = 44