Thursday, October 8, 2009

Best Practices in Java

Best Practice for loops
1. Use integer as loop index variable.
2. Use System.arraycopy() to copy arrays instead of loop.
3. Avoid method calls in loops if possible.
4. It is efficient to access variables in a loop when compared to accessing array
elements.
5. Avoid using method calls to check for termination condition in a loop
When using short circuit operators place the expression which is likely to evaluate
to false on extreme left if the expresion contains &&.
6. When using short circuit operators place the expression which is likely to evaluate
to true on extreme left if the expresion contains only ||.
7. Do not use exception handling inside loops.

No comments:

Post a Comment