Optimizing Application Deployment

Team-Fly

One last area of optimization has to do with the actual deployment of your application. As you may remember from Chapter 3, MIDlets are packaged in MIDlet suites, which are really just fancy JAR files. One way to optimize your application is partition your classes so that only the ones you need are loaded into the runtime environment. If you are careful, you can reduce the size or your MIDlet suite JAR by eliminating classes you don't need. Finally, a code obfuscator may be used to further reduce the size or the MIDlet suite JAR.

Partition Your Application

The MIDP runtime environment loads classes as they are needed. You can use this to your advantage to optimize the runtime footprint of your application. For example, suppose you write a datebook application that has the capability to send you reminder e-mails, or ticklers. You would probably realize that many people will not take advantage of the tickler feature. Why should they have the tickler code taking up space in their MID if they're not using ticklers? If you partition your code correctly, all of the tickler functionality can be encapsulated in a single class. If the rest of the application never calls the tickler code, the class will not be loaded, resulting in a slimmer runtime footprint.

Only Include Classes You Need

You may be using third-party packages in your MIDlet suite, like an XML parser (see Chapter 11) or a cryptography package (see Chapter 12). For development, you might have simply dumped the whole package into your MIDlet suite. But come deployment time, you should prune out the excess packages to reduce the size or your MIDlet suite JAR. In some cases this will be fairly easy, like dumping out WAP support classes if you're simply parsing XML. Other times it will not be so obvious which classes you need and which ones you can get rid of. However, if you really want to reduce your MIDlet suite JAR size, this is a crucial step.

Use an Obfuscator

Finally, a bytecode obfuscator can reduce the size of your class files. A bytecode obfuscator is a tool that is supposed to make it difficult to decompile class files. Decompilation is a process by which someone can recreate the source code that was used to make a particular class file. People who are worried about competitors stealing their code use obfuscators to make decompilation more difficult. However, obfuscation has the side effect of reducing class file size, mainly because the descriptive method and variable names you created are replaced with small machine-generated names. If you're very serious about reducing the size of your MIDlet suite JAR, try obfuscating your code. I suggest running the obfuscator before preverifying the class files, but it's conceivable it would work the other way around, too. Here are two obfuscators to get you started:

http://www.retrologic.com/retroguard-main.html

http://www.alphaWorks.ibm.com/tech/JAX


Team-Fly


Wireless Java. Developing with J2ME
ColdFusion MX Professional Projects
ISBN: 1590590775
EAN: 2147483647
Year: 2000
Pages: 129

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net