February 25, 2021
Hot Topics:

The Basics of J2ME

  • By Prentice Hall
  • Send Email »
  • More Articles »

Java Virtual Machines

As you well know, the engine behind any Java application (or applet, servlet, etc.) is the JVM.

Once you've compiled your Java source code into a class file(s), and optionally included them in a Java Archive (JAR) file, the JVM translates the class files (more accurately, the byte code in the class files) into machine code for the platform running the JVM. The JVM is also responsible for providing security, allocating and freeing memory and managing threads of execution. It's what makes your Java programs go, so to speak.

For CDC, the virtual machine has the same specification as J2SE. For CLDC, Sun has developed what is referred to as a reference implementation of a virtual machine, known as the K Virtual Machine, or simply KVM. This virtual machine was designed to handle the special considerations of resource-constrained devices. It's clear the KVM is not the "traditional" Java virtual machine:

  • The virtual machine itself requires only 40 and 80 kilobytes of memory
  • Only 2040 kilobytes of dynamic memory (heap) are required
  • Can run on 16-bit processors clocked at only 25 MHz

The KVM is Sun's implementation of a JVM that fits the guidelines of the CLDC. It is not necessarily the only JVM that is or will be available.

How are the KVM and CLDC Related?
From Sun's documentation: "CLDC is the specification for a 'class' of Java virtual machines that can run on the categories of devices targeted by CLDC and support the profiles." Essentially, the CLDC outlines requirements that must be met by the virtual machine. The KVM is what is known as a reference implementation—it is a virtual machine that meets the CLDC requirements.

Big Picture View of the Architecture

We've covered an assortment of information about J2ME. Let's put all this together into two separate scenarios. The first is a "generic" software architecture, if you will, of J2ME. The second is the architecture as it will apply to our interests as we progress through the book.

Generic Architecture

It begins with the host Operating System (OS) as the base (see Figure 1-2), followed by the virtual machine (VM). The VM will take one of two forms:

  • For systems complying with the CDC, it will be the "traditional"virtual machine; that is, the same feature set as in theJava 2 Standard Edition.

  • For systems complying with the CLDC, it will be the KVM or a virtual machine that meets the specifications as required by the CLDC.

CLDC or CDC core libraries are next in the heirarchy. Profiles are the topmost layer, and are designed to provide a toolkit for writing applications for a particular device family.

Figure 1-2 "Generic" J2ME architecture

Figure 1-3 "MID Profile architecture

MIDP Architecture

As before, the host OS is the base. The virtual machine will be the KVM. Remember, the KVM is Sun's implementation of a JVM meeting the CLDC specificationit may not be the only implementation available of a virtual machine for MIDP. CLDC core libraries are next, followed by MID Profile.

Compatibility between Java Editions

At the beginning of this section, I introduced Sun's Java tagline: "Write Once, Run Anywhere." Now that we've introduced Configurations, Profiles and a KVM, do you think this still applies? Well, the answer is, sort of.

Will J2SE applications run on J2ME?

J2ME is basically a slimmed down version of J2SE. Many components have been removed to keep the platform small and efficient. An obvious example is that of the Abstract Window Toolkitmany mobile devices do not have the screen capabilities to provide advanced user interface components such as overlapping windows and drop-down menus.

On the other hand, if you write J2SE code that adheres only to the classes that are available within the J2ME Configuration you are targeting, then your programs will run on both platforms. Keep in mind, such applications will most likely be very constrained, with little to no user interface, as J2ME and J2SE offer completely different APIs for handling the display.

Will J2ME applications run on J2SE?

The same rules apply here. If you limit the code to what is common on both platforms, the answer is yes. However, the majority of software you write for a J2ME device will require special interface and event handling code. Thus, you are greatly limited to what types of programs will be appropriate for both platforms.

Putting all the Pieces Together

Sun created the Java 2 Micro Edition to allow development of Java applications for devices that do not have the same processing power and memory found on a typical desktop platform. Products may include cellular phones, PDAs, pagers, entertainment and automotive navigation systems, to name just a few.

J2ME is divided into two broad categories, known as Configurations. CDC is a set of APIs to support "fixed" devices such as a television set-top box. CLDC is a set of APIs targeted at devices that have limited processing power, display and memory. The majority of these devices will also be mobile (e.g., cellular phones and pagers).

A Configuration is closely tied to a Java virtual machine. For CDC, the virtual machine is compatible with the virtual machine of the Java 2 Standard Edition. The KVM, a virtual machine that takes into consideration the limited resources available on devices that fit this configuration, was developed for the CLDC.

On top of Configurations are device Profiles. Here you will find the APIs for user interface design, networking support and persistent storage. The Mobile Device Information Profile and the associated libraries are the main focus of this book.

This is a sample chapter of Core J2ME Technology and MIDP
by John W. Muchow
ISBN: 0-13-066911-3

For the full text, visit http://www.phptr.com
©2001 Pearson Education. All Rights Reserved.

# # #

Page 3 of 3

This article was originally published on August 6, 2002

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date