• Post Reply Bookmark Topic Watch Topic
  • New Topic

short circuiting in java (was: hi)  RSS feed

 
Dhivya rajagopal
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone, can you please tell about short circuiting in java

[jc edit: changed the title of your post]
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have come across code which does this- We could discuss it. Basically its used to avoid extra evaluations in Boolean expressions.

And as mentioned earlier- A meaningful subject line would draw the attention of other members and would help you in getting your query answered at the earliest.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wasn't sure what you meant by "short-circuiting"; you mean the short-circuit operators.
In the case of && and ||, you can sometimes tell the value of the entire expression by evaluating its left half, so false && ... always evaluates to false, and true || ... always evaluates to true. So the JVM only evaluates the left half of the whole expression in those cases.
In the case of true && ... or false || ..., the JVM must evaluate the right half as well.
 
Jan Cumps
Bartender
Posts: 2632
17
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's explained in an understandable way at WikiPedia.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!