Java ME Coding Tips

Java ME Coding Tips

The following tips are only suggestions and May or may not give gains in performance, it is to your own judgment and discretion to use them or not.

1. Use String Buffer instead of String because of the fact the String object cannot be changed. Any modification to a String variable is actually a new object creation.

2. Accessing class variables directly is faster then using setter and getter methods.

3. Using local variables are more efficient then instance/class variables

4. Using variables are more efficient then arrays.

5. Avoid synchronization in loops because there is an extra overhead to lock and unlock each time the loop occurs

6. Counting down in loops is faster then counting up

7. Use compound operators like  += 1 instead o f  =  + 1 because fewer byte codes is generated

8. Remove constant calculations in loops

9. Reuse objects

10. Assign null to unused objects, especially unused threads

11. Try to use already built in methods, for example if you want to copy data from one array to another use System. Array copy more then is more efficient then the one you created yourself.

—–

Leave a Reply

You must be logged in to post a comment.