Home           J2EE Concepts           JMS           Java Language           Contact           Back           Next           Bookmark this Page          










Some useful tips related to:
 - health & fitness
 - vehicle care
 - cooking
 - misc household tasks

Difference between & and &&!


Let us consider following example:
int var=50;
if(var<25 & var++ < 100)
{
System.out.println("Inside if loop!");
}

Here first expression is var<25 and 2nd expression is var++ < 50.
When & is used it will evaluate both the expressions.
Whereas if && is used, after evaluating first expression it would find result of first expression as FALSE, it would not evaluat next expression. It would just quit the comparison and hence save time.
This evaluation is called short-circuit evaluation.


Another basic difference is that & can also be used as a bitwise operator whereas && is only a logical operator.