February 28, 2021
Hot Topics:

Understanding The Connected Device Configuration (CDC)

  • By Eric Giguère
  • Send Email »
  • More Articles »

The Generic Connection Framework

Since the CDC is a superset of the CLDC, it includes the Generic Connection Framework (GCF). Unlike the CLDC, however, the CDC also requires GCF support for two specific connection types: files and datagrams. This makes sense because the CDC includes the file classes from the java.io package and the datagram classes from the java.net package. It is therefore straightforward for the device manufacturer to write GCF implementation classes that simply map GCF requests (using the file or datagram protocol at the start of a URL) into their java.io and java.net equivalents.

File and Datagram Support

Here is an example of opening a file for writing using the GCF:

import java.io.*;
import javax.microedition.io.*;

try {
    String url = "file:/logs/mylog.txt";
    OutputConnection conn = 
         (OutputConnection) Connector.open( url,
                                            Connector.WRITE );
    OutputStream out = conn.openOutputStream();
    ..... // write to the output stream
catch( IOException e ){
    // handle error

Datagram support is a bit more complex, but quite similar.

Why not just use the java.io and java.net classes directly? The GCF provides a consistent I/O model that works across all J2ME platforms that support the required protocols. If you don't need interoperability with J2SE, use the GCF whenever possible to open your I/O connections.

Using the CDC

Like the CLDC, the CDC is by itself a limited programming platform. Again, because it does not define any user interface classes or implement any I/O models, about all you can do for output is write to the System.out stream, which may or may not be captured to a console or file. The extra classes defined by one or more J2ME profiles are really required to write interactive applications.

Sun has a reference implementation of the CDC hosted on Linux available for download from its website. See Sun's main CDC page for links to it and to the CDC specification.

Next: The Mobile Information Device Profile

Eric Giguère is the author of Java 2 Micro Edition, the first book about J2ME, and co-author of Mobile Information Device Profile for Java 2 Micro Edition, both published by John Wiley & Sons. He works as a software developer for iAnywhere Solutions, a subsidiary of Sybase. For more information about Eric, see his web site or drop him a note at ericgiguere@ericgiguere.com.

# # #

Page 2 of 2

This article was originally published on August 9, 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