Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chapter 2 page 59 (Sybex OCA Java 8 Study Guide)

 
Victoria Nicholls
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. According to the order of precedence, first we have to evaluate post-unary operations. Why it first starts to evaluate operators from left-to-right, not paying attention to operators' precedence?

P.S. Thank You for answers .
Order of operator precedence.PNG
[Thumbnail for Order of operator precedence.PNG]
This snippet of table illustrates that post-unary operators have greater precedence than pre-unary
operators.PNG
[Thumbnail for operators.PNG]
Chapter 2 page 59 example
operators (mine).PNG
[Thumbnail for operators (mine).PNG]
My evaluation
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Viktorija Nekrasaite,

First of all, a warm welcome to CodeRanch!

Viktorija Nekrasaite wrote:Hi. According to the order of precedence, first we have to evaluate post-unary operations. Why it first starts to evaluate operators from left-to-right, not paying attention to operators' precedence?

The study guide is spot-on! And your proposed changes are wrong. Why? That's well explained (with additional code snippets) in this thread.

Hope it helps!
Kind regards,
Roel
 
Victoria Nicholls
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You. It was really helpful ;).
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Viktorija Nekrasaite wrote:Could You tell me why the precedence in the table 2.1 is as it is?

Because that's the precedence of operators in Java. If you look at Oracle's Java tutorials, you'll find a table which is very similar to the one in the study guide. But that's not enough to decide the order of evaluation/execution of a statement in Java! This thread is definitely a must read: it has an in-depth discussion (with many code snippets) about the different concepts used to determine how a given expression is evaluated.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic