• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Order of Operators Precedence

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am looking at the Operator Precedence table on Oracle's website: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html.

Their table labels &, ^, | as bitwise and &&, || as logical, whereas the table on page 52-53 in my OCA book labels  &, ^, | as logical and &&, || as short-circuit. Are these terms interchangeable?

Oracle's table also lists bitwise & as having greater precedence than ^ which has greater precedence as | which has greater precedence as logical && which has greater precedence as ||.
Do I evaluate & before ^ (and so on) no matter its order in the expression?

Thanks!
 
Saloon Keeper
Posts: 13248
291
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, the terms are not interchangeable. However, &, ^ and | are overloaded for both bitwise and logical operations. When used as logic operators (meaning, with boolean operands), they don't short-circuit.
 
author
Posts: 23907
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

AngelinaJeana Brown wrote:
Oracle's table also lists bitwise & as having greater precedence than ^ which has greater precedence as | which has greater precedence as logical && which has greater precedence as ||.
Do I evaluate & before ^ (and so on) no matter its order in the expression?



Precedence and Evaluation Order are two separate concepts. Evaluation order is defined by Section 15.7 of the Java Language Specification, and basically, goes from left to right.

Henry
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This topic is an absolute must-read to learn everything you need to know about operator precedence and evaluation order.
 
AngelinaJeana Brown
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic