I'll try to answer this with some references, so that you can go into whatever depth you want. It's not entirely clear what is confusing you.

Firstly, you need to be clear on the difference between assignment operators (= in your examples, but these also include e.g. += etc) and other (binary) operators (e.g. +,-,*,% etc). Assignment operators (such as =) evaluate right to left - i.e. they work out the value of everything on the right of the operator and then assign it to whatever is on the left.

For other operators, they first apply operator precedence and then apply left to right operation on operators with equal precedence. A table of precedence and discussion of this is available in the official tutorial. It is very similar to the table (Fig A.1) on p.1509 of the book you are using, but the web tutorial explanation may be easier to understand. It can be summed up as precedence being applied as expressions in brackets first, followed by postfix then unary operators (e.g. x++, then -x), then multiplicative operators (*,\,%) and then additive (+,-) and finally lots of logical operators that are not directly relevant to this question.

Finally, the tutorial contains the statement

When operators of equal precedence appear in the same expression, a rule must govern which is evaluated first. All binary operators except for the assignment operators are evaluated from left to right; assignment operators are evaluated right to left.

Crucially, the precedence then left-to-right evaluation will be repeated, most easily illustrated by going through your example step by step:

(4 * 4) + (8 * 8) * (4 * 4) - 16/4
// Found brackets - highest precedence.
// more than one, so evaluate left to right
16 + (8 * 8) * (4 * 4) - 16/4
16 + 64 * (4 * 4) - 16/4
16 + 64 * 16 - 16/4
//brackets finished, back to precedence.  Found multiplicative operators
//evaluate left to right
16 + 1024 - 16/4
16 + 1024 - 4
//multiplicative finished, back to precedence.  Found additive operators
//evaluate left to right
1040 - 4
1036
// Expression fully evaluated. Can now be used / assigned to a variable

Addendum

The definitive specification for the evaluation of expressions is in the Java Language Specification chapter 15. It's probably more confusing than helpful at this level, but I include it for completeness. Section 15.7.3 deals with respecting brackets (parantheses) around expressions and operator precedence.

Answer from J Richard Snape on Stack Overflow
🌐
Princeton CS
introcs.cs.princeton.edu › java › 11precedence
Appendix A: Operator Precedence in Java
Associativity and precedence determine in which order Java groups operands and operators, but it does not determine in which order the operands are evaluated. In Java, the operands of an operator are always evaluated left-to-right. Similarly, argument lists are always evaluated left-to-right.
🌐
Programiz
programiz.com › java-programming › operator-precedence
Java Operator Precedence
In Java, the precedence of * is higher than that of -. Hence, the multiplication is performed before subtraction, and the value of myInt will be 4. The table below lists the precedence of operators in Java; higher it appears in the table, the higher its precedence.
🌐
Scaler
scaler.com › home › topics › operator precedence in java
Operator Precedence in Java - Scaler Topics
May 4, 2023 - Explanation The precedence of the assignment operator = is the least, and equal to the operator (==) is left to right-associative. ... Explanation The above code results in a compile-time error because Java parses the statement as ++(++x) and ...
🌐
UW Computer Sciences
pages.cs.wisc.edu › ~willb › cs302 › java-operator-precedence.pdf pdf
Operator Precedence in the Java™ Programming Language
May 4, 2023 - operator, indicating which is to · be performed first. In the case of · Java, multiplication takes · precedence over addition; therefore, x will get the value 19. For arithmetic expressions, multiplication and division are · evaluated before addition and ·
🌐
Oracle
docs.oracle.com › javase › tutorial › java › nutsandbolts › operators.html
Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)
Operators with higher precedence are evaluated before operators with relatively lower precedence. Operators on the same line have equal precedence. When operators of equal precedence appear in the same expression, a rule must govern which is evaluated first.
🌐
GeeksforGeeks
geeksforgeeks.org › java › operator-precedence-and-associativity-in-java
Operator Precedence and Associativity in Java - GeeksforGeeks
July 31, 2025 - For example, in the expression ... (a + b) - c. Operators with left-to-right associativity include: Arithmetic operators: +, -, *, /, % Relational operators: >, <, >=, <= Logical AND/OR: &&, || Bitwise operators: &, |, ^, <<, ...
Top answer
1 of 2
2

I'll try to answer this with some references, so that you can go into whatever depth you want. It's not entirely clear what is confusing you.

Firstly, you need to be clear on the difference between assignment operators (= in your examples, but these also include e.g. += etc) and other (binary) operators (e.g. +,-,*,% etc). Assignment operators (such as =) evaluate right to left - i.e. they work out the value of everything on the right of the operator and then assign it to whatever is on the left.

For other operators, they first apply operator precedence and then apply left to right operation on operators with equal precedence. A table of precedence and discussion of this is available in the official tutorial. It is very similar to the table (Fig A.1) on p.1509 of the book you are using, but the web tutorial explanation may be easier to understand. It can be summed up as precedence being applied as expressions in brackets first, followed by postfix then unary operators (e.g. x++, then -x), then multiplicative operators (*,\,%) and then additive (+,-) and finally lots of logical operators that are not directly relevant to this question.

Finally, the tutorial contains the statement

When operators of equal precedence appear in the same expression, a rule must govern which is evaluated first. All binary operators except for the assignment operators are evaluated from left to right; assignment operators are evaluated right to left.

Crucially, the precedence then left-to-right evaluation will be repeated, most easily illustrated by going through your example step by step:

(4 * 4) + (8 * 8) * (4 * 4) - 16/4
// Found brackets - highest precedence.
// more than one, so evaluate left to right
16 + (8 * 8) * (4 * 4) - 16/4
16 + 64 * (4 * 4) - 16/4
16 + 64 * 16 - 16/4
//brackets finished, back to precedence.  Found multiplicative operators
//evaluate left to right
16 + 1024 - 16/4
16 + 1024 - 4
//multiplicative finished, back to precedence.  Found additive operators
//evaluate left to right
1040 - 4
1036
// Expression fully evaluated. Can now be used / assigned to a variable

Addendum

The definitive specification for the evaluation of expressions is in the Java Language Specification chapter 15. It's probably more confusing than helpful at this level, but I include it for completeness. Section 15.7.3 deals with respecting brackets (parantheses) around expressions and operator precedence.

2 of 2
1

Usually, the code is always read from left to right, but also follows the math precedence. Example:

(4 * 4) + (8 * 8) * (4 * 4) - 16/4

Math says in this case: Parentheses first, multiplication and division after, and then addition and subtraction. Then:

//Parenthesis done
(16) + (64) * (16) - 16/4

//Multiplication and division done
16 + 1024 - 4

//Addition and subtraction done
1036
🌐
O'Reilly
oreilly.com › library › view › javatm-how-to › 9780133813036 › ch02lev2sec26.html
Rules of Operator Precedence - Java™ How To Program (Early Objects), Tenth Edition [Book]
February 24, 2014 - Rules of Operator Precedence Java applies the operators in arithmetic expressions in a precise sequence determined by the rules of operator precedence, which are generally the same... - Selection from Java™ How To Program (Early Objects), Tenth Edition [Book]
Authors   Paul DeitelHarvey Deitel
Published   2014
Pages   1248
Find elsewhere
🌐
Tutorialspoint
tutorialspoint.com › java › java_operator_precedence_and_associativity.htm
Java Operator Precedence and Associativity
The operator precedence determines the grouping of terms in an expression. This affects how an expression is evaluated. Certain operators have higher precedence than others; for example, the multiplication operator has higher precedence than ...
🌐
W3Schools
w3schools.com › java › java_operators_precedence.asp
Java Operator Precedence
February 24, 2014 - Java Examples Java Videos Java ... Q&A Java Certificate ... When a calculation contains more than one operator, Java follows order of operations rules to decide which part to calculate first....
🌐
Saylor Academy
learn.saylor.org › mod › book › view.php
Java Data and Operators: Operator Precedence | Saylor Academy | Saylor Academy
Table 5.6 Precedence order of the arithmetic operators · Parenthesized expressions have highest precedence and are evaluated first. Next come the multiplication, division, and modulus operators, followed by addition and subtraction.
🌐
PW Skills
pwskills.com › blog › java developer › java operator precedence
Java Operator Precedence: Order Of Operations With Examples
November 12, 2025 - In int x = y = 10;, Java first assigns 10 to y, and then assigns the value of y to x. Let’s see how a Java Developer would look at this line: ... We can understand exactly how the machine gets the final answer by looking at the table of Java operator precedence and associativity. ... Arithmetic precedence (* before +) int a = 2 + 3 * 4; Java applies multiplication first, so it becomes 2 + 12, and a ends up as 14.
🌐
Dremendo
dremendo.com › java-programming-tutorial › java-operator-precedence
Operator Precedence in Java Programming | Dremendo
Operator Precedence in Java programming is a rule that describes which operator is solved first in an expression. For example, * and / have the same precedence, and their associativity is, Left to Right.
🌐
StudySmarter
studysmarter.co.uk › java arithmetic operators
Java Arithmetic Operators: Examples & Order | StudySmarter
Java Arithmetic Operators: Symbols used for basic arithmetic operations (addition, subtraction, multiplication, division) in Java programs. Order of Precedence: Operators are evaluated in this order: Parentheses, Multiplication, Division, Modulo, Addition, and Subtraction.
🌐
Javatpoint
javatpoint.com › java-operator-precedence
Java Operator Precedence - Javatpoint
Java Operator Precedence with java tutorial, features, history, variables, object, programs, operators, oops concept, array, string, map, math, methods, examples etc.
Top answer
1 of 8
13

Almost everybody so far has confused order of evaluation with operator precedence. In Java the precedence rules make the expression equivalent to the following:

a + (b  * c) / ( d - e )

because * and / have equal precedence and are left associative.

The order of evaluation is strictly defined as left hand operand first, then right, then operation (except for || and &&). So the order of evaluation is:

  a
      b
      c
    *
      d
      e
    -
  /
+

order of evaluation goes down the page. Indentation reflects the structure of the syntax tree

Edit

In response to Grodriguez's comments. The following program:

public class Precedence 
{
    private static int a()
    {
        System.out.println("a");
        return 1;
    }   
    private static int b()
    {
        System.out.println("b");
        return 2;
    }
    private static int c()
    {
        System.out.println("c");
        return 3;
    }
    private static int d()
    {
        System.out.println("d");
        return 4;
    }
    private static int e()
    {
        System.out.println("e");
        return 5;
    }

    public static void main(String[] args) 
    {
        int x = a() + b() * c() / (d() - e());
        System.out.println(x);
    } 
}

Produces the output

a
b
c
d
e
-5

which clearly shows the multiplication is performed before the subtraction.

2 of 8
13

As JeremyP has nicely shown us, the first answer is correct.

In general, the following rules apply:

  • Every operand of an operator is evaluated before the operation itself is performed (except for ||, &&, and ? :)
  • Operands are evaluated left to right. The left-hand operand of a binary operator appears to be fully evaluated before any part of the right-hand operand is evaluated.
  • The order of evaluation respects parentheses and operator precedence:
    • Parentheses are evaluated first.
    • Operators are evaluated in order of precedence.
    • Operators with equal precedence are evaluated left-to-right, except for assignment operators which are evaluated right-to-left.

Note that the first two rules explain the result in your second question:

int i = 2;
System.out.println(i * (i=3)); // prints '6'
int j = 2;
System.out.println((j=3) * j); // prints '9'

Reference documentation:

http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#4779

Tutorial:

http://download.oracle.com/javase/tutorial/java/nutsandbolts/operators.html