2ME Laboratory Sheet CS4289/CS5289 Projects in Pervasive Computing
2ME Laboratory Sheet CS4289/CS5289 Projects in Pervasive Computing
2ME Laboratory Sheet CS4289/CS5289 Projects in Pervasive Computing
I. Objective
A mobile phone, which lacks the computational power, memory, and workstation
power, cannot perform the same functionality as high-end servers or client workstations.
J2ME aims to port the Java programming language to devices with resource limitations. There
are various kinds of mobile phones, and it is the reason why J2ME is divided into
configurations, profiles, and optional packages. Configurations are specifications that detail a
virtual machine and a base set of APIs that can be used with a certain class of devices. A
configuration, for example, might be designed for devices that have less than 512 KB of
memory and an intermittent network connection.
Connected, Limited Device Configuration (CLDC) is for small wireless devices with
intermittent network connections, like pagers, mobile phones, and Personal Digital Assistants
(PDAs). CLDC consists of a standardized set of functionalities that all vendors who offer
J2ME-certified phones will support.
The Mobile Information Device Profile (MIDP), which is based on CLDC, was the
first finished profile and thus the first finished J2ME application environment. It is designed
for supporting the various kinds of cell phones or similar devices constrained by screen and
keypad limitations, in addition to the battery, processor, and bandwidth constraints. The
profile contains a series of APIs that let you create anything from video games using
customized graphics to full-scale business applications using external and internal data
sources.
Optional packages with CLDC, CDC, and their corresponding profiles are created to
meet different specific market requirements. Optional packages offer standard APIs for using
both existing and emerging technologies such as Bluetooth, Web services, wireless messaging,
multimedia, and database connectivity. Because optional packages are modular, device
manufacturers can include them as needed to use the features of each device.
The KVM (kilo virtual machine) and the interpreter are both contained in the CLDC.
J2ME also provides another version for high-end PDA and other mobile devices which have
more processing capability as shown in Figure 1.
1
J2ME Laboratory Sheet CS4289/CS5289 Projects in Pervasive Computing
Figure 1
(Source : http://java.sun.com/j2me/j2me-ds.pdf)
The toolkit enables users to select the configurations, profiles, and optional packages
that will be used by the MIDlets applications. The APIs calls will be verified during the build
and packaging process as some of APIs may not be supported in some profiles.
JavaTM 2 SDK, Standard Edition (J2SE SDK), version 1.4.2 (current version 1.4.2_10
- http://java.sun.com/j2se/1.4.2/download.html) is required for this toolkit.
It is totally free of charge but you need to register to the Sun Download Center first.
The registration is also free of charge.
2
J2ME Laboratory Sheet CS4289/CS5289 Projects in Pervasive Computing
Note:
JAR file is a file format based on the popular ZIP file format. It is used for aggregating many
files into one. They are commonly used as building blocks for applications and extensions. A
JAR file manifest consists of a main section followed by a list of sections for individual JAR
file entries. The main section contains security and configuration information about the JAR
file itself, as well as the application or extension that this JAR file is a part of. The individual
section defines various attributes for packages or files contained in this JAR file. Not all the
files in a JAR file need to be listed in the manifest as entries. However, all the files which are
to be signed must be listed.
(Source : http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#JAR%20Manifest)
3
J2ME Laboratory Sheet CS4289/CS5289 Projects in Pervasive Computing
Notice :
Directory Structure :
4
J2ME Laboratory Sheet CS4289/CS5289 Projects in Pervasive Computing
package cs4289.j2me2_2;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
* constructor
*/
public helloMidlet() {
super();
display_scr = Display.getDisplay(this);
tb_msg.addCommand(cmd_exit);
tb_msg.setCommandListener(this);
}
/**
* Called when this MIDlet is started for the first time,
* or when it returns from paused mode.
*/
public void startApp() {
System.out.println("startApp() is called");
display_scr.setCurrent(tb_msg);
}
/**
* Called when this MIDlet is paused.
*/
public void pauseApp() {
System.out.println("pauseApp() is called");
}
5
J2ME Laboratory Sheet CS4289/CS5289 Projects in Pervasive Computing
/**
* Destroy must cleanup everything not handled
* by the garbage collector.
*/
public void destroyApp(boolean unconditional) {
System.out.println("destroyApp() is called");
}
5. Click Run (at short cut bar) and show the result to your instructor.
Code explainations
As you can see, the Command class constructor takes three parameters. It contains the
following three pieces of information: label, type, and priority.
The label is a string for the visual representation of the command. For example, the
label may appear next to a soft button on the device or as an element in a menu as
shown in Figure 1.
The type specifies the command's intent. The defined types are: BACK, CANCEL,
EXIT, HELP, ITEM, OK, SCREEN, and STOP.
The priority value describes the importance of this command relative to other
commands on the screen. A priority value of 1 indicates the most important command,
and higher priority values indicate commands of lesser importance.
The documentation of API can be found at the directory of the wireless toolkit.
({j2mewtk.dir}\docs\api\midp\index.html)
6
J2ME Laboratory Sheet CS4289/CS5289 Projects in Pervasive Computing
Modify the program to make it to accept user information and show all information
after pressing the “Confirm” command.
You need to create one more TextField(s) for accepting user information.
Note: The J2ME documentation is located at the following directory. You may use
them for references.
H:\WTK22\docs\api\midp\index.html
Hints : You need to refer to the following classes to complete lab task I
Class Display
Class Screen (Abstract Class)
Class Ticker
Class Form
Class Alert
Class TextField
Class Command
7
J2ME Laboratory Sheet CS4289/CS5289 Projects in Pervasive Computing
References:
2. http://java.sun.com