We recall that a variable of type reference to object that does not refer to any object has value null.
The comparison with null can be used in the condition of an if-else statement. To compare with null we have to use == and not the equals() method.
Example: showInputDialog returns null if the user presses the ``cancel'' button:
String input = JOptionPane.showInputDialog("..."); if (input != null) { ... }