J2ME Program Optimization Method 20

Source: Internet
Author: User
J2ME program because of its special operating environment restrictions, so optimization is more important, the following is my Learning J2ME programming to collect some of the skills and their own experience.

This paper is mainly to explain the special optimization method on J2ME platform, and some techniques of repetition with J2SE will not be repeated.
1. When the image is displayed, make sure you have a FPS, preferably a few small experiments, so that you have a better balance in the display effect and the speed of the operation.

2.gamacanvas.getgraphics () produces an entirely new object each time, but the operations on these objects are all in the same graphics, so it is only once for later use.

3. Allow multiple objects to use the same listener, such as having the main MIDlet class implement Commandlistener and Itemstatelistener interfaces.

4. Consider using some of the SDK provided by mobile phone developers, no one knows their phones better than they do, so there are times when you can dramatically improve your speed, especially with pictures and video.

5. Using monitoring tools to analyze MIDlet bottlenecks, WTK and various company-supplied development kits will be available to identify weaknesses in the program. If it's on your phone, use a timer to test where you think you can.

6. Using System.GC (), you can effectively relieve memory pressure in the event of a wireless path blocking, but some companies are not too recommended (such as Nokia). Sun is also the lower end of the machine to execute the slower, in short, careful use it.

7. Use a fixed array instead of vector.

8. Picture optimization. Consider the specification of the device, which may not be shown in high-resolution pictures.

9. Unused object assignment is null, for faster recycling

10. Use a obfuscation to handle your class file, prevent decompile, and a good side effect is that it reduces the size of the class file because the obfuscation often replaces the original variable with a shorter string.
The quantity or method name.

11. If the data is too large, you can encode the data as a string, decode the runtime, or save the data as a binary file and package with the program, using the getResourceAsStream method of the class loader to access it at run time.

12. Use existing classes, such as you use the Gamecanvas, you do not have to generate off-screen, other like CLDC profile does not construct the collection class, so we can use the built-in hashtable and vector classes to implement.

13. Use optimization software jpresto (http://www.s5systems.com/jPresto.htm)---No use, but write on it.
If the memory limit is very strict on the size of the file, then only some unconventional methods can be used. Perhaps these methods deviate from oo thinking, but in most cases it is very positive (but also possible), and if you care more about the maintenance and extension of the program, I suggest you skip it-_-| |

14. Make a data file of all the resource documents.

15. Make a file of all the small picture files, and then "cut" when running.

16. Use limited object-oriented, because pure oo often means more virtual methods, more hierarchical relationships, more class

17. Generating as few class,class as possible has a certain overhead.

Generate as few methods as possible in 18.class. Speed Comparison: Synchronization method "Interface method" Instance method final method static method.

19. A small speed increase can be achieved with the final static limit method.

20. Use public qualification for data members instead of get and set methods, but be aware of security.

J2ME optimization may make your program in different simulators, different devices have different operating effects, so the optimization must be based on the development of equipment specifications.
The methods listed above do not necessarily work on all MIDP devices, and are not necessarily suitable for each program, in short, should be based on their own situation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.