Welcome to JavaRanch!
First, a bit of business: you may not have read our naming policy on the way in. It reqiures that you use a full, real (sounding) first and last name for your display name. You can change your display name here. Thanks!
Second: yes, it's the same thing. In the "C" language, writing comparisons in this order makes some sense (for reasons that I won't burden you with right now). In Java, it's unnecessary. Java code like this generally indicates that the author switches back and forth to writing C a lot.
[ February 02, 2005: Message edited by: Ernest Friedman-Hill ]
which sets i to 1 and evaluates to true. (i think 1 is true in C; it's been a long while, it might be false.) this can actually be useful, say if you want to set one variable to the value of another and then execute the body of the "if" statement only if that value is 1; that's kindof rare, but does happen. other languages force you to spell out what you're doing when you're doing that - this is intentional.
so, in C, you should always take care to use "==" in comparisons to avoid possibly difficult-to-diagnose bugs. or, alternatively, take care to put the constant part of any comparison that involves a constant first, since even in C, assigning to a constant is a compile-time error. considering possible typos, better to use both precautions.
(you've got to give C this much: at least it isn't FORTRAN. in some early dialects of FORTRAN, you could assign new values to constant literals... which were global, no less! )
[ February 02, 2005: Message edited by: M Beck ]
if(obj = null)
if(obj == null)
In Java the compiler will throw a fit because null is not a boolean, but C is less picky about what it takes in a conditional statement. But I don't think that even C lets you assign a value to null.
Originally posted by Lionel Badiou:
Another minor advantage mentionned by thoses who like this style is readability. In the sample below, you may quickly identify cases because the discriminant value is at the beginning of the line. Of course, that's a matter of taste
If XXX, YYY, and ZZZ are integral types, you should prefer a switch statement over the if...else if...else chain anyway.
But that's somewhat off topic...