Java ME CDC to Java SE Embedded 8 Migration Guide

Introduction

Java ME CDC technology is Oracle's legacy technology that addresses embedded devices that had more than 1MB RAM and 10MB ROM. Java SE Embedded 8 is a new generation Java Embedded Platform that addresses devices that have about the same amount of resources, but also allows them to access the latest APIs and functionality. This article helps the legacy Java ME CDC developer migrate their CDC apps to Java SE Embedded 8.

There are many types of implementations of Java SE Embedded 8 including ports to Linux/ARM and Linux/PowerPC, the same types of platforms as where many developers use Java ME CDC. Along with the same types of ports, Java SE Embedded 8 gives the added advantage of full set of Java SE 8 language and APIs.

Also, there is the new feature of JDK 8 Compact Profiles. Compact Profiles allow for size ranges of the Java SE Runtime to be 11MB to 50MB depending on a CDC application API requirements. There are also additional size reductions such as memory optimizations, a reduced Java virtual machine, and class size reduction in Java SE Embedded 8, to address the same size concerns that CDC developers had in the past.

Compact Profiles

Compact Profiles are new subsets of APIs for Java SE Embedded 8. The primary motivation for this new feature is to allow applications that do not require the entire Java SE Platform to run on resource-constrained devices, just like the CDC platform allowed for Java ME CDC development. An application that does not use the Swing/AWT/2D graphics stack, e.g., or which uses Java FX instead, can achieve considerable space savings by running on top of a Compact Profile that does not include those APIs, just like headless CDC applications ran on the headless Java ME CDC/Foundation Profile stack.

More broadly, the feature of Compact Profiles is intended to enable the migration of applications currently built on top of the Java ME Connected Device Configuration (CDC) to appropriate Compact Profiles of the Java SE Platform, part of the long-term effort to converge CDC with Java SE.

Compact Profile 1: The Equivalent of Java ME CDC/Foundation Profile

The typical size of the first Compact Profile, called the compact1 runtime is about 11MB which is similar to the CDC platform. So, for about the same static footprint size in compact1, you have a very capable runtime environment that is equivalent to Java ME CDC. The specific packages found in compact1 should look familiar to the typical Java ME CDC programmer, who might be happy to see the addition of Annotation, Concurrent, Pref, Script, Time, and NIO which are new compared to CDC and Foundation Profile specs.

Fig. 1 compact1 package names

There are other new Java SE Embedded 8 Features above and beyond the CDC spec that are worth mentioning that have advanced in the Java SE stack since the days of Java ME CDC. These include new features of the Hotspot VM which is the Java virtual machine that is now optimized and tuned for embedded devices while delivering the functionality of Java SE technology:

Client VM: Parallelized for multicore CPUs and concurrency support

Generation GC: Special garbage collection that is fast and small

Tiered Compilation: Special way to have just-in-time compilation to save space and compile faster

Also, there are these new security features that are above what CDC provided in the past:

Building a Compact Profile 1 Environment

In order to build a compact1 platform, you would start with the Java SE Embedded 8 JDK and use the new jrecreate tool to create a new compact profile. This is down using the jrecreate.sh script in this manner:

After creating your compact1 profile environment, you will have a Java SE Embedded runtime that can be used on your device with a small footprint but will all the APIs found in the Compact Profile 1 defined Java SE 8 subset. If you'd like to customize the type of Java VM that is in your compact1 profile environment, you can use the -vm flag to change it from "minimal" (which is the smallest VM setting) to either "client" or "server".

For example this following jrecreate tool command will create a Full JRE Profile with "server" Java virtual machine.

% sh jrecreate.sh -d /home/myjre/full-jre --vm server

Compiling Existing CDC Application for Compact Profile 1

Once you have your compact1 profile (which is the equivalent to CDC), you are now ready to compile an existing CDC application source file to run with your compact1 profile runtime. To do so, you would use the new javac -profile <compact#> flag option.

So, for example, if you had a HelloWorld.java application written for CDC, you would use the new Java SE Embedded 8 javac to compile using the new "-profile compact1" flag to compile your CDC app to the compact1 runtime of Java SE Embedded 8:

$ javac -profile compact1 HelloWorld.java

If you had a application source file that tried to use an API outside the scope of the legacy CDC/Foundation Profile spec, or outside the new Compact Profile 1 spec (such as using the ThreadMXBean class which is not in any of the Compact Profiles), you would see this error when trying to compile using the "-profile compact1" flag:

So, you can see that ther would be an API "not available in profile 'compact1'" error message such as above, if you did not remain to the subsetted spec of the -profile file, in order to run in a smaller environment.

Executing CDC Application

To execute your application, instead of invoking with the "cvm" command line Java VM call, you would use the Java SE "java" call with the same arguments:# Java ME CDC

% cvm -cp . HelloWorld

# Or

% cvm -jar HelloWorld.jar

Would become:

# Java SE 8 Embedded Using Compact Profiles

% java -cp . HelloWorld

# Or

% java -jar HelloWorld.jar

It's a simple matter of just replacing "java" for "cvm", so it is a very straight-forward migration step.

Summary

In summary, you can see that it is easy to migrate your Java ME CDC applications to Java SE Embedded 8 to take advantage of the new smaller Compact Profiles of Java SE 8 and to be able to customize using the new jrecreate tool. Also, there are more and better APIs to choose from in Java SE Embedded 8 with the latest advancement in the Java SE platform.

For more information, see the Java SE Embedded 8 Web page at: http://www.oracle.com/technetwork/java/embedded/overview/javase