Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

short circuit logical operands

 
Libania Paes
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I couldn�t find anywhere in the book Java 2 Sun Certified Programmer from Osborne something about short circuit operands.
What are they?

Thanks!!!
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
&& and || .
Probably not everyone calls them "short-circuit" operators.
 
Libania Paes
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Ron!
But there�s a question before mine that says:

Please explain about & and |. Can some one run through the following example.
public class ShortCkt {
public static void main(String args[]) {
int i = 0;
boolean t = true;
boolean f = false, b;
b = (t & ((i++) == 0));
b = (f & ((i+=2) > 0));
System.out.println(i);
}
}

& and | are Bitwise operators only, right??
Thanks again!
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
& and | are both bit-wise operators and boolean operators. However, when they are boolean operators, both operands are always evaluated first.
^ is also both a bit-wise operator and a boolean operator.
[ August 16, 2002: Message edited by: Ron Newman ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic