Sun Java Solaris Communities My SDN Account Join SDN
 
FAQ

Writing an application for the J2ME Personal Profile

 
 



Question

How do I write an application for the upcoming J2ME Personal Profile?

Tip

First as background, the J2ME Personal Profile is a J2ME Connected Device Configuration (CDC)-based technology for small devices. It is the migration path for PersonalJava technology. Personal Profile differs from the better known Mobile Information Device Profile (MIDP), in that Personal Profile is meant for higher end devices, such as high-end PDAs (such as, Sharp Zaurus), smart communicators (such as PDA/cell phone combinations), TV set-top boxes, game consoles, automobile dashboard electronics, and so on.

MIDP is currently meant for smaller devices with small LCD screens and limited input entry methods (such as a cell phones with simple keypads). Also, MIDP is currently a J2ME Connected Limited Device Configuration (CLDC)-based technology. It has limited Java technology -- for example, it has no support for floating point, no on-board bytecode verification, no Java Native Interface (JNI), no Abstract Windowing Toolkit (AWT), and no advanced Java 2 technology features (such as reflection and security).

By contrast, J2ME Personal Profile is a J2ME CDC-based profile and therefore has all those missing features. Note that J2ME CDC is fully compliant with the Java 2 VM specification. This allows a developer using the Personal Profile to leverage his or her knowledge of the Java 2 Platform, Standard Edition to write programs for smaller devices.

More importantly, J2ME Personal Profile has full AWT 1.1 support. This means that you can write your application following the regular J2SE AWT APIs without having to relearn anything (that is, as long as you stay within the AWT 1.1 subset of APIs).

Lastly, applications and applets written for J2ME Personal Profile are upwardly compatible with J2SE. In other words, an applet written for J2ME Personal Profile will also run as an applet in a Web browser with J2SE, such as Netscape Navigator or Internet Explorer. This is a good mechanism for interoperability of applets that you want to run in both J2ME Personal Profile and J2SE environments (as long as you remember to conform to the smaller device's screen size).

Build your application using the PersonalJava Emulation Environment (PJEE) and the J2SE v1.2 javac compiler.

First write the program following the AWT 1.1 APIs and J2SE, v1.2. Here's an example of a program written for the J2ME Personal Profile:

/**
* PersonalProfileApp
*
* @author Hinkmond Wong
* @(#)answer166.jsp	1.3 02/02/11
*/

import java.awt.*;
import java.awt.event.*;

// Simple J2ME Personal Profile application
public class PersonalProfileApp extends Frame implements ActionListener {

    Label       panelLabel = new Label("Panel");
    Button      button = new Button("Get Data");
    Panel       panel = new Panel();
    Label       label = new Label("Button:");
    int         count = 0;

    public void start() {
        setLayout(new BorderLayout());

  	// Add a Container
	panel.setLayout(new FlowLayout());
	panel.add(label);
	panel.add(button);

	add("North", panel);

	// Add a Component
	label = new Label("HelloWorld");
	label.setBackground(Color.white);
	label.setForeground(Color.red);

	add("Center", label);

	// Add a action listener to the button to tell when
	// it's pressed
	button.addActionListener(this);

	validate();
    }

    //-----------------------------------------------------------
    // ActionListener Interface
    //-----------------------------------------------------------

    public void actionPerformed(ActionEvent event) {
	label.setText("Button pressed # "+(count++));
    }

    public static void main(String argv[]) {
	PersonalProfileApp    testApp = new PersonalProfileApp();
	testApp.start();
	testApp.setSize(220, 200);
	testApp.validate();
	testApp.show();
    }
}

Then, compile the program using the J2SE v1.2 javac compiler and PersonalJava Compatibility Classes 1.2.

Finally, run JavaCheck against your program to make sure the APIs you use fall under the PersonalJava subset. This also means that your program will run with the J2ME Personal Profile.

To test the program, use PJEE for your specific platform, or download your Java class to a PersonalJava device (such as Sharp Zaurus). If you test on a Sharp Zaurus, do the following:

  1. Transfer your file to the Zaurus (for example, through data synchronization from the PC connected cradle)
  2. Open a shell.
  3. Run the program using the PersonalJava VM (evm) that comes with the Sharp Zaurus. For example, to run the PersonalProfileApp shown above, enter the shell command:
    evm -cp path_to_classfile PersonalProfileApp
    Replace path_to_classfile with the path to your class.

You should find that writing an application for J2ME Personal Profile is as easy as AWT.

Acknowledgments

Thank you to member Hinkmond Wong for the solution to this question.

.
. . .
. Note: If you have a question to which you need an answer, try the Mobility Forums. You can read through the existing topics or register for your free Sun Developer Network membership and post new messages or threads. For more information, go to the Why Register page. .
.
.

Back To Top