Professional Documents
Culture Documents
Portability
This configuration includes a wide range of Java libraries and a comprehensive collection of virtual
machine features. CDC supports the following Java packages:
Package
Description
java.net
java.util
java.udl.zio
java.util.jar
ja va. Io
ja va. Text
java.security
java.security.cert
java.math
java.lang
Java.lang.ref
Reference classes
Java. microedition. io
Note
A J2ME application cannot access customized
packages.
CLDC
CLDC, on the other hand, handles devices that are less powerful than high-end consumer devices. Some of
the commonly used devices that use CLDC are mobile phones, personal organizers, and pagers. CLDC is a
subset of CDC. In addition to some of the J2SE classes, CLDC includes some new classes that are specifically
used for low-end consumer devices. CLDC specifies the basic set of libraries and virtual machine features for
running J2ME applications. Java has launched a new virtual machine named Kilobyte Virtual Machine
(KVM) for implementing the CLDC specifications. KVM is derived from JVM and is written in C
programming language. KVM also specifies several optional features that can be used depending upon the type
and capabilities of a mobile device. CLDC, along with KVM, forms a part of the new J2ME run-time
environment.
java.lang
Classes
Class, Long, Runnable, Thread, ArithmeticException,
ArraylndexOutOfBoundException, ArrayStoreException,
ClassCastException,
ClassNotFoundException, Error, IllegalAccessException,
IllegalArgumentException,
IllegalMonitorStateException, IllegalThreadStateException,
IndexOutOfBoundException, Instantiation Exception,
ja va. io
ja va. util
The CLDC library contains several new interfaces and classes that are specific to
CLDC. These form a part of the j avax . microedit i on . io package, which is used
in J2ME to support the networking capabilities of CLDC. The following table lists these
classes.
Package
Classes
Javax.microedition.i
o
Package
Classes
java.lang
java.util
NOTE:
In some cases, the J2SE packages are used as is in J2ME, for example, the java.util and java.io packages. However,
due to resource constraints, only a sub set of certain J2SE packages, such as java.lang is used. Some of the
packages, such as the microedition package are completely rewritten for J2ME.4
.
Mobile Information Device Profile (MIDP)
MIDP contains additional libraries that provide Java APIs that interact with the user interface and database. In
addition, these Java APIs address issues such as application life cycle and device-specific networking. You can use
APIs available under MIDP to create a variety of applications, such as consumer applications and games. MIDP
applications are known as MIDlets.
The following table describes the various MIDP packages.
MIDP PACKAGE
ja vax. microedition.
lcdui
DESCRIPTION
User interface classes and interfaces
javax.microedition.io
java.lang
java.util
Note
The PDA profile, which belongs to the category of mobile information devices, is still in its construction stage.
MIDP is used in mobile information devices, such as mobile phones and pagers, which have the following
characteristics:
In addition, MIDP runs on low-end processors and creates minimum garbage. In J2ME, CLDC combines
with MIDP to forma comprehensive run-time environment. The interface for system-level services is provided by
the configuration, CLDC, and the interface for application-level services is provided by the profile, MIDP.
You can control the display of a pixel by specifying the color or gray-scale using bits. A one-bit display
means that a single bit is used for one pixel.
J2ME WIRELESS TOOLKIT
The J2EE and J2SE platforms are used to create applications that run on high speed, and
large memory devices. Java applications written for such devices are compiled by JVM
that uses large memory. However, KVM takes up lesser memory but is severely restricted
in its capabilities compared to JVM. Any virtual machine in a mobile application must be
able to identify and reject invalid class files. One of the restrictions of KVM is that it
cannot perform class file verifications. These verifications are required to filter the class
files that do not belong to the CLDC configuration. Therefore, a mechanism is needed to
perform the class file verifications outside KVM and this is accomplished by J2ME
Wireless Toolkit. This toolkit is a set of tools from Sun that is used to build and test MIDlets.
After a MIDlet is created, it has to be tested to ensure that the application runs successfully. If
the MIDlet is developed to run in different mobile devices, it needs to be tested in each of
Bytecode verifier
J2ME emulator
In addition, certain J2ME Wireless toolkits, such as SDK for J2ME, released by Motorola
also contain an additional component known as Configuration editor.
The Bytecode Verifier
As mentioned earlier, a J2ME MIDlet must conform to the CLDC configuration. J2ME
does not support all class files available in J2SE. CLDC configuration further limits the
usage of these class files. In such a scenario, the virtual machine must be able to locate
and reject all invalid class files from a MIDlet and retain only the valid ones. KVM
cannot perform these tasks. Therefore, a bytecode verifier is used for this purpose. This
process of filtering invalid classes is known as pre-verification. The pre-verification
process is carried out during the development phase of a MIDlet. The verified MIDlet is
then ready to be loaded as an application. The advantage of having a bytecode verifier is
that it reduces the workload of KVM. This enables KVM to concentrate entirely on the
compilation process without having to check for invalid class files. To summarize, the
bytecode verifier:
Is used to locate and reject all invalid class files from a MIDlet and retain
only the valid ones. This process of filtering invalid classes is known as
pre-verification.
Manifest file: Also called application descriptor, this file describes the
MIDlets, such as name of MIDlet, vendor name, and so on. This file is
saved with the extension jad.
Other resources: These resources include image files and sound files that are used
by the MIDlets.
A single JAR file might contain more than one MIDlet. A number of MIDlets together
forma MIDlet suite. The application descriptor provides information needed to access a
particular MIDlet from a suite. This application descriptor is stored as a .j ad file within a
JAR file. The other resources stored in a JAR file include sound and image files.
The J2ME Emulator
Before a MIDlet is ready to be deployed, it has to be tested in real-life conditions. This
involves testing a MIDlet within each device for which it is created. The J2ME emulator
is used to perform this test. The emulator provides an efficient simulated environment to
test the code on a PC. When the simulation is carried out, the image of the device
appears on the screen and the application executes exactly as it would execute in that
particular device. The user can interact with the device by using the mouse to click the
various buttons available on the device.
J2ME Wireless Toolkit is capable of simulating the environments of the following devices:
DefaultColorPhone
DefaultGrayPhone
Motorola i85s
PaImOSDevice
FJMavaHand-held
A J2ME emulator offers the following advantages:
Helps you run a MIDlet repeatedly in a simulated environment until the errors are
fixed
Provides a single interface on which you can test run the MIDlets on different
devices
Although you might consider the J2ME emulator as a complete solution provider, it has
certain limitations. There area few characteristics of MIDlets that an emulator cannot test and
verify with absolute accuracy.
These limitations include:
Execution speed
Memory availability
A MIDlet is created to run in various devices, each with its own processor speed. Therefore, it is desirable
to have an emulator that tests the MIDlets in various speeds. Unfortunately, this is not possible with the
current version of J2ME Wireless Toolkit.
The same holds true for testing the memory available for MIDlets in various
devices. Memory availability determines how well an application runs within a
device. It is not possible to test run a MIDlet in an emulator by varying the
available memory.
Another limitation of the emulator is its inability to simulate the working of
the application manager that resides on every mobile device. The
application manager is responsible for adding, removing, and executing
the MIDlets within a mobile device. The emulator cannot simulate the
working of an application manager. Therefore, it cannot determine exactly how
these MIDlets are managed within a device.
The Configuration Editor
The Configuration editor helps a user configure the device environment. It
means that the user can alter the various profiles available within a device.
For example, the user can modify the device image, screen size, and buttons
available in a device. In this way, the editor provides a mechanism for the user to
control the simulated environment.
Note
The configuration editor is not available with the standard J2ME Wireless Toolkit released
by Sun. However, this standard toolkit enables a user to configure the device environment.
It is available in the SDK for J2ME released by Motorola.
KToolbar
Note
You will learn more about the KToolbar environment because you will be building most of your
applications in this environment.
KToolbar
KToolbar provides a simple visual environment to test run MIDlets. It has limited features compared
to those offered by Forte for Java, the latest visual environment from Sun Microsystems. It manages
source code files effectively and automates the building process of MIDlets. However, it does not have an
editor of its own. Therefore, code has to be written in a text editor outside the KToolbar environment.
KToolbar provides all the utilities required to perform pre-verification and emulation of code.
Note
KToolbar is available with J2ME Wireless Toolkit and is automatically installed with the toolkit. To open
KToolbar, select Start, Programs, J2ME Wireless Toolkit 1.0.3, KToolbar.
SUMMARY
J2ME is used for small handheld devices, such as mobile phones, pagers, and PDAs, which have major
hardware constraints.
The two types of configurations in J2ME platform are CDC and CLDC.
There are various categories of CLDC library APIs, such as classes that are a subset of J2SE and classes
that are specific to CLDC.
CLDC, along with KVM, combines with MIDP to form the run-time environment for a J2ME
application.
The structure of J2ME Mobile Toolkit consists of the bytecode verifier and J2ME emulator.
The bytecode verifier performs checks to ensure that invalid class files are not
present in a MIDlet.