Before calling a function of an object, I need to check if the object is null, to avoid throwing a NullPointerException.
NullPointerException
What is the best way to go abou
Method 4 is my preferred method. The short circuit of the && operator makes the code the most readable. Method 3, Catching NullPointerException, is frowned upon most of the time when a simple null check would suffice.