Wednesday, March 10, 2010

J2ME jar size

If you build application, sooner or later you will hit J2ME jar size problem. if you use libraries like LWUIT, you start with 90KB. Then you add resources (images, strings) of 130KB. And then your app takes few more hundred KBs. This will hit you when you realize that some of the phones like MOTO RAZR will only support 400 or 500KBs app sizes and some phones will even restrict you to 200KB.

Statment level LOC, Method and Class are three variables that we played with. Keeping LOC and class constant we changed methods. Here are the numbers,






MethodsJar Size (Bytes)Delta for additional method
11301
2132019
3133919


Keeping LOC contant, we added classes (and in first three additions a new method also came about)








MethodsJar Size (Bytes)Delta for additional method
11301
21738 437
32167429
42605 438
52913308 Empty class added


So, for every method add a 19B and every class add a 308-400B hit is there.

Here is the class that we were playing with,

public class HelloWorld {
public void say()
{
System.out.println("H");
System.out.println("e");
System.out.println("l");
System.out.println("l");
System.out.println("o");
}

}

For methods we had,


public class HelloWorld {
public void say()
{
System.out.println("H");
System.out.println("e");
System.out.println("l");
System.out.println("l");
System.out.println("o");
}
public void say1()
{
System.out.println("W");
System.out.println("o");
System.out.println("r");
}
public void say2()
{
System.out.println("l");
System.out.println("d");
System.out.println("!");
}

}

No comments: