What is the significance of checking for null, or why is null first? I have no idea why the code is checking for null,of course; you can't tell the code's intent from one line.
But null is first here because of a C-language programming tradition. In C, the condition of an "if" statement is an int -- C doesn't have a 'boolean' type like
Java. 0 is interpreted as false; anything else is true. Furthermore, pretty much anything can be converted to an int without a cast. Therefore, if you want to check if a variable x is equal to 2, and you accidentally write:
if (x = 2) ...
the compiler doesn't warn you of the error (= instead of ==). The value of x is changed, and the expression's value is always true! This leads to lots of sneaky, hard-to-find bugs. So many C programmers train themselves to write
if (2 == x) ...
instead. If you write = instead of == in
this expression, the compiler
will complain; you can't assign a value to a literal int!
In Java, it's very hard to make the same mistake. The only time you can do the accidental assignment in Java is if x is boolean and you write
if (x = true)
but there's an easy way to avoid that: never compare a boolean to a boolean literal -- it's redundant. Always just write "if (x)" or "if (!x)", and this assignment bug will never happen.
So anyway: the reason this code is written this way is because someone was used to writing this way in C. In Java, it's just ugly, and there's no reason for it.