At this stage there is only one profile that overlays the CLDC: the MID Profile.
Although an implementation of MIDP was released for Palm devices by Sun in October 2001, it is really intended for smaller and more constrained devices, such as mobile phones and pagers. As such, it does serve as a common platform across a wide range of devices and the developer has the choice of a lower common denominator if the developer wishes to target those devices. To the user, it means that an application written for MIDP on a mobile phone will also work on Palm devices.
The MIDP specification defines additional requirements for the target device beyond the underlying CLDC requirements. Defined by JSR37, MIDP specifies that there must be an additional 128 KB of non-volatile memory for the MIDP components, 8 KB for persistent data created and used by applications, and 32 KB for the Java heap.
The MIDP 1.0 specification builds on the CLDC 1.0 and provides functionality in the following areas:
Application lifecycle management
User interface
Persistent storage
Networking
Timers
MIDP does not cover the following areas:
System-level APIs
Application delivery, installation, and storage
Security beyond what is already specified in the CLDC.
MIDP provides a few new classes in java.lang, java.util, and javax.microedition.io, and defines new packages for the user interface, persistent storage, and application lifecycle management extensions. These packages are named javax.microedition.lcdui, javax.microedition.rms, and javax.microedition.midlet, respectively. Appendix B, "Extensions of CLDC Provided by MIDP," on page 211, shows the new packages as well as the new classes in packages already defined in CLDC.
An MIDP application is called a MIDlet. A MIDlet is part of a group of MIDlets called a MIDlet suite. MIDlet suites can share resources, such as data persisted in a Record Management System (RMS) database on the device. An MIDP application must extend the class MIDlet and implement three of its methods that are defined as abstract: startApp, pauseApp, and destroyApp. These methods are called by the MIDlet application environment when the host environment requires the MIDlet to change state. A MIDlet has the following states:
Paused. When the environment requires the MIDlet to enter the Paused state, it calls the pauseApp method to allow the MIDlet to release shared resources.
Active. The MIDlet's startApp method is called after the MIDlet instance is created, and every time the MIDlet comes out of the Paused state.
Destroyed. When the destroyApp method is called, the MIDlet is being notified that it should save its state and release any resources it was holding.
The developer can also cause the MIDlet to enter these states, using the methods notifyPaused, notifyDestroyed, and resumeRequest.
The following code shows a simple MIDlet, called SimplestMIDlet. This MIDlet displays a basic form, adds a command for pausing the MIDlet, and a command for exiting. In subsequent sections, we will add to this basic code to build up more interesting MIDlets.
package com.javaonpdas.introduction; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class SimplestMIDlet extends MIDlet implements CommandListener { protected Form mainForm = new Form("SimplestMIDlet"); protected Command exitCommand = new Command("Exit", Command.EXIT, 1); protected Command pauseCommand = new Command("Pause", Command.SCREEN, 1); protected Display display = null; // In the constructor we add commands to the form, and tell // the form that this class will handle command events. public SimplestMIDlet() { mainForm.addCommand(exitCommand); mainForm.addCommand(pauseCommand); mainForm.setCommandListener(this); } // The startApp method is called when the MIDlet is created. public void startApp() { display = Display.getDisplay(this); display.setCurrent(mainForm); System.out.println("entered active state"); } // The pauseApp method is called when the MIDlet enters the // paused state. public void pauseApp() { System.out.println("entered paused state"); } // The destroyApp method is called when the MIDlet should save // its state and free any resources public void destroyApp(boolean unconditional) { System.out.println( "entered destroyed state (unconditional:" + unconditional + ")"); } // The commandAction method is called when a command event // occurs public void commandAction(Command c, Displayable d) { if (c == exitCommand) { destroyApp(false); notifyDestroyed(); } else if (c == pauseCommand) { // The developer can cause the MIDlet to enter paused // state by calling the notifyPaused method notifyPaused(); } } }
MIDP 2.0 builds on MIDP 1.0, and is backward compatible with it, so that applications developed for MIDP 1.0 will also run on MIDP 2.0. Defined in JSR118, the final specification was released in November 2002. It assumes CLDC 1.0 functionality underneath, although it will also work with CLDC 1.1.
MIDP 2.0 adds some new packages:
javax.microedition.lcdui.game. This package includes classes for creating a game environment. It includes a new GameCanvas and Sprites.
javax.microedition.media and javax.microedition.media.control. MIDP 2.0 includes a subset of the Mobile Media API (JSR135) and supports tone generation and playback of sampled sound.
javax.microedition.pki. Certificates for secure network connections.
To obtain a copy of the MIDP 2.0 specification, go to http://www.jcp.org/jsr/detail/118.jsp.
In this section, we have a look at several vendor's implementations of the MIDP specification for PDAs.[2]
[2] The test for a product to be included in this summary is: "Does the product include an implementation of MIDP specifically for PDAs? That is, does the tool produce a Palm OS executable?" All MIDP tools produce a JAD/JAR pair, but a Java PDA developer needs to produce a binary that can be downloaded to a PDA and executed.
MIDP for Palm is an implementation of MIDP 1.0 and CLDC 1.0 for Palm OS 3.5.x. It includes a tool for converting a Java Archive (JAR)/Java Application Descriptor (JAD) pair produced with any MIDP Integrated Development Environment (IDE) into a Palm Resource File?a Palm application (PRC) for downloading to a Palm. It also includes the KVM and MIDP/CLDC libraries in a PRC package. KVM is the Java virtual machine underlying the CLDC configuration.
The hardware requirements for MIDP for Palm 1.0 are:
Palm OS 3.5.x
At least 600 KB free storage
At least 4 MB total memory
Sun has tested MIDP for Palm on a Palm Vx, a Palm VIIx, a Palm IIIc, and a Handspring Visor Pro, but it should work on other Palm OS hardware as well, providing they meet the hardware requirements.
MIDP for Palm OS 1.0 is free and available for download from http://java.sun.com/products/midp4palm/index.html.
IBM's WebSphere Studio Device Developer (WSDD, formerly VisualAge Micro Edition) is an IDE as well as a bundle of J2ME implementations (including CLDC and MIDP) for a wide range of embedded platforms and devices, including Palm devices. WSDD uses its own Java virtual machine, which is called J9. J9 has been ported to a number of embedded devices, including Palm devices. WSDD also offers the ability to call Palm OS native functions, but doing this is not consistent with the MIDP specification, and applications making use of native functions are not portable to other MIDP platforms.
The WebSphere Micro Environment includes an implementation of CLDC/MIDP for the Palm OS platform, using the Palm III, Palm Vx, and Palm V as a reference platform.
An evaluation version of WSDD is available for download from http://www3.ibm.com/software/wireless/wsdd.
JBed Micro Edition CLDC is a Java virtual machine and CLDC library for Palm devices and other platforms. The JBed virtual machine always compiles to native code, rather than interpreting bytecodes, which gives it a nice performance benefit. For more detail, see http://www.esmertec.com/technology/jbed_me.shtm.
Insignia offers a CLDC/MIDP product based on its Dynamic Adaptive Compiler (DAC) technology. The compiler compiles commonly used blocks of bytecodes into native platform processor code, making execution much faster than an interpreter approach. Insignia quotes a 30 times speed improvement over the Sun MIDP reference implementation. The total executable footprint is 437 KB, based on the Pocket PC/ARM version.