j2me step by step, e-book, JAVA
[ Pobierz całość w formacie PDF ]
J2ME: Step by step
Presented by developerWorks, your source for great tutorials
ibm.com/developerWorks
Table of Contents
If you're viewing this document online, you can click any of the topics below to link directly to that section.
2
4
8
J2ME: Step by step
Page 1
Presented by developerWorks, your source for great tutorials
ibm.com/developerWorks
Section 1. Tutorial tips
Should I take this tutorial?
This tutorial examines in detail the Java 2 Platform, Micro Edition (J2ME) and targets the
intermediate developer who has a solid background in Java programming and the concepts
of object-oriented design and development.
You'll start off by examining the background of J2ME and exploring the J2ME configurations
and profiles. You'll then step through the process of setting up your development
environment for developing J2ME applications.
You'll be introduced to topics such as the K virtual machine (KVM) and KJava API used in
conjunction with the Connected Limited Device Configuration (CLDC) API, and the Mobile
Information Device Profile (MIDP), which uses CLDC. You will then build a simple application
that will allow you to see what you can do with J2ME. You'll use CLDC and KJava to develop
a basic drawing application and also a small MIDP application.
Requirements
To work through this tutorial, you will need the following:
*
The
(formerly known as a JDK); J2SE 1.3 SDK is recommended. In
particular, you will use the following tools from the Java 2 SDK:
*
java
javac
*
*
jar
javadoc (optional)
*
*
The
reference implementation
*
The K virtual machine (KVM), which is included with the CLDC reference
implementation
*
The
*
The
, which you can use to test your KJava applications
before deploying to a "real" Palm OS device.
*
A Palm handheld device
Getting help
For technical questions about J2ME, visit the
.
For questions about the content of this tutorial, contact the authors, Shari Jones, at
, or Steven Gould, at
.
Shari Jones is a freelance journalist and a technical writer. She is a former consultant and
has more than ten years experience writing technical articles and documentation covering all
areas of the high-tech industry.
Steven Gould is an Executive Consultant with CGI Information Systems. Based in Dallas, he
J2ME: Step by step
Page 2
Presented by developerWorks, your source for great tutorials
ibm.com/developerWorks
is a systems architect and senior developer, focusing primarily on Java and C++
development under Windows and various UNIX platforms. A Sun-certified Java developer,
Steven has been using Java since the JDK 1.0 beta release.
J2ME: Step by step
Page 3
Presented by developerWorks, your source for great tutorials
ibm.com/developerWorks
Section 2. J2ME overview
Introduction
This section will get you started using J2ME. We'll begin by defining J2ME, then we'll discuss
its general architecture and learn about the devices J2ME targets. As part of the architecture
discussion, we will provide an overview about profiles and configurations. (We'll address the
details of both profiles and configurations in later sections.) We also will cover briefly some
considerations for packaging and deploying J2ME applications.
What is J2ME?
Sun Microsystems defines J2ME as "a highly optimized Java run-time environment targeting
a wide range of consumer products, including pagers, cellular phones, screen-phones,
digital set-top boxes and car navigation systems."
Announced in June 1999 at the JavaOne Developer Conference, J2ME brings the
cross-platform functionality of the Java language to smaller devices, allowing mobile
wireless devices to share applications. With J2ME, Sun has adapted the Java platform for
consumer products that incorporate or are based on small computing devices.
General J2ME architecture
J2ME uses configurations and profiles to customize the Java Runtime Environment (JRE).
As a complete JRE, J2ME is comprised of a configuration, which determines the JVM used,
and a profile, which defines the application by adding domain-specific classes.
The
configuration
defines the basic run-time environment as a set of core classes and a
specific JVM that run on specific types of devices. We'll discuss configurations in detail in the
section on
on page
.
The
profile
defines the application; specifically, it adds domain-specific classes to the J2ME
configuration to define certain uses for devices. We'll cover profiles in depth in the section on
on page
.
The following graphic depicts the relationship between the different virtual machines,
configurations, and profiles. It also draws a parallel with the J2SE API and its Java virtual
machine. While the J2SE virtual machine is generally referred to as a JVM, the J2ME virtual
machines, KVM and CVM, are subsets of JVM. Both KVM and CVM can be thought of as a
kind of Java virtual machine -- it's just that they are shrunken versions of the J2SE JVM and
are specific to J2ME.
J2ME: Step by step
Page 4
Presented by developerWorks, your source for great tutorials
ibm.com/developerWorks
Configurations overview
The configuration defines the basic run-time environment as a set of core classes and a
specific JVM that run on specific types of devices. Currently, two configurations exist for
J2ME, though others may be defined in the future:
*
Connected Limited Device Configuration (CLDC)
is used specifically with the KVM
for 16-bit or 32-bit devices with limited amounts of memory. This is the configuration
(and the virtual machine) used for developing small J2ME applications. Its size
limitations make CLDC more interesting and challenging (from a development point of
view) than CDC. CLDC is also the configuration that we will use for developing our
drawing tool application. An example of a small wireless device running small
applications is a Palm hand-held computer. We will cover CLDC in depth in the section
on
on page
.
*
Connected Device Configuration (CDC)
is used with the C virtual machine (CVM) and
is used for 32-bit architectures requiring more than 2 MB of memory. An example of
such a device is a Net TV box. CDC is outside scope of this tutorial, although we will
cover it briefly later on in the section on
on page
.
Profiles overview
The profile defines the type of devices supported by your application. Specifically, it adds
domain-specific classes to the J2ME configuration to define certain uses for devices. Profiles
are built on top of configurations. Two profiles have been defined for J2ME and are built on
CLDC: KJava and Mobile Information Device Profile (MIDP). These profiles are geared
toward smaller devices.
A skeleton profile on which you create your own profile, the Foundation Profile, is available
for CDC. However, for this tutorial, we will focus only on profiles built on top of CLDC for
smaller devices.
We will discuss both of these profiles in later sections and will build some sample
applications using KJava and MIDP.
Devices J2ME targets
J2ME: Step by step
Page 5
[ Pobierz całość w formacie PDF ]