title: Precedence of ++ and -- operators in Java
body: <p>I read from the official tutorial of Java that prefix and postfix ++ -- have different precedences:</p>
  
  <blockquote>
    <p>postfix:  expr++ expr--</p>
    
    <p>unary:    ++expr --expr +expr -expr ~ !</p>
  </blockquote>
  
  <p><a href="http://download.oracle.com/javase/tutorial/java/nutsandbolts/operators.html" rel="nofollow">Operators</a></p>
  
  <p>According to the tutorial, shouldn't this</p>
  
  <p><code>d = 1; System.out.println(d++ + ++d);</code></p>
  
  <p>print out 6 (<code>d++</code> makes d 2, <code>++d</code> makes it 3) instead of 4?</p>
  
  <p>I know the explanation of <code>++d</code> being evaluated beforehand, but if <code>d++</code> has higher precedence then <code>++d</code>, why isn't <code>d++</code> being first evaluated? And what is more, in what case should <code>d++</code> shows that it has higher precedence?</p>
  
  <p>EDIT:</p>
  
  <p>I tried the following:</p>
  
  <p><code>d = 1; System.out.println(++d * d++);</code></p>
  
  <p>It returns 4. It seems that it should be 2*2, instead of 1*3.</p>