How to check for null value in java
<p>In this code.</p>

<pre><code>public class Test {
     public static void testFun(String str) {
         if (str == null | str.length() == 0) {
             System.out.println("String is empty");
         } else { 
             System.out.println("String is not empty");
         }
     }
     public static void main(String [] args) {
         testFun(null);
    }
}
</code></pre>

<p>We pass a null value to the function <code>testFun</code>. Compiles fine, but gives a <code>nullPointerException</code> in runtime.</p>

<p>Suppose the value of the actual argument being passed to <code>testFun</code> is generated from some process. Assume that mistakenly a null value is returned by that process and is fed to testFun. If such is the case, how hoes one validates that value passed to the function is null or not?</p>

<p>One (weird) solution may be by assigning the formal parameter to some variable inside the function and then testing it. But if there are many variables passed to the function, that might become tedious and unfeasible. Then how to check for null values in such scenario?</p>

<p>Edit: By mistake I wrote || instead of | in the if condition. Runtime exception is now generated</p>
