In an expression
that contains multiple operators, Java uses a number of rules to
decide the order in which the operators are evaluated. The first
and most important rule is called operator precedence.
Operators in an expression that have higher precedence are executed
before operators with lower precedence. For example, multiplication
has a higher precedence than addition. In the expression 2+3*4,
the multiplication is done before the addition, producing a result
of 14.
If consecutive operators in an expression have
the same precedence, a rule called associativity is
used to decide the order in which those operators are evaluated.
An operator can be leftassociative, rightassociative, or nonassociative:
Table 42 shows the precedence
and associativity of all the operators
in Java.[7]
Table 4.2: Precedence and Associativity of Operators in Java
Precedence 
Operator 
Associativity 
1 
(), [] 
nonassociative 
2 
new 
nonassociative 
3 
. 
leftassociative 
4 
++,   
nonassociative 
5 
 (unary), + (unary),
!, ~, ++,
 ,
(type) 
rightassociative 
6 
*, /,
% 
leftassociative 
7 
+,  
leftassociative 
8 
<<, >>,
>>> 
leftassociative 
9 
<, >,
<=, >=,
instanceof 
nonassociative 
10 
==, != 
leftassociative 
11 
& 
leftassociative 
12 
^ 
leftassociative 
13 
 
leftassociative 
14 
&& 
leftassociative 
15 
 
leftassociative 
16 
?: 
rightassociative 
17 
=, *=,
/=,
%=, =, <<=,
>>=, >>>=,
&=, ^=, = 
rightassociative 
As in C/C++, the order in which operators
are evaluated can be modified by the use of parentheses.
The
rest of the rules that concern order of operations have to do with
the evaluation of operands or arguments in a single expression.
 The left operand of a binary operator is evaluated
before its right operand.
 The operands of an operator
are evaluated before the operator is evaluated. Consider the following
expression:
First, the left
operand of * is evaluated; it produces the
value 4. Then the right operand of *
is evaluated. Since evaluation of the left operand
set x to 4, evaluation of the right operand
produces 4. Finally, the * operator itself is
evaluated, producing the value 16.
 In an index expression, the expression to the
left of the square brackets is evaluated before the expression inside
the square brackets.
 In an expression that calls a method
through an object reference, the object reference is evaluated before
the argument expressions.
 In any expression that calls
a method or constructor, the expressions supplied as the actual
arguments are evaluated from left to right.
 In an array
allocation expression, the expressions that appear in square brackets
and provide the dimensions of the array are evaluated from left
to right.
The intent of all of these rules is to guarantee
that every implementation of Java evaluates any given expression
in the same way.[8]
In order to produce optimized code,
a Java compiler is allowed to deviate from the rules governing the
order in which operations are performed, provided that the result
is the same as if it had followed the rules.
References
Array Allocation Expressions;
Index Expressions;
Method Call Expression;
Object Allocation Expressions

