Midlet in J2ME

MIDlet is a Java program for embedded devices, more specifically the Java ME virtual machine. Generally, these are games and applications that run on a cell phone

A MIDlet requires a device that implements Java ME, MIDP to run. Like other Java programs, MIDlets have a “compile once, run anywhere” potential. MIDlet distributions also consist of a .jad file describing the contents of the JAR file.

A MIDlet has to fulfill the following requirements in order to run on a mobile phone:

  • The main class needs to be a subclass of javax.microedition.midlet.MIDlet

  • The MIDlet needs to be packed inside a .jar file (e.g. by using the jar-tool)

  • The .jar file needs to be pre-verified by using a preverifier.

  • In some cases, the .jar file needs to be signed by the mobile phone’s carrier.

MIDP Applications (MIDlets) and MIDlet Lifecycle

The applications written for mobile information devices such as cellular phones and pagers are called MIDlets. Like applets, MIDlets are controlled by the software that runs them. In the case of an applet, the underlying software is a browser or the applet viewer tool and in the case of a MIDlet, the underlying software is the cell phone or two-way pager device implementation that supports the CLDC and MIDP. A MIDlet is a well-behaved MIDP application, which lives within the resource constraints, which runs and terminates when requested.

Start exploring endless computing possibilities with your own Raspberry Pi computer and accessories. Perfect for beginners and students.

All the devices, which support MIDP, are supposed to have a device-specific Application Management Software that takes care of installing, managing and removing MIDlets interactively.

MIDlet lifecycle

MIDlets move through a well-defined lifecycle consisting of five phases. It is the task of the Application Management Software to move MIDlets through these phases:

  • Retrieval – The AMS retrieves the MIDlet from some source and reads the MIDlet into the device’s memory. The medium through which the MIDlet is downloaded depends on the device. It could be through a serial cable, an IRDA port, or a wireless network.
  • Installation – Once the MIDlet is downloaded, the AMS installs the MIDlet on the device. During the installation process, the MIDP implementation verifies that the MIDlet does not violate the device’s security policies.
  • Launching – A MIDlet is launched when a user selects it using the interface provided in the device. At this point, the MIDlet enters the KVM and the lifecycle methods of the MIDlet are invoked.
  • Version Management – The AMS keeps track of all the MIDlets that are installed on the device including their version numbers. This information is used to upgrade a MIDlet to its new version.
  • Removal – The AMS removes a MIDlet and cleans up the related resources from the memory.

A MIDlet can be in one of the three states after the Application Management Software launches it:

  • Paused A MIDlet enters the Paused state once it is created and initialized by the AMS. It can also enter this state when it is Active.
  • Active this state means the MIDlet is running normally. A MIDlet goes to the Active state from the paused state if there are no runtime exceptions during its initialization.
  • Destroyed this state means the MIDlet has released all its resources and is terminated. A MIDlet can reach this state either from the paused state due to a runtime exception during its initialization or from the active state when the user has chosen to close the application.

MIDlet suites:

MIDlets are usually available through MIDlet suites. A MIDlet suite consists of two files, a .jar and a .jad file. The Java ARchive (JAR) file contains your compiled classes in a compressed and preverified fashion. All MIDlets must be preverified. This means that a checksum is computed, enabling the resource-constrained MID to easily check the integrity of the jar-file (using only a few hundred bytes of memory). Several MIDlets may be included in a MIDlet suite. Hence, the JAR file will contain all these MIDlet classes.

The Java Application Descriptor (JAD) file is a plain text file containing information about your MIDlet suite. All MIDlets must be named in this file, the size of the JAR file must be included (and be correct!) and the URL to the JAR file must be present. In addition, the MIDlet suite version number is included here. This is essential information for a MID. If the suite is already installed, it will know if a newer version is available. The size of the JAR file is important information, the MID can determine if there is enough memory available to install the MIDlet suite.

Every MIDLet contains 3 abstract methods that are called by the application manager to manage the life cycle of MIDLet. These abstract methods are startApp(), pauseApp(), destroyApp ( boolean unconditional)

public class Mymidlet extends MIDLet{

public void startApp(){


public void pauseApp(){


public void destroyApp( boolean unconditional ){



What does a JAD file contain? Why it’s required?

The JAD file is used by the application manager to know whether the MIDLet suite can be implemented on the device.

There are five required system attributes for a JAD file.

  1. MIDLet Name.
  2. MIDLet Version.
  3. MIDLet – vendor.
  4. MIDLet-n.
  5. MIDLet-Jar-URL.

An Example of JAD File:

MIDLet-Name: Best MIDLet

MIDLet-Version: 2.0

MIDLet-Vendor: Mycompany

MIDLet-Jar-URL: http://www.mycompany.com/bestmidlet.jar

MIDLet-1: Best MIDLet, /images/BestMIDLet.png , Best.BestMIDLet

Leave a Reply