20 tips for efficient J2EE applications

Source: Internet
Author: User

Because of its special running environment restrictions, the optimization of the program becomes more important.ProgrammingSome of the collected skills and your own experiences.

This article mainly describes the Special optimization methods on the j2se platform.

1. Determine your fps when displaying the image. It is best to do a few small experiments first, so that you can have a good balance between the Display Effect and running speed.

2. GamaCanvas. getGraphics () generates a brand new object each time. However, operations on these objects are performed on the same graphics, so they are only used once.

3. Let multiple objects use the same listener. For example, let the primary MIDlet class implement the CommandListener and ItemStateListener interfaces.

4. Consider usingMobile phoneDevelopmentSome sdks provided by vendors, no one knows their mobile phones better than they do, so sometimes they can significantly increase the speed, especially in image and video usage.

5. Use monitoring tools to analyze the bottleneck of the MIDlet. wtk and the development packages provided by various companies can be used to find program vulnerabilities. If you are on a mobile phone, use timer to test what you think is possible.

6. use System. gc () can effectively relieve the memory pressure in the case of wireless congestion, but some companies are not too recommended to use (such as nokia ). sun's statement is that the lower the end of the machine, the slower the sub-execution. In short, use it with caution.

7. Use a fixed array instead of a Vector.

8. Image optimization. Considering the device specification, high-resolution images may not be displayed.

9. The value of unused objects is null, which is faster to recycle.

10. Use the obfuscator to process your class files to prevent decompilation. A good side effect is that it reduces the size of the class file, because the obfuscator often replaces the original variable with a short string.

Volume or method name.

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

12. Use existing classes. For example, if you use GameCanvas, you do not need to generate off-screen by yourself.DCProfile does not construct a collection class, so we can use the built-in Hashtable and Vector classes.

13. Use Optimization Software jPresto (Http://www.s5systems.com/jPresto.htm) --- Never used, but write it now.

If the file size and memory restrictions are very strict, you can only use some unconventional methods at this time. These methods may deviate from the OO idea, but in most cases, it plays a very positive role (but it may also be). If you are more concerned with program maintenance and expansion, I suggest you skip it.-_-|

14. Make all resource files into a data file.

15. Make all the small image files into one file, and then "cut" the file during running.

16. use limited object-oriented, because pure OO often means more virtual methods, more hierarchies, and more classes.

17. Generate as few classes as possible, and the class has certain system overhead. 18. Generate as few methods as possible in the class. Speed comparison: synchronous method <interface method <instance method <final method <static method.

19. Using the final static limitation method can increase the speed slightly.

20. Use public restrictions on data members to replace the get and set methods, but pay attention to security.

The optimization of j2-based programs may have different running effects on different simulators and devices. Therefore, the optimization must be based on the specifications of the Development devices.

The methods listed above do not necessarily work on all midp devices, nor are they suitable for every program. In short, they 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.