&& operator checks the first condition if it find it false then it goes for second one. But & operator checks the both condition irrespective of bollean value of first condtion. So if && operator is replaced with & operator it will give the null pointer exception in the given example
The difference between the & and && operators is that & always evaluates both operands, whereas && only evaluates the second operand if the first one is true. For this reason the latter is sometimes referred to as a 'short-circuiting' operator.
So, if you use & and 'a' is null making the first operand false, the second operand will still be evaluated and will throw an exception for the reason Javeed stated.
AartiPosted Nov 17, 2011, 3:56 AM
VulpesPosted Nov 9, 2011, 4:23 AM
Javeed M ShaikhPosted Nov 8, 2011, 7:21 PM