Reduce the size of the DoJa program

Source: Internet
Author: User
Tags resource

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.

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.