It makes no difference at all. All of a method's local variables are allocated at once, on method entry.
Good programming style dictates that we declare the variable in the smallest scope in which it is used, and also that we don't initialize to a value at declaration unless that value is actually meaningful and expected to be used in our method.
So in your case, even if you declared outside the loop, you'd skip the = null part, since there's no meaning or reason for it. However, since you're only using the variable inside the loop, you should declare it inside the loop anyway, so that becomes a moot point.
Seems the first one is better which is probably what most people would guess ;-)
Why the second doesn't have to null a local but I guess that was obvious ;-) a class member it would have had to.
- Would this give you a measurable improvement .. nope
I only did this for personal interest, I used a class viewer on similar code in Java 6 and one appears to have to null the variable and took two more lines of byte code, will the JIT just drop the difference ? / any impact on escape analysis ? Do we care ? ;-)
"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5