Desktop Java

How to create MIDlet in J2ME


Java Mobile Application is called J2ME. Normally when we are working in the mobile technology field then we must think about J2ME application. Through this way we can develop our mobile application and also install it in our device through the jad or jar file. In current years the largest enhancement in mobile phone development was the introduction of JavahostedMIDlets. MIDlets are executed on a Java virtual machine that abstracts the underlying hardware and lets developers create presentations that run on the wide variety of devices that generally supports the Java run time system. Inappropriately this convenience comes at the price of restricted access to the device hardware. Now in the mobile development it was considered normal for third-party applications to receive different hardware to access and execution rights from those given to native applications written by the phone manufacturers’. The introduction and implementation of Java MIDlet expanded developers’ audiences. But the lack of low-level hardware access and sandboxed the execution meant that most mobile applications are regular to desktop programs or web sites designed to render on a smaller screen.

In this article MIDlet creation will be discussed in details.


J2ME abbreviation as Java 2, Micro Edition. It is a functional version of the Java besieged at devices which have limited treating power and storage aptitudes and alternating or fairly low-bandwidth network connections system. These systems also include mobile phones, pagers, wireless devices that are normally used in our daily life. MIDlets are part of the applets for mobile phones system. Here applets which can run in a protected sandbox. This system is extremely limited for that process. The MIDP ( ) 1.0 is currently found on most Java-capable phones and is fairly good. As an example – the KVM doesn’t allow us to process the floating point numbers yet and MIDlets written for MIDP 1.0 cannot access anything outside of the sandbox without proprietary APIs (Application Programming System.) from phone makers. Now we can put our dreams for developing the ultimate MIDlet with hooks into each part of our phone Operating System on the backburner. Basically when we want to find out exactly that how limited MIDP 1.0 is present then we should probably read the spec here. If we do it then it might want to check out MIDP 2.0 version and it’s up gradation. Here the time being we are going to write our first MIDlet – a full-featured like “Hello MIDlet” application.

The MIDlet Lifecycle

Every system should have lifecycle and through this life cycle we can recognize the step by step process of the system. Here we shortly discuss MIDlet Lifecycle Mobile devices like emulators or real that can interact with a MIDlet using their own software technology process known as Application Management Software (Abbreviated as AMS). The AMS is responsible for initializing, starting, pausing, resuming, and destroying a MIDlet. AMS may be responsible for installing and removing a MIDlet. To facilitate this life cycle management, a MIDlet can be in one of three states which are controlled via the MIDlet class methods that every MIDlet extends and overrides. These states are split up with different part like active, paused and destroyed.

Virtual Machines

Generally these types of programming model Virtual Machine or Virtual Device also take a vital role in the software development section. Now the CLDC (J2ME Connected, Limited Device Configuration) and the CDC (J2ME Connected Device Configuration) necessitate their own virtual machine because of their altered memory and displayed the capabilities. The CLDC virtual machine is smaller than that required by the CDC and supports fewer features. In that sense the virtual machine for the CLDC is called the Kilo Virtual Machine (KVM) and the virtual machine for the CDC is called the CVM.

J2ME Connected, Limited Device Configuration:

  • It is used to specify the Java environment for mobile phone, pager and wireless devices as well as support other devices also.
  • CLDC devices are usually wireless that means mobility system is supported via CLDC
  • Memory requirement is very much important in that particular device such that 160 – 512k of memory available for Java.
  • Energy saver system has limited power or battery operated capability.
  • Communication process is very important here. The network connectivity is wireless, intermittent, low-bandwidth (9600bps or less).

J2ME Connected Device Configuration:

  • Generally it describes the Java environment for the digital television set-top boxes, mobile, high end wireless devices and automotive telemetric systems.
  • The device is powered by a 32-bit processor supported system.
  • 2MB or more memory is available for the Java platform.
  • The network connectivity that are often wireless, discontinuous, low-bandwidth (9600bps or less)

Process to Create our own MIDlet in Net Beans

Generally when we work in the Net Beans field then we have to install Java SE Development Kit (JDK) for that reason we must Download and install the latest 32–bit version of Java SE Development Kit (JDK) first. The JDK is required for compiling the Java classes to execute the code. The Net Beans installation Guide asks that is used to browse to the JDK location on the local drive during installation.

ð This point should be remembered that when we are installing Net Beans then we select to customize the installation and clear theFeatures ON-Demand option. Then download and install a software development kit (SDK) that supports Java ME (Micro Edition). The SDK provides Java ME class libraries that the IDE involves for building MIDlets for a particular device platform.

Actually when we generate the MIDlets for the Series 40 devices we use a Nokia SDK (Software Development Kit) for Java. Now if we want to create MIDlets for Series 40, 6th edition, or earlier Series 40 devices then use the corresponding Series 40 SDK.

ð Remember that SDK is properly integrated with the IDE and also install the SDK on the same logical drive as the IDE section.

Process to configure Net Beans

After installing the required software integrate Net Beans with the installed SDK.
Here we will discuss step by step process to create the project:

  1. Open Net Beans (Version 7.2.1 it may be changed according software update process
  2. Select Tools-> Java Platforms.
  3. Click Add Platform.
  4. Select Java ME CLDC Platform Emulator and click next. Net Beans searches our computer for SDKs that support Java ME.
  5. Select File> New Project.
  6. Select Java ME -> Mobile Application and click next.

Figure 1: Selecting the Java platform type
Figure 1: Selecting the Java platform type


  1. If we do not find the SDK (Software Development Kit) in Net Beans IDE then click Find More Java ME Platform Folders and select the folder where we installed the SDK. Net Beans searches the selected folder for SDKs (Software Development Kits) that support Java ME (Micro Edition).
  2. Select the SDK and click Next -> Net Beans detects the SDK capabilities.

Figure 2: Adding a Series 40 Software Development Kit
Figure 2: Adding a Series 40 Software Development Kit


  1. After the completion click configuration -> click Finish and then Close.
  2. Your development environment is now set and you can create the MIDlet in Net Beans.

To create the HelloBCEI MIDlet:

  1. Download and install Netbeans (select an installation bundle that supports Java Micro Edition).

In this Project Name field, enter “HelloBCEI”.

Figure 3: Creating your first MIDlet in Net Beans
Figure 3: Creating your first MIDlet in Net Beans


  1. Clear the checkbox Create Default Package and Main Executable Class.
  2. Click Next. The MIDlet setup continues with device platform selection.
  3. In the Emulator Platform drop-down menu option, select the device platform for which you want to create the MIDlet:

For those Series 40 devices, here we select a Nokia Software Development Kit for Java.

Figure 4: Choosing the device platform for the MIDlet
Figure 4: Choosing the device platform for the MIDlet


  1. Select CLDC-1.1 and MIDP-2.0. We may also select MIDP-2.1 and Click Finish. NetBeans sets up the MIDlet project for us.

Now I am creating the program through the following way.

  1. To create the main class for the MIDlet, select File -> New File.
  2. Select CLDC -> MIDlet and click next.
  3. In the MIDlet Name field, enter “HelloBCEI”.
  4. In the MIDP Class Name field, enter “HelloBCEIMIDlet”.
  5. Click Finish.

The HelloBCEI MIDlet class is created in the default package. Here we write down the code that code is generated in the program.

Listing1: Showing MIDlet class

import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.MIDlet;

public class HelloMIDlet extends MIDlet
public HelloWorldMIDlet()

// Sets the MIDlet’s current Display to a HelloScreen object.
public void startApp()
Displayable current = Display.getDisplay(this).getCurrent();
if (current == null)
HelloScreen helloScreen = new HelloScreen(this, “Hello, BCEI!”);
public void pauseApp()

public void destroyApp(boolean unconditional)


To create the HelloBCEIScreen class:

  1. select File -> New File.
  2. Select Java-> Java Class and click Next.
  3. In the Class Name field, enter “HelloBCEI”.
  4. Click Finish. The HelloBCEI class is created in the default package.

Listing2: Shown class created in default package

import javax.microedition.lcdui.*;

class HelloBCEIScreen extends Form implements CommandListener
private final HelloBCEIMIDlet midlet;
private final Command exitCommand; //Exit command for closing the MIDlet in the device UI.

public HelloBCEIScreen(HelloWorldMIDlet midlet, String string)
StringItem helloText = new StringItem(“”, string);
this.midlet = midlet;
exitCommand = new Command(“Exit”, Command.EXIT, 1);

public void commandAction(Command command, Displayable displayable)
if (command == exitCommand)

Save the project by selecting File -> Save All.

In the Project pane, right-click the HelloBCEI project and select Deploy option. After selecting the deploy option the program is ready to install in the device.

NetBeans builds the MIDlet and creates the JAR and JAD files used for deploying the MIDlet to a device. You can also find the generated files in the Files pane under the dist folder.

Figure 5: HelloBCEI project viewed in the Projects pane
Figure 5: HelloBCEI project viewed in the Projects pane


Debugging a MIDlet

Before we can debug a MIDlet, we must have versions of the MIDP executable and the MIDlet that has debugging cryptogram in their class files. To see whether we have an acceptable version of the midp executable and run the midp command in the midst of the -help option. If the generated executable has Java debugging capabilities then we will see the -debugger option listed below. For example:

C:\midp2.0fcs> bin\midp -help

Usage: midp [<options>]

Run the Graphical MIDlet Suite Manager….

or midp [<options>] -debugger …

The version of the midp executable that we are using does not support Java programming language debugging. To produce a version of the MIDlet that contains debugging symbols we use the –g option to the javac (compiler of the Java) command.

To debug a MIDlet following steps should be followed up one by one:

1. at first open a command prompt or terminal window.

2. Change our current directory to midpInstallDir.

For illustration, if the MIDP Reference accomplishment were installed in the directory

c:\midp2.0fcs we can run the command:c:\> cd midp2.0fcs

3. Start the MIDP Reference accomplishment and executable in debug mode.

Use the midp command in the midst of the switches -debugger and -port. The port number should be 2800. Here the port number on which the KVM debug proxy expects the debugger to be running.

Reference Implementation executable. For example:

c:\midp2.0fcs\> bin\midp -debugger -port 2800 -classpath classes

4. Now Start the KVM debug proxy.

Check the KVM documentation for information on the correct syntax, arguments, and options. For specimen, the following command has the KVM debug proxy connect to the midp executable that we started in the previous step and then listen at port 5000 for software compliant with the Java™ Platform Debugger Architecture process:

 c:\midp2.0fcs\> java -jar

c:/kvm/bin/kdp.jar kdp.KVMDebugProxy –l 5000 -p -r localhost 2800 -cp

Paths Including MIDletClassFiles

5. Connect to the KVM debug proxy from any debugger compliant with the Java Platform Debugger Architecture.  The Compliant debuggers include jdb, Sun™ ONE Studio (formerly known as Forte™ for Java), JBuilder, Code Warrior, Visual Café etc.

Deploy the Project

Now we will be discussing about the deployment process. We have reached the stage where we can deploy the MIDlet directly on our mobile device and also run it. Basically there are two ways to do this. Naturally the first is via a network connection between our computer and our handset device. This process can either be via a USB (Universal Serial Bus) cable or a Bluetooth wireless connection and depending on our device. Most of Java-enabled devices will allow us to install J2ME applications via this connection.

Second, the one that is more motivating chapter because it opens up our MIDlet to the outside world via the Internet system. Generally, this means that our device should be able to connect to the Internet using its internal browser.

Click <a href=”DateTimeAppliction.jad”>here</a> to download DateTimeApplication MIDlet!

Processing to get the code in the our own device:

When we have created our gorgeous little MIDlet and ensured that everything worked smoothly in the emulator and the next step is to get it running on an actual device.

Over The Air (OTA) Provisioning:

OTA provisioning that allows users to download our application wirelessly using the WAP browsers built into their phones (mobile). To start it we need to take a look at the Java Application Descriptor (JAD) file that is produced when we package a MIDlet using the J2ME Wireless Toolkit. When we edit a JAD file by means of the Wireless Toolkit then we must open our project and also click on Settings option. That will open up a new window with a number of tabs – API Selection, Required, Optional, User Defined, MIDlets, Push Registry and Permissions.

These all types of Application are very vital and important in our working field. Following table gives brief idea.


In the above discussion we have got knowledge on the Java Micro Edition. We know that this Edition is suitable for the mobile software development platform. Because when we are working in the mobile software based technology then J2ME is very much reliable and helpful for us. If we are working in that particular filed as a mobile software developer then Java platform is highly secured.

Hope you have got the understanding of the MIDlet creation and its practical implementation. Keep watching in TechAlpine !!

Kaushik Pal

Kaushik has 16 years of experience as a technical architect and software consultant in enterprise application and product development. He has interest in new technology and innovation area along with technical writing. His main focus is on web architecture, web technologies, java/j2ee, Open source, big data and semantic technologies. He has demonstrated his expertise in requirement analysis, architecture design & implementation, technical use case preparation, and software development. His experience has spanned in different domains like Insurance, banking, airlines, shipping, document management etc. Kaushik worked with a wide variety of technologies starting from Mainframe (IBM S/390), midrange (AS/400), web technologies and open source area. He has worked with clients like IBM, Lexmark, United Airlines and many more.
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments
Back to top button