• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Evaluation and Execution problem.

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Friends,
This is what given in pg 66 of Simon Roberts:
" Although execution order is dertermined by preceedence and associativity , evaluation order of the arguments is not"
Question ID :952739436480:
The explanation in this jqplus question given was as under:
Here is what JLS says on this:
3 Evaluation Respects Parentheses and Precedence
problem: Does the senctence " Evaluation Respects Parentheses and Precedence " mean that Evaulation order is also dependent on preceedence ?
Thnaks in advance
Padmini
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Padmini
the first quote you give says that evaluation of the arguments is not determined by precedence or parenthesis.
Basically what it is saying is that in an expression all of the arguemnts are evaluated before any or the operations are performed. They are evaluated left to right.
Look at this, fragment:
int a=1, c=25, d=2, e=5, f=6;
int b = c * (a + c=2) / (d + e) - (f + c)
the values of a, c, d, e and f will all be determined before any of the operations are performed. Note the assignment in the middle: c=2. Because the operands are evaluated left to right the final expression looks like this:
int b = 25 * (1 + 2) / (2 + 5) - (6 + 2)
the first place c is used it has its original value of 25, then it is assigned the value of 2 and that is the value of it throughout the rest of the expression. Even though the parenthesis would lead you to think that the (a + c=2) wold be the first thing done.
The sentence that you quoted in the JLS is refering to the evaluation of the value of the expression as a whole, not the value of the operands.
hope that helps
Dave
[This message has been edited by Dave Vick (edited June 18, 2001).]
 
padmini Babu
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dave Vick:
[B]Padmini
Thanks Dave, That really helped.

reply
    Bookmark Topic Watch Topic
  • New Topic