Sun Java Solaris Communities My SDN Account Join SDN
 
Article

J2ME for Home Appliances and Consumer Electronic Devices

 

The Java 2 Platform, Micro Edition (J2ME) is aimed at the market for consumer and embedded electronic devices: cellular telephones, two-way pagers, Personal Digital Assistants (PDAs), set-top boxes, and other small devices. Since J2ME's release, hundreds of companies have joined the development effort, including large corporations such as Motorola, Nokia, Ericsson, Palm, Samsung, WindRiver, Sharp, Siemens, Sympian, and RIM. This vote of confidence is not surprising; J2ME provides a complete set of solutions for creating state-of-the-art networked applications for small devices. An added attraction is that the direction J2ME travels is not masked in corporate secrecy; its development is handled openly, through the Java Community Process (JCP).

Currently, J2ME offers two standard configurations: The Connected Limited Device Configuration (CLDC) is prevalent in the J2ME world, and powers cellular phones, pagers, PDAs, and other handheld devices. The Connected Device Configuration (CDC) targets more powerful devices, such as home appliances, set-top boxes, and Internet TVs. The Mobile Information Device Profile (MIDP) runs on top of the CLDC, and several profiles run on top of CDC. This article is a tutorial introduction to CDC, its virtual machine CVM, and three related profiles: Foundation, Personal, and Personal Basis. This article:

  • Describes CDC's place in the J2ME context
  • Presents an overview of profiles implemented on top of CDC
  • Provides instructions on downloading and building CDC, CVM, and the profiles
  • Shows how to get started developing applications for consumer and embedded devices
  • Presents code examples that demonstrate how to use CDC and its components
  • Discusses the different application models supported by CDC

A High-Level View of J2ME

J2ME defines two major categories of components:

  • Configurations comprise a Java virtual machine and a minimal set of class libraries. Think of a configuration as a vertical set of APIs that provides the base functionality for a particular range of devices that share similar characteristics, such as memory footprint and network connectivity. A configuration also defines a Java virtual machine to be used on different types of devices.
  • Profiles constitute a horizontal set of high-level APIs that defines the application life-cycle model, the user interface, and access to services provided by a category of devices. A profile is typically a superset or a subset of another profile.

These components make up the J2ME architecture, as shown in Figure 1. At the heart of J2ME is a configuration, whose Java virtual machine interacts with the device's host operating system. One or more J2ME profiles add programming libraries that provide access to device capabilities such as I/O and GUI. Together, a configuration and a profile compose a J2ME runtime environment. For example, the MIDP profile sits on top of the CLDC configuration, which includes the KVM virtual machine. A number of optional packages extend the J2ME platform, offering standard APIs for using existing and emerging technologies (Bluetooth and web services, for example).  Optional packages provide access to services that are useful on more than one class of device, but not on all.

High-level View of J2ME Architecture
Figure 1: High-level View of J2ME Architecture

Figure 2 shows how CDC and its related technologies realize this architecture.

J2ME CDC and Related Technologies
Figure 2: J2ME CDC and Related Technologies

CDC

CDC is a Java Community Process effort (JSR 36) that has standardized a portable, Java-technology building block for consumer electronics and embedded devices. It provides a set of basic libraries and a Java virtual machine appropriate for use with profiles for vertical product markets. CDC targets powerful devices that are intermittently connected to a network, including set-top boxes, interactive TVs (iTVs), home appliances, and car navigation systems.

CDC contains a full-featured Java virtual machine.  CVM's capabilities are similar to the JVMs that support the Java 2 Platform, Standard Edition (J2SE). The main differences lie in the memory and display capabilities of the devices targeted.

A device that meets the resource requirements that J2ME specifies for CDC:

  • Is powered by a 32-bit processor
  • Makes available to the Java runtime at least 2 MB of memory, including both RAM and flash memory or ROM
  • Requires the full functionality of the Java Virtual Machine Specification
  • Has connectivity to some kind of network, often wireless
  • May have a user interface with some degree of sophistication

It's worth noting that applications written using the CLDC APIs are upward-compatible with CDC.

The CDC Class Library

CDC includes a minimal set of APIs, only those packages from J2SE v1.3 needed to build and run a virtual machine:

  • java.lang: virtual machine system classes
  • java.io: file input and output classes
  • java.net: UDP datagrams
  • java.util: Java utility classes
  • java.text: minimal support for internationalization
  • java.security: support for minimum fine-grain security and encryption for object serialization

CVM

The CDC configuration defines its own subset of JVM features.  Its virtual machine is called CVM.

.
. . .
. Note: CVM was once an acronym for "Compact Virtual Machine." Engineers at Sun Microsystems believed that people might confuse the "Compact" in CVM with the K in KVM, however, so now C doesn't stand for anything at all. The virtual machine is known simply as CVM. .
.
.

CVM is designed for the consumer and embedded devices that CDC targets. The reference implementation currently available from Sun Microsystems runs on Linux and VxWorks. It is implemented almost entirely in C, with about 100 lines of assembly code, and contains a well-documented porting layer that leaves anyone targeting a new platform a bare minimum of work to do.

.
. . .
. Note: Linux is becoming a commonly used development platform, and I believe it will excel in the market for embedded and consumer devices. .
.
.

Profiles for CDC

To make it possible to define Java platforms for vertical product markets, J2ME introduces profiles. At the implementation level, a profile is a set of APIs that reside on top of a configuration and give applications access to the capabilities of a category of devices. The profiles defined on top of CDC are the Foundation Profile, the Personal Profile, and the Personal Basis Profile.

The Foundation Profile

As its name suggests, the Foundation Profile is meant to serve as a foundation for other profiles, such as Personal and Personal Basis. It extends the APIs provided by CDC to provide those services that virtually all CDC-based applications need. Because not all need a user interface, this profile doesn't provide any UI APIs.

The foundation profile contains all the basic packages in J2SE 1.3 except the ones needed to support the GUI classes of java.awt. It contains the packages included in CDC, and additions and enhancements needed to give applications a complete foundation:

  • java.lang: the full java.lang package
  • java.io: all I/O packages
  • java.net: support for TCP sockets and HTTP
  • java.util: full support for ZIP files and other utility classes
  • java.text: full support for internationalization
  • java.security: support for code signing and certificates
.
. . .
. Note: When they inherited packages from J2SE, CDC and the Foundation Profile excluded all deprecated APIs that have new equivalents. The intent was to start off with a clean and correct set of APIs, and no need to support and maintain APIs that serve no useful purpose. The only deprecated APIs included are those don't have new equivalents. .
.
.

The Personal Profile

To support web-based applets, the Personal Profile extends the Foundation Profile with packages that provide a graphical user interface (GUI). The Personal Profile is a redefinition of PersonalJava, and therefore is backward-compatible with PersonalJava 1.1 and 1.2 applications. In other words, it provides the functionality of the PersonalJava environment in a next-generation J2ME profile. What is interesting about the Personal Profile is that it can support many graphics library specifications, such as Home Audio-Video interoperability (HAVi) and the Java TV API.

Applications based on the Personal Profile can be graphical or non-graphical. The profile provides graphics APIs based on the Abstract Windowing Toolkit, including the AWT's lightweight and heavyweight components. Applications with modest GUI requirements can use the Personal Basis Profile, which provides basic AWT support but excludes the heavyweight components.

The Personal Profile is a superset of the Personal Basis Profile, and applications based on the latter are upward-compatible. For example, an Xlet written for the Personal Basis profile will run on the Personal profile.

.
. . .
. Note: Most Personal Profile applications and applets can run in a J2SE environment, but Xlets, which use the javax.microedition package, cannot. .
.
.

You can use the Personal profile to create a wide variety of applications for PDAs, telematics, iTV, lottery terminals, and medical devices, electronic program guides for television, stock tickers, and home server applications for controlling home appliances and household services such as heating, lighting, entertainment, and security.

Some of the features of the Personal profile are:

  • Lightweight and heavyweight AWT components
  • Support for BigDecimal and BigInteger
  • Some JavaBeans support
  • Support for applets and for Xlets, including inter-Xlet communication

Application Models

The Personal Profile supports three kinds of applications:

  • Typical applications contain a static main() method, and are written as for the J2SE platform, except that they use the Personal Profile classes. Such applications may have a GUI (a medical monitoring application) or may not (a home server).
  • Applets are typical mini-applications run and managed by the Applet Viewer or a web browser. You write applets for the Personal Profile just as you do for the J2SE, except that you use the Personal Profile classes.
  • Xlets are applications that can be dynamically downloaded to the system running the Personal Profile. The user can execute a provider's application on demand. Like applets, Xlets are executed under tighter security restraints than local applications. The security mechanism prevents untrusted Xlets accessing system resources. An Xlet application consists of one or more Xlets and an Xlet manager, which runs Xlets and manages their states.

Applets are well suited for use with Internet browsers. Xlets on the other hand are suited for consumer-device applications such as television broadcasting, and indeed the Xlet application model was originally designed for iTV applications. Applets usually have a GUI, but don't always need one. An application that doesn't require a GUI can run as an Xlet. Such applications display some graphics on the screen and provide some interaction with the user. They synchronize with audio and video devices, and have a limited life.

The Personal Basis Profile

The Personal Basis Profile is a subset of the Personal Profile, and applications written for it are upward-compatible. This profile supports Xlets as well as typical applications containing static main(). Its footprint is smaller than the Personal Profile's because it excludes the heavyweight AWT components and provides no support for applets.

The Personal Basis Profile is well suited to the interactive TV market, as it contains the APIs necessary for the Java platform to support the Multimedia Home Platform (MHP) currently being developed. The MHP is a standard for enhanced broadcast interactive services; it defines an interface between interactive applications and the devices on which they run. For more information on MHP, see Digital Video Broadcasting Multimedia Home Platform.

The Personal Basis profile is also compatible with other major specifications for consumer electronics, such as Home Audio-Video interoperability (HAVi), the OpenCable Application Profile middleware specification for iTV services and MHP-based applications, and the DTV Applications Software Environment (DASE), an enhanced television standard that defines middleware that allows interactive and enhanced applications to run on a common receiver.

Downloading and Building CDC/CVM/Foundation

As I mentioned earlier, the J2ME CDC technology is available for the Linux operating system. If you have access to Linux, you can start developing future-generation applications for consumer electronic devices. The remainder of this article leads you through the processes of downloading and installing the resources you'll need, and of building applications.

You can download CDC, the Foundation Profile, and all the other profiles from the Sun Download Center if you're a member of the Java Developer Community (JDC membership is free).

The configuration and the profiles come in source format, so you'll need to compile the code yourself. To do so, you will need to fulfill the following requirements:

  • Red Hat Linux (v7.2 recommended), configured for multicast
  • Intel 686-compatible CPU
  • J2SE v1.3.1
  • 100 MB of available disk space
  • 16 MB RAM recommended

If you have a machine that satisfies these requirements, download CDC and the Foundation Profile, and unzip the archive file containing the source.

Note that you can build CDC by itself or with the Foundation Profile. If you build the profile, you'll be building both, because the Foundation Profile contains all the CDC libraries. You may wish to skip the first procedure, and begin at "To build the Foundation Profile with CDC."

To build CDC:

  1. Change directory to build/linux-686:

    cd build/linux-686

  2. Use a make command like the following to build CDC:

    make CVM_JAVABIN=/usr/local/jdk/bin CVM_GNU_TOOLS_PATH=/usr/bin

The CVM_JAVABIN option sets the path to your JDK bin directory, and CVM_GNU_TOOLS_PATH sets the path to the GNU tools. Note that the option values in boldface are machine-dependent, and yours may differ from mine.

If all goes well, several files will appear in the build/linux-i686 directory, including the bin/cvm subdirectory. You'll use the JAR file lib/cdc.jar for the CVM bootclasspath.

To test your installation, change directory to build/linux-i686/bin and enter the command:

./cvm -Djava.class.path=../testclasses.zip HelloWorld.

This command runs CVM to execute the class HelloWorld. It should print Hello World on the screen to indicate successful build and installation.

To build the Foundation Profile with CDC:

  1. Change directory to build/linux-686:

    cd build/linux-686

  2. Use a make command like the following to build CDC and the Foundation Profile:

    make J2ME_CLASSPATH=foundation CVM_JAVABIN=/usr/local/jdk/bin CVM_GNU_TOOLS_PATH=/usr/bin

The J2ME_CLASSPATH option controls the class library produced by the build. The default is cdc.

Again, the CVM_JAVABIN option sets the path to your JDK bin directory, and the CVM_GNU_TOOLS_PATH sets the path to the GNU tools. And again note that your values may need to differ from the ones shown in boldface.

If all goes well, several files will appear in the build/linux-i686 directory, including the bin/cvm subdirectory. You'll use the JAR file lib/foundation.jar for the CVM bootclasspath.

To test your installation, change directory to: build/linux-i686/bin and enter the command:

./cvm -Djava.class.path=../testclasses.zip HelloWorld.

This command runs CVM to execute the class HelloWorld. It should print Hello World on the screen to indicate successful build and installation.

Developing and Compiling New Applications

You can develop applications for the Foundation Profile the same way you develop J2SE applications. Remember, however, that this profile doesn't include any GUI libraries, so all applications for the Foundation profile are command-line programs. Here is a typical Hello application:

public class Hello {
    public static void main(String argv[]) {
	System.out.println("Hello there");
    }
}

Save this code in a file Hi.java under build/linux-i686/bin directory and compile it using:

javac -bootclasspath ../btclasses.zip:../lib/cdc.jar Hi.java

This command will produce Hi.class. To run it, enter:

cvm Hi

Building and Installing the Personal Profile

Sun Microsystems has made a compiled version of the Personal Profile Runtime Environment available so you can avoid the hassle of compiling the source code to build the implementation. If you download and unpack the binary distribution, you will get a new directory j2me-pp1.0 and several subdirectories including: bin, which contains the CVM, and lib, which contains personal.jar among other things. Go to the bin directory and use the cvm command to run the virtual machine. You may also wish to run the demo using the command j2me-pp1.0/rundemo

If you prefer to build and install the Personal Profile yourself, download its reference implementation to your Linux machine from the Sun Download Center, and unzip the source archive file. Then:

  1. Change to the personal/build/linux-i686 directory.
  2. Enter:

    make J2ME_CLASSLIB=personal JDK_HOME=your-java-home-dir CVM_GNU_TOOLS_PATH=/usr/bin

If all goes well, the make command will produce several files in build/linux-i686, including bin/cvm. You'll use lib/personal.jar for the CVM bootclasspath.

To test your installation, change directory to: build/linux-i686/bin and enter:

./cvm -Djava.class.path=../testclasses.zip HelloWorld.

This command executes HelloWorld. It should print Hello World to indicate successful build and installation.

Here is a sample Hello applet:

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
public class HelloApplet extends Applet {
   private StringBuffer buffer;

   public void init() {
      buffer = new StringBuffer();
      addMessage("Initializing....");
   }
   public void start() {
     addMessage("Starting....");
   }
   public void stop() {
     addMessage("Stopping....");
   }
   public void destroy() {
     addMessage("Unloading....");
   }
   public addMessage(string msg) {
     buffer.append(msg);
     repaint();
   }
   public void pain(Graphics g) {
     g.drawString(buffer.toString(), 10, 35);
   }
}

To test this applet, copy it to a file HelloApplet.java and save it in build/linux-i686/bin. Now compile it using:

javac -bootclasspath ../btclasses.zip../lib/personal.jar HelloApplet.java

Before you can run it, you first need to create an HTML file Hello.html with the appropriate applet reference:

<html>
<head>

<title>Sample Applet</title>
</head>
<body>
<applet code="HelloApplet.class" width="400" height="300">

</applet>
</body>
</html>

Now you can run the applet:

cvm sun.applet/AppletViewer Hello.html

Installing the Personal Basis Profile

To install the Personal Basis profile, download its reference implementation to your Linux machine, and unzip the archive.

To build the implementation:

  1. Change to the basis/build/linux-i686 directory
  2. Enter:

    make J2ME_CLASSLIB=basis JDK_HOME=your-java-home-dir CVM_GNU_TOOLS_PATH=/usr/bin

If all goes well, this command will produce several files in build/linux-i686, including bin/cvm. You'll use lib/basis.jar for the CVM bootclasspath.

To test your installation, change to build/linux-i686/bin and enter:

./cvm -Djava.class.path=../testclasses.zip HelloWorld

This command executes HelloWorld. It should print Hello World to indicate successful build and installation.

You should also test the installation with an Xlet. To compile the Xlet using the Personal Basis profile APIs, use:

javac -bootclasspath personal/build/linux-i686/btclasses.zip: personal/build/linux-i686/lib/basis.jar MyXlet.java

To run it, enter:

cvm com.sun.xlet.XletRunner -name MyXlet -path .

Conclusion

This tutorial introduced CDC and its associated profiles. The article described the architecture of CDC and the application models of the related profiles. It also provided detailed instructions on downloading, building, and installing CDC and its profiles, and furnished sample applications, along with instructions for compiling and running them.

The CDC technology is very interesting. I particularly like the Personal Basis profile's upward compatibility with various major standard specifications for home appliances.

Sun Microsystems has made available some optional packages for CDC such as those that provide support RMI and JDBC.

For more information

- CDC (JSR 36)
- Foundation Profile (JSR 46)
- Personal Profile (JSR 62)
- Personal Basis Profile (JSR 129)
- Download CDC/Foundation
- Download Personal Profile
- Download Personal Basis Profile

Acknowledgments

Special thanks to Mark Fulks and Dan Stevens of Sun Microsystems whose feedback helped me improve the article.




Reader Feedback
Excellent   Good   Fair   Poor  

If you have other comments or ideas for future technical tips, please type them here:

Comments:
If you would like a reply to your comment, please submit your email address:
Note: We may not respond to all submitted comments.

Have a question about Java programming? Use Java Online Support.



Back To Top