Home > Developer > Difference Between MIDP and DoJa

Difference Between MIDP and DoJa

Porting mobile Java Applications Amongst Different Carriers

Portable Java Specifications

Since mobile Java specifications are different for each carrier, portable Java applications must be designed to maximize shared parts, and carrier differences have to be merged.

Differences between DoJa and MIDP

Boot Up Class

A DoJa application's boot up class is IApplication, MIDP's is MIDLet.

Saving Data

DoJa cannot store data in "record store", so data should be saved in the scratch pad.

Canvas Class for Low Level UI

Double buffering for drawing graphics and size acquisition varies between DoJa and MIDP, but can almost be unified.

Panel and Frame Classes for Higher Level UI

These classes cannot be shared since their designs are completely different in MIPD and DoJa.

Graphic Context Class

This class can be shared by implementing a conversion class for DoJa to MIDP.

Images

Simply changing the image format can merge image processing.

Processing Key Events

Key events can be merged in preprocessing is used to eliminate differences. Soft keys are not directly detected in MIDP.

Multimedia (Sound, Movies)

Multimedia processing is deeply related to each device and carrier, so code sharing is unfeasible.

Merging by Means of the Preprocessor ( Key Event Example )

By using the preprocessor to rewrite DoJa's "processEvent" function, it can be called from "commandAction" and "keyPressed" in MIDP.

// Sharing code for key event processing
#ifdef DOJA
    #define PP_KEY_PRESSED_EVENT Display.KEY_PRESSED_EVENT
    #define FIRE Display.KEY_SELECT
    #define SOFT1 Display.KEY_SOFT1
    #define SOFT2 Display.KEY_SOFT2
#else
    #define PP_KEY_PRESSED_EVENT 0
    #define SOFT1 0x100
    #define SOFT2 0x101
#endif

   .
   .
   .
 *snip*
   .
   .
   .

#ifdef MIDP
    Command[] command = new Command[2];
    public void commandAction(Command c, Displayable s) {
        if(c == command[0]){
            processEvent(PP_KEY_PRESSED_EVENT, SOFT1);
        } else if(c == command[1]){
            processEvent(PP_KEY_PRESSED_EVENT, SOFT2);
        }
    }

public void keyPressed(int keyCode) {
    if(keyCode != 0){
        processEvent(PP_KEY_PRESSED_EVENT, getGameAction(keyCode));
    }
}
#endif

public void processEvent(int type, int param){
    if(type == PP_KEY_PRESSED_EVENT){
        switch(param){
        case FIRE:
            // Process center key
            break;
        case SOFT1:
            // Process soft key 1 
            break;
        case SOFT2:
            // Process soft key 2
            break;
        }
    }
}

( the rest is ommited )

Merging the Graphics Class

The Graphics class can be shared by means of a wrapper class.

// DojaGraphics Class
import javax.microedition.lcdui.*;

class DojaGraphics {
    public static final int BLUE = 0x000000FF;
    public static final int GREEN = 0x0000FF00;
    public static final int RED = 0x00FF0000;
    public static final int WHITE = 0x00FFFFFF;
    public static final int BLACK = 0x00000000;

    Graphics graphics;
    Font font;

    public DojaGraphics(Graphics g) {
        graphics = g;
    }

    public int getColorOfName(int c) {
        return c;
    }

    public void setColor(int c) {
        graphics.setColor(c);
    }

    public void setFont(Font f) {
        font = f;
        graphics.setFont(f);
    }

    //implemention omitted
    public void lock() {}
    public void unlock(boolean forced) {}

    public void drawString(String str, int x, int y){
        graphics.drawString( str, x, y, graphics.BASELINE | graphics.LEFT);
    }

    public void drawImage(Image img, int x, int y) {
        graphics.drawImage( img, x, y, graphics.TOP | graphics.LEFT);
    }

    public void drawLine(int x1, int y1, int x2, int y2) {
        graphics.drawLine(x1, y1, x2, y2);
    }

    public void fillRect(int x, int y, int w, int h) {
        graphics.fillRect(x, y, w, h);
    }

    public void drawRect(int x, int y, int w, int h) {
        graphics.drawRect(x, y, w, h);
    }
}
// example of DojaGraphics class
    public synchronized void paint(Graphics g) {
#ifdef MIDP
        paint(new DojaGraphics(g));
    }

    public void paint(DojaGraphics g) {
#endif
    g.lock();

    g.setColor(g.getColorOfName(g.WHITE));

    (*snip*)

    g.unlock(true);
}

To optimize size, only the required methods are implemented in DoJa. Methods can be added or deleted as needed.

The Size Restrictions of mobile Java

Every carrier has size restrictions for mobile Java that can be very severe.

Specification Size restriction (JAR size)
NTTDoCoMo 10KB / 30KB / 100KB / 1024KB
au EZ Appli ( Java ): 50KB / 150KB; Open appli ( Java ): 300KB
SoftBank 30KB / 50KB / 80KB / 200KB / 1024KB
WILLCOM 1024KB

* J-Phone and Vodafone mobile Java models are also under SoftBank

Compressing mobile Java Applications

Exploiting Java APIs

Maximize the usage of Java APIs.

Using Immediate Values

Dialog dialog = new Dialog(Dialog.DIALOG_ERROR,"...");
dialog.show();

Can be substituted for:

new Dialog(Dialog.DIALOG_ERROR,"...").show();

The variable dialog can be deleated once.

In-lining Methods

Methods for getting and setting can be expanded, and the original methods deleted.

Remove Unused Fields

Fields that are never used should be deleted

Constant Expansion

If a result is constant, substitute the constant in place of the expression.

Variable Arrays

Multiple variables will be compressed to a single variable by combining them in an array.

Class Integration

Integrating several classes into a single one.

Name Sharing and Shortening

Shortening or sharing class, field and method names.

mobile Java Compression Tools

Free Tools

ProGuard

http://proguard.sourceforge.net/

Optimizes bytecode and removes unused instructions. Compression rates are maximized when used with SophiaCompress(Java)

JavaBlender

http://homepage.mac.com/t.sekiguchi/javablender/index.html

A mobile Java compression tool that shortens function names and implements some class integration.

jarg

http://jarg.sourceforge.net/

Open source mobile Java compression tool. Shrinks and obfuscates jar files.

RetroGuard

http://www.retrologic.com/

RetroGuard focuses on obfuscation and its compiled source code almost impossible to decode. Compression is achieved through name shortening.

Commercial Tools

SophiaCompress(Java)

/products/sophiacompress_java/

Japan's first choice for compressing mobile Java applications. It has an established reputation for ease of use and has some of the highest compression rates in the industry.

DashO Pro

http://www.preemptive.com/products/dasho/index.html

DashO Pro like RetroGuard, is mainly used as an obfuscator, it guards against reverse engineering.

mBooster

http://www.innaworks.com/

Has some notable elements such as video compression function and stack map reduction function.