Sometimes the condition in Java class needs to compare between a constant string and a variable.

For example: variable.equals(CONSTANT_STRING);

Now suppose if the variable is not initialized then the above statement throws a null pointer exception.

To avoid this null pointer exception you can re-write the above statement:

CONSTANT_STRING.equals(variable);