In SQL, NULL pretty much behaves like NaN in Java.
[icode]SELECT NULL = NULL[/icode] -> [icode]NULL[/icode]
[icode]SELECT NULL != NULL[/icode] -> [icode]NULL[/icode]
[icode]SELECT NULL <> NULL[/icode] -> [icode]NULL[/icode]
[icode]SELECT NULL <=> NULL[/icode] -> [icode]1[/icode] (true)
[icode]SELECT NULL IS NULL[/icode] -> [icode]1[/icode] (true)
[icode]SELECT NULL IS NOT NULL[/icode] -> [icode]0[/icode] (false)
[icode]SELECT NULL = 13[/icode] -> [icode]NULL[/icode]
[icode]SELECT NULL <=> 13[/icode] -> [icode]0[/icode] (false)
You can equally reason that [icode]null[/icode] is nothing, unknown, and cannot be compared with another unknown.
The difference, however is, that in Java, NaN is a range of values, and null is basically the integer zero (for the VM). In theory the VM could have been implemented that a null value would be defined as any value below 1, but the language designers were sane enough to follow C’s example, as opposed to SQL’s.
One advantage of SQL’s NULL is that you can have unlimited NULLs in a set (as used by UNIQUE INDEX).
One advantage of Java’s NaN is that it’s ‘hardware accelerated’ (x87)
Slightly more on topic: it would be nice to have (additional) floating point types in Java that raised exceptions when the result of an operation was NaN, as to avoid silent errors. Just like dividing by zero for integers.