• 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

Boolean expression

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
we are reading the excellent book Java2 Study guide for 310-035 but we have a little question about a boolean expression that is in there.
it says that with the following statement:

when y = 5, x = 2 and doStuff() always returns true, it will print nothing.
However in our mind it should evaluate to [BOLD]true[/BOLD]!
It says the runtime compiler would execute it like

Why??? Are there rules for the precedence of operators? Do the shortcircuit operator have a lower precedence than the boolean operators?
Have help would be appreciated.
Regards,
Robert Willems
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes
bitwise inclusive OR '| '
is higher in precedence.
Check this
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/expressions.html
Spec
 
Robert Willems
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks! that solves the whole problem ;-)
reply
    Bookmark Topic Watch Topic
  • New Topic