In the DoJa environment, the size of the jar file and Scratchpad file is limited, as shown in the following table:
version |
jar file Size (kbyte) |
scratchpad file Size (kbyte) |
doja 1.0 |
50 |
30 |
100 |
30 |
200 |
30 |
200 |
doja 3.0 |
30 |
200 |
100 |
400 |
For this limitation, I'll introduce you to some common methods of compressing programs.
1. To your resource file
1.1. Reduce the size of the picture
In the jar file, it mainly holds the resource files (pictures, sounds, data, etc.) and the compiled class files used by the program. Obviously, the most direct way is to reduce the size of the jar file by reducing the number of pictures used, and we can reduce the size of the jar file by reducing the size of individual pictures and decreasing the number of colors in the picture.
1.2. Storing resource files in scratchpad files
Instead of storing them in a jar file, we can download the resource data from the network and save it in the Scratchpad file. We can then read the data from the Scratchpad file instead of using the resource file directly.
2. Optimization class
2.1 Reduction of the number of classes
By analyzing the class file, we found that the package name, class name, method name, and variable name are all saved as strings. The area where we will save this data is called a constant pool, and this part is the most frequent area shared by the class file.
For example, the following programs:
import com.nttdocomo.ui.*;
public class helloWorld extends IApplication
{
public void start()
{
System.out.println("Start IApplication!");
}
}
The following selected sections are the Chang for storing com.nttdocomo.ui.IApplication classes:
2.2 Shortened class name
By shortening the name of the class, we can also achieve the goal of reducing the size of class files.
Compare the definitions of the following two classes:
// class 1
public class HelloWorld{
public void start(){}
}
// class 2
public class A {
public void start(){}
}
Class A required class HelloWorld reduced by 18 bytes.