Documentation



Oracle Java SE Embedded: Developer's Guide

3 Quick Start for Application Developers

Learn how to test your applications so they will run with the compact profile that matches the JRE installed on the embedded device.

This page contains the following topics:

Typical Tasks for Embedded Application Developers

Here are the basic tasks that embedded application developers use to develop an application for an embedded device.

Note:

If you have a device or your own that you need to set up with Java SE Embedded, see Quick Start for Platform Developers.

Quick Start Examples

The tasks in the following sections will walk you through a simple example of how to develop applications for an embedded device. These instructions assume the following conditions:

  • You will work on a host computer for application development. You can work with a supported, standard JDK installation, using your regular development tools. Download the standard JDK from. http://www.oracle.com/technetwork/java/javase/downloads/index.html

  • You have a basic knowledge of the Java programming language and Java SE technology.

  • You know which compact profile is installed, or will be installed, on the embedded device as part of the JRE.

For basic information about compact profiles, see About Compact Profiles.

This quick start scenario is very simple. For more information and more options, see the More Information links at the end of each section.

Tip:

NetBeans IDE provides support for profiling, running, and debugging applications on both the host computer and target device. See Developing Embedded Applications in NetBeans IDE.

Task 1   Develop Your application

Develop your application using your regular Java development tools and the standard JDK. The difference from standard development is that you will frequently test your application to ensure the libraries in your application meet the requirements of the compact profile installed on the device.

To illustrate the process, let's take two simple headless application examples: Hello World and Hello RMI.

In the Hello World example, shown in Example 3-1, the application merely prints "Hello World" to the console.

Example 3-1 Hello World Application

public class HelloWorld {
  public static void main (String args[]) {
    System.out.println("Hello world!");
  }
}

In the Hello RMI example, shown in Example 3-2, the application uses an RMI LocateRegistry class to access a remote object and print a stack trace if there is an error.

Example 3-2 Hello RMI Application

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
 
public class HelloRMI {
  public static void main (String args[]) {
    if (System.getSecurityManager() == null) {
      System.setSecurityManager(new SecurityManager());
    }
    try {
      Registry registry = LocateRegistry.getRegistry("testRMI");
      System.out.println("Hello RMI!");
      } catch (Exception e) {
        System.err.println("RMI exception:");
          e.printStackTrace();
      }
  }
}

More Information:

Note:

In most cases, embedded devices run headless applications (no user interface). If you are working with headful applications, see Develop Headful Applications.

Task 2   Test your application frequently

As you develop your application, test it frequently to make sure the libraries use fit the compact profile that is planned for the device. See Your Choices When Creating a Custom JRE.

To test, first compile the application, then run the jdeps command. For more complex applications, you can additionally test the application on the target device.

In order to use the jdeps tool, you must compile your application. As shown in Example 3-3, use javac without the -profile option, because the purpose is to determine the profile.

Example 3-3 Compile Commands for Hello World and Hello RMI

% javac HelloWorld.java
% javac HelloRMI.java

Now you can use the jdeps tool to determine the minimum compact profile required to run each application. Example 3-4 show the command and results for the Hello World application.

Example 3-4 jdeps Command and Results for the Hello World Application

% jdeps -P HelloWorld.class
 
HelloWorld.class -> /net/test11.us.example.com/export/java-re/jdk/8/ea/b124/binaries/linux-i586/jre/lib/rt.jar
   <unnamed> (HelloWorld.class)
      -> java.io                                            compact1
      -> java.lang                                          compact1

The results in Example 3-4 show that the compact1 profile is the minimum profile required to run the HelloWorld application.

Example 3-5 shows the jdeps command results for the Hello RMI application.

Example 3-5 jdeps Command and Results for the Hello RMI Application

% jdeps -P HelloRMI.class
HelloRMI.class -> /net/test11.us.example.com/export/java-re/jdk/8/ea/b124/binaries/linux-i586/jre/lib/rt.jar
   <unnamed> (HelloRMI.class)
      -> java.io                                            compact1
      -> java.lang                                          compact1
      -> java.rmi.registry                                  compact2

The result in Example 3-5 show that a java.rmi.registry class in the Hello RMI application requires the compact2 profile, so compact2 would be the minimum profile that would need to be installed.

More Information:

Task 3    Package and deploy your application

Compile the final application using the -profile option, as in the example in Specifying the Profile in the javac CommandExample 3-6.

Example 3-6 Specifying the Profile in the javac Command

$ javac -profile compact1 HelloWorld.java

Package the application by creating a JAR file in the normal fashion.

To deploy the application, simply copy the JAR file and any resource files to the embedded device.How you copy to the device depends on how whether you use the network or an SD card.

Tip:

For larger applications, it is a best practice to test the application on the embedded device in iterative steps to see how the application performs. In this way you can make performance improvement changes to the application in the early stages of the development of teach component.

More Information:

Close Window

Table of Contents

Oracle Java SE Embedded: Developer's Guide

Expand | Collapse