Ummmm.... kids? Friends don't let friends take bad advice.
The "performance tips" are simply all incorrect, and the "best practices" are mostly just bad personal opinions. Do yourself a favor and don't take anything you read there too seriously -- at least try to confirm the information agrees with some other source.
Originally posted by Stefan Wagner:
There is a funny comparision of exceptions inside or outside of loops.
The benchmark shows: 50 millisec. inside loop, 0 millisec. outside the loop.
The loop shall iterate over 25000 elements, and it does in the first block.
But in the second block the block is left immeadiately, because the first iteration fires the exception, and the block is left.
It's not too astonishing, that this behaviour is faster.
In the second line the test on 'a.length' is only performed once, while in the first line 'a.length'-times, which seems to be too much work, if the length of 'a' doesn't change in the loop.
It makes no measurable difference on my 1.4.2_02 -linux-jdk, (which is, to be fair, announced). But it is allways about 20% faster than the suggested solution.
"Whenever you are done with an object make that reference null so that it is eligible for garbage collection."
Are you really going to choke without that one object's few bytes of memory before the variable goes out of scope at the end of the block or the end of the function? What about the memory used up by, depending on the compiler, all those extra assignment statements making the references null? And what was the reason for garbage collection again?
"Whenever possible avoid using class variables, use local variables since accessing local variables is faster than accessing class variables."
In this case, the advice may be good - use local variables unless you actually need the persistence of a member variable - but the reasoning is questionable. Local variables are not necessarily faster, and efficiency shouldn't be the primary reason for scoping decisions, anyway.
"Use ArrayList with proper initialization if you don't want thread safe for the collection whenever you add/remove/access objects at end and middle of collection."
Joyce: Yes, I encountered the vanished text phenomen too, and was told, that it sometimes happens, when editing posts with mixtures of code and quote, and that the only suggestion is: avoid mixing code and quote.
The whole idea of inner- or outer try-catch-blocks is somewhat braindamaged.
An outer try-catch block will allways exit your loop - so what do you want to catch outside?
To cite 'Practical Java' is no help.
It's not my bible, but thanks for warning - I will keep away from it.
Choosing a good design, appropriate data-structures and the best algorithm is much more important, than learning suspicious rules, which are out of date with the next jvm.