The problem is that for conditional statements (like if, else etc.) in
java/C++, it does "Short-circuiting". i.e. This means that the expression will
be evaluated only until the truth or falsehood of the entire expression can be
unambiguously determined.
In ur case when, s = null;
a. if (s== null || s.length()> 0),
Here s==null is TRUE, so s.length() is not evaluated.
b. if ( s!= null || s.length()> 0),
Here s!=null, this means the conditional statement can be true
if s.lenght()>0. But the time it evaluates s.lenght(), it finds
s is null and throws NPE.