Dec 8, 2010

Short Circuit Operators

&& and || are called short circuit operators. These operators are used for "AND" and "OR" operation respectively.
Ex.
if(a && b), Suppose if  a is false, it wont even check the value of b, it skip the condition itself. Take an another example:
if(refVal!=null && refVal.isValid() ) ,
 in this consider refVal is the reference variable and it has not been assigned to any object, so the value of refVal=null, so if its checking refVal.isValid(), it will throw the NullPointerException. Since, the first condition is false, it skips the second condition.

No comments:

Post a Comment

Post a Comment

Note: Only a member of this blog may post a comment.