Create, test, and deploy applications on Java platforms for mobile and embedded devices Mobility Tech Tips

Wednesday Feb 06, 2008

By Eric Giguere

The Java ME platform comprises configurations, profiles, and optional packages. Like configures and profiles, an optional package is a set of APIs. Unlike a profile, however, it does not define a complete application environment. An optional package is always used with a configuration or a profile. It extends the runtime environment to support device capabilities that are not universal enough to be defined as part of a profile or that need to be shared by different profiles.

Consider the Wireless Messaging API (WMA), a set of classes for sending and receiving Short Message Service (SMS) messages. Because the WMA is an optional package, it can be included on any Java ME device with SMS capabilities, not just MIDP-enabled cellphones. If WMA were part of a specific profile, such as MIDP, its use would have been limited to that profile and its supersets.

Just like profiles and configurations, optional packages are specified through the Java Community Process. So each has its own reference implementation (RI) and test compatibility toolkit (TCK).

Note that it is the vendor of a Java runtime environment – in many cases, the device manufacturer – that controls which optional packages are available, just as it controls which configuration is used and which profiles are available. In general, it isn't possible to use an optional package if it isn't preloaded onto a device as part of the runtime environment. It takes some time after an optional package's specification has been finalized before implementations of the package appear in commercially available devices.

Using Optional Packages

For the application developer, an optional package is just another set of Java classes to place in the Java compiler's classpath. The classes are not packaged with the applications, of course, because the devices that support the optional package include them in their runtime environments.

To detect the presence or absence of an optional package, test for the existence of a class unique to the optional package:

    ...
    public static boolean isWMAPresent(){
        try {
            Class.forName(
                   "javax.wireless.messaging.MessageConnection" );
            return true;
        }
        catch( Exception e ){
            return false;
        }
    }
    ...

Choose the class to test with care. For example, the existence of the java.rmi.Remote interface does not imply that the RMI Optional Package (JSR 66) is supported, because the Personal Basis Profile includes the same interface as part of its support for inter-Xlet communication.

If an optional package is required for your application to function, make sure the application checks for its existence, and exits gracefully if it isn't found. Letting the application terminate with a cryptic Class not found error will confuse users.

Example Optional Packages

Optional packages are defined through the Java Community Process. For the complete list of optional packages, refer to the JCP web site for Java ME-related JSRs.

About the Author

Eric Giguere is a software developer and has written extensively on computing topics. He holds BMath and MMath degrees in Computer Science.
Comments:

hey how can i get java for my computer? it won't let me get it. it is saying:
this installation package could not be opened verify the package exists and that you can access it, or contact the application vendor to verify that this is a valid windows installer package.

Posted by linda marcum on March 12, 2008 at 05:50 AM PDT #

You can download Java from several places; here are 3 options:

- The Java consumer download page: <http://java.com/en/>
- The developers download page: <http://developers.sun.com/downloads/>
- The Java SE download page: <http://java.sun.com/javase/downloads/index.jsp>

Posted by christine dorffi on March 12, 2008 at 03:08 PM PDT #

i still download java onto my computer. so how can i get that. i need it to do alot of things on here. i can't even play games on here

Posted by linda marcum on March 13, 2008 at 08:46 PM PDT #

Please see the Download Help FAQ at <http://java.com/en/download/help/>

Posted by christine dorffi on March 13, 2008 at 08:59 PM PDT #

I also have the same question. I want this site to answer. I am really frustrated and Java 2 Standard Platform Edition is my last hope of downloading Java. Please tell me how i can verify that the package exists.

Posted by Rishi Singh on May 13, 2008 at 01:35 PM PDT #

To get Java on your computer, go to this page and choose the specific Java technology you want to download: <http://developers.sun.com/downloads/>. If you want to download the Java Platform, Standard Edition (Java SE), select that option or go to <http://java.sun.com/javase/downloads/index.jsp>.

This tech tip shows you how to verify that the specific package you are interested in exists. It uses the Wireless Messaging API as an example. To download the Wireless Messaging API, go to <http://java.sun.com/products/wma/>. Go to <http://java.sun.com/javame/technology/msa/jsr205.jsp> to read more information on the WMA.

Posted by Christine Dorffi on May 13, 2008 at 03:07 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed