Q:

Instances and iterations. Which one is better?

I wanna read documents and process them. Each iteration processes one document.
Which kind of code is better?
1.
BufferedReader br;
for(File f : files)
{
    br = new BufferedReader(......);
    ......
}

2.
for(File f : files)
{
    BufferedReader br = new BufferedReader(......);
    ......
}

My point is which one is more efficient in terms of space and speed?

A:

The latter is clearer in my view. In general, prefer to declare local variables with the smallest scope you can, ideally initializing them at the point of declaration.
It won't directly affect the performance - but it will affect readability and maintenance, which will affect the ease with which you can make changes which will affect performance.
In general:

Work out your performance and behavioural requirements (and how you'll test both)
Write the simplest, cleanest code which achieves the behaviour you'll want
See if it meets your performance requirements
If not, analyze where the problem is, and make the "least unclean" change to improve things. (This may mean making a design change rather than a micro-optimization.)
Lather, rinse, repeat until you've got code which meets your performance requirements and is as clean as it can be.

A:

They are exactly the same and all differences are lost after compiling into bytecode.
Even if we imagine the worst possible scenario, which could theoretically (in another Java) amount to one extra memory write, the difference would be so ridiculously small that you'd need the world's most precise atomic clock to measure it.
The real difference for you should lie with the overall maintainability of your code and that should be a much higher concern than even a real difference in speed lower than 2-3%. For example, many design patterns introduce some kind of overhead, but people are more than willing to pay that for the amount of flexibility it gives the code base.

In code optimization it is very easy to fall into the trap of Win Small, Lose Big: each individual method may be optimized to perfection, but overall system performance may still be a disaster due to the inadequacies of global architecture. One must always optimize top-down, and when doing so, you'll see that only 1% or less lines of code can actually contribute to overall performance if replaced by an optimized version.

A:

If you don't use the br variable elsewhere, they're both exactly the same.
Beware not to lose too much time attempting nano-optimizations. Even when the bytecode differs, the JIT isn't so bad when optimizing the obvious. You don't need to declare a variable before the block where it is used and you shouldn't as it make it less clear what it is used for.

