ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Java 2ME and MIDP Development

by John W. Muchow
03/22/2001

Welcome to the world of MIDlets. A MIDlet is a Java application that conforms to the specifications set out by the Connected, Limited Device Configuration (CLDC) and the Mobile Information Device Profile (MIDP).

As you might guess from the specification names, MIDlets are targeted at mobile devices that provide some level of network connectivity. The devices that will run MIDlets also have several common attributes: limited screen size, memory and processing power. The specifications are designed to address these considerations. Typical devices include cellular phones and pagers.

This article will focus on the installation and configuration of the CLDC and MIDP software. We will also write a simple MIDlet and learn the steps required for previewing the MIDlet in a mobile device emulator.

The CLDC defines a specification for a Java virtual machine and a set of core libraries. The CLDC is essentially a slimmed down version of the Java 2 Standard Edition (J2SE) designed for devices with limited memory and resources.

A configuration (for example, CLDC) is designed to run with what is known as a Profile. The MID Profile is a specification that provides a core set of libraries for writing Java applications targeted for mobile devices. A profile defines the libraries that are used by developers to write applications for a specific device or for range of devices. For example, MIDP defines classes for creating user interfaces (textboxes, forms, etc), handling user input, and communicating over a network with HTTP.

Download the Software

Before you can write a MIDlet, you need to download the required software: the Java Developer's Kit (JDK), Connected, Limited Device Configuration (CLDC) and the Mobile Information Device Profile (MIDP).

You may also choose to download the J2ME specification. This download includes the MIDP API. A great reference once you begin development of MIDlets.

Install the Software

Java Developers Kit
The JDK has default directories for installing the files. If you choose to install to a directory other than the default, you will need to write this down, as we will use this path as we progress through this installation.

If you install JDK version 1.3, and choose the default paths, the JDK will be installed into the directory:

c:\jdk1.3

Are you curious about why you need the JDK? Neither the CLDC nor MIDP include the Java compiler (javac.exe) as part of their respective installation. Obviously, without the ability to compile you Java code, you won't get very far.

Connected, Limited Device Configuration (CLDC)
Extract the zip file that you download onto your hard-drive. I recommend the path c:\j2me. Here is what the directory structure will look if you extract the files to the path c:\j2me:

c:\j2me
       |
       j2me_cldc

Mobile Information Device Profile (MIDP)
Once again, extract the zip file to your hard drive. Use the same directory as above: c:\j2me. You will now have a directory structure that should look similar to this:

c:\j2me
       |
       j2me_cldc
       midp-fcs

Configure the Software

Updating the PATH
The PATH environment variable is used by Windows to locate executable programs. We need to update the PATH to point to the location of the Java compiler, as well as directories for the CLDC and MIDP programs.

Update the PATH for JDK

Windows 2000 or Windows NT

  • From the Control Panel choose System
  • Click Environment (or Advanced/Environment)
  • Find the PATH entry and at the end, add the location of the /bin directory in your JDK install path. Assuming you installed version 1.3 of the JDK, and selected the default installation path, you would add the following to the end of the path:
    C:\jdk1.3 

For Windows 98 or Windows 95

Windows includes a program called the System Configuration Editor. This program is a quick and easy way to update configuration files including: win.ini, system.ini, config.sys and autoexec.bat. To start the editor from within Windows:

  • Click the Start button
  • Select Run
  • Enter sysedit in the dialog box
  • Click Ok

Find your way to the autoexec.bat dialog box. Assuming you installed version 1.3 of the JDK, and selected the default installation path, enter the following:

If there is not an entry for PATH add this line:

    PATH=C:\jdk1.3\bin

If there is an entry for PATH, find the end of the entry and add:

C:\jdk1.3\bin

Update the PATH for CLDC
You will also need to update your PATH environment variable to point to the directory where the CLDC executable files are located (the K Virtual Machine and class file preverifier).

Follow the same steps as outlined above to add to the PATH: C:\j2me\j2me_cldc\bin

Update the PATH for MIDP
One last time, update your PATH environment to reference the directory where the MIDP executable file is located; this is the cellular phone emulator for testing your MIDlets.

Follow the same steps as outlined above to add to the PATH: C:\j2me\midp-fcs\bin

Update/Insert the CLASSPATH Environment Variable
CLASSPATH tells the Java compiler where to search for classes that are not part of the Java (JDK) platform itself. In our case, we need to update CLASSPATH to refer to the MIDP classes. You will also need to have a reference to the current directory (".") as part of the CLASSPATH.

Follow the same steps as outlined for the PATH, to update the CLASSPATH: CLASSPATH=C:\j2me\midp-fcs\classes;. -- notice the "." at the end to represent the current working directory.

Insert the SCREEN_DEPTH Environment Variable
MIDP includes a mobile device emulator to test your MIDlets. The emulator can run in color or various shades of black and white. To specify the number of colors, you can add the environment variable named SCREEN_DEPTH. For example:

SCREEN_DEPTH=8

You can add this variable to the environment as you did with the PATH and CLASSPATH variable.

SCREEN_DEPTH values and colors:
Value Number of colors
1 2
2 4
4 16
8 256

Pages: 1, 2

Next Pagearrow