×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    1

    Optimizing J2ME application size

    Hi,
    how can I optimize my code in order to reduce the size of my application and verify the condition 30K as maximum size?

    Thanks.

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    5

    RE: Optimizing J2ME application size

    Try to use obfuscators, it should help to reduce jar size.

    WBR,
    Alexey Epishkin
    Offshore Algorithms Co.

  3. #3
    Regular Contributor
    Join Date
    Mar 2003
    Location
    UK
    Posts
    229

    RE: Optimizing J2ME application size

    I've found JODE (jode.sourceforge.net) and Jax (www.alphaworks.ibm.com) to be good at code size reduction, these will often save you quite a bit. JODE is GPL too.

    Here also are a few tips that have worked for me.

    Use the fewest number of classes possible in your application. You really only need 2 or 3, one that extends MIDlet, one that extends Canvas and possibly a TimerTask. Lots of classes takes up lots of room in the jar file, and the preverifier adds more size to each one.

    Use bytes and shorts as member variables where you can, rather than ints. Don't use booleans (which are ints), use a single int as 32 booleans!

    Don't have static arrays in your code. Static arrays of anything take up lots of space in the final class file. Use a resource file of data and load that into dynamically created arrays as necessary.

    Get rid of all "strings" in your code too, again, use a seperate data file and load them with a loop into an array. Reference them by index into the array in your code. This is also good for producing midlets that support multiple languages.

    Believe it or not, switch statements produce more bytecodes than if/elseif statements.

    If you don't mind using the Nokia UI, write a utility program that takes PNG files and produces a 'raw' data file which contains the image data in the format of the device you're coding for. TYPE_1_BYTE_GRAY for example. These data files will often compress much better in a jar file than PNGs do, thus saving you space. At runtime, load the data file into a byte [] array and use DirectGraphics.drawPixels to create Image objects.

    Finally, compact all your resource files into a single data file and read the resources (array data, images, strings) using offsets into that file. The less files in the jar, the better.

    Hope this helps,

    Steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •