• 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

Any good overview out there on logical operators precedence?

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everybody,

I have been searching online but was not able to find a good summary of how exactly the logical operators precedence works in the absence of parentheses in complex logical expressions (combining short-circuit and non-short-circuit and everything else). Does anybody know where I can find this kind of detailed info?

I have been running and testing all kinds of weird scenarios, but still cannot figure out exactly how the compiler knows where to put the *implicit* parentheses. Here is one ridiculous example...


In real life I would kill anybody who uses expressions as complex as this one, AND does not use parentheses. But I have the feeling that the SCJP expects us to know...

So is there any good overview resource where the compiler precedence determination for complex logical statements is well summarized and documented???
[ November 21, 2007: Message edited by: Marcus Jastrebowski ]
 
Marcus Jastrebowski
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm...

Or perhaps I should assume that the exam does not test the operator precedence any more -- as the "Exam Watch" box on page 278 in Sierra/Bates says? ... Just thinking out loud here...

Any feedback, ideas?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Google for "java operator precedence".

The Java Tutorials - Operators
 
Marcus Jastrebowski
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the link Jesper. I did google, but unsuccessfully. The table you are referring to does not even cover the non-short-circuit operators (| and &). And I am not sure if the precedence level of overloaded operations of "bitwise AND" and "bitwise inclusive OR" is the same as the non-short-circuit AND and OR logical operators.

Anybody else knows of any good comprehensive summary of short-circuit combined with non-short circuit behavior in complex logical expression in the absence of parentheses ?

Thanks much...
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Marcus,

The older versions of the exam really pounded on the details of precedence - the newer versions of the real exam have de-emphasized that topic (preferring parens), but a lot of mock exam writers haven't kept up with those changes on the real exam, so you can still find a lot of mocks that go way overboard on this type of question.

Howver, you should still be really clear about short circuits!

hth,

Bert
 
Marcus Jastrebowski
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Bert, I am sure that everybody is so glad to see the SCJP evolving to more closely represent the real life (on the job) situations...

Cheers,
Marcus
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Marcus Jastrebowski:
Thanks for the link Jesper. I did google, but unsuccessfully. The table you are referring to does not even cover the non-short-circuit operators (| and &). And I am not sure if the precedence level of overloaded operations of "bitwise AND" and "bitwise inclusive OR" is the same as the non-short-circuit AND and OR logical operators.


Hmmm, you're right, the boolean & and | are not included in that table. Have a look at this one: http://www.uni-bonn.de/~manfear/javaoperators.php
 
Marcus Jastrebowski
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They do not like me over there Apparently, I can't get there from here:

Access forbidden!

You don't have permission to access the requested object on this server. Either you tried to access a directory that contains no index document or the specified object isn't readable.

In case you think this is a server error, please contact the Webmaster.

Error 403

RHRZ-Universitaet Bonn,
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here you have another table.
 
Marcus Jastrebowski
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Awesome! Thank you Jan.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic