Have you tried them? Did you notice any difference?
I believe this sort of thing is a holdover from the C programming language. There, you could have any expression in the if-condition. Basically, there, 0 was false and ANYTHING ELSE was true.
Further, a common programming error was to use the '=' assignment operator when you meant to use the '==' equality operator. So, this was legal (just like it is in java:
However, since the 'value' of an assignment operation was the value being assigned, this was also legal:
Note the difference. The first one checks to see if x is equal to seven, and may be true or may be false. The second one ASSIGNS the value of 7 to x, making the value of that expression 7, therefore ALWAYS TRUE.
this was usually a mistake, but caused endless hours of hunting for bugs.
The recommended way to prevent this was to put the constant first:
since using the assignment operator would cause an error,, since it makes no sense
The upshot and my real point here, is that now, it doesn't really matter. you can write your null check either way, since java will never allow you to do
as it is not legal to test for true/false based on anything but a boolean.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors