// 
//     Licensed to the Apache Software Foundation (ASF) under one
//     or more contributor license agreements.  See the NOTICE file
//     distributed with this work for additional information
//     regarding copyright ownership.  The ASF licenses this file
//     to you under the Apache License, Version 2.0 (the
//     "License"); you may not use this file except in compliance
//     with the License.  You may obtain a copy of the License at
// 
//       http://www.apache.org/licenses/LICENSE-2.0
// 
//     Unless required by applicable law or agreed to in writing,
//     software distributed under the License is distributed on an
//     "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
//     KIND, either express or implied.  See the License for the
//     specific language governing permissions and limitations
//     under the License.
//

= Creating, Debugging, and Profiling a Mobile Embedded Application
:jbake-type: tutorial
:jbake-tags: tutorials 
:jbake-status: published
:syntax: true
:icons: font
:source-highlighter: pygments
:toc: left
:toc-title:
:description: Creating, Debugging, and Profiling a Mobile Embedded Application - Apache NetBeans
:keywords: Apache NetBeans, Tutorials, Creating, Debugging, and Profiling a Mobile Embedded Application

Sungmoon Cho, Alyona Stashkova

Mobile embedded applications are employed in small embedded devices such as industrial metering devices, vending machines, security systems, modems, home electronics devices, and similar devices with either simple or no display and with some limited network connectivity. This example shows you how to develop a new Java ME embedded project in the NetBeans IDE using the Oracle Java Micro Edition Embedded platform that includes support for link:http://jcp.org/en/jsr/detail?id=228[+JSR 228+], the Information Module Profile-Next Generation API (IMP-NG). It will also explain how to debug and profile your own IMlet using NetBeans support for Oracle Java ME Embedded.

*To complete this tutorial, you need the following software and resources:*

|===
|Software or Resource |Version Required 

|link:https://netbeans.org/downloads/index.html[+NetBeans IDE with Java ME+] |Version 7.3 and more recent 

|link:http://www.oracle.com/technetwork/java/javase/downloads/index.html[+Java Development Kit+] (JDK) |Version 6, 7, or 8 

|link:http://www.oracle.com/technetwork/java/javame/javamobile/download/sdk/index.html[+Java ME SDK+] |Version 3.2 and more recent 
|===

*Important:* This tutorial runs on Win32 compatible platforms only.


== Installing Oracle Java ME Embedded

To set up the NetBeans IDE with the Oracle Java ME Embedded software for the Windows platform, you need to:

* install Oracle Java ME SDK
* activate the Java ME feature in the NetBeans IDE
* install the Oracle Java ME Embedded platform in the NetBeans IDE

*To install Oracle Java ME SDK:*

1. Go to the link:http://www.oracle.com/technetwork/java/javame/javamobile/download/sdk/index.html[+Java ME SDK download+] page.
2. Click the Accept License Agreement option.
3. Download an Oracle Java ME SDK installer file (for example, oracle-jmesdk-3-4-rr-win32-bin.exe) and save it to any location on your computer.
4. Double-click the installer file to run the installer, and follow the instructions.
When the installation is complete, the Java (TM) ME Platform SDK Device Manager icon ( image::images/icon.png[]) appears in the Windows system tray.

*To activate the Java ME feature:*

1. Choose Tools > Plugins from the main IDE's toolbar.
2. In the Plugins dialog box, click the Installed tab and select Java ME in the list of available features.

[.feature]
--
image::images/plugins-small.png[role="left", link="images/plugins.png"]
--


[start=3]
. Click Activate.

[start=4]
. At the Welcome panel of the Installer dialog box, click Activate.

[.feature]
--
image::images/installer-small.png[role="left", link="images/installer.png"]
--


[start=5]
. When the activation is successfully completed, click Finish.

[start=6]
. Click Close to close the Plugins dialog box.

*To install the Oracle Java ME Embedded platform:*

1. Choose Tools > Java Platforms.
The Java Platform Manager dialog box displays.

[.feature]
--
image::images/jpmanager-small.png[role="left", link="images/jpmanager.png"]
--


[start=2]
. Click Add Platform.

[start=3]
. In the Select Platform Type of the Add Java Platform wizard, select Java ME CLDC Platform Emulator and click Next.
The IDE displays the Choose directory to search for platforms dialog box.

[start=4]
. Select the directory you installed the Java ME SDK Platform to (for example,  ``C:\Java_ME_Platform_SDK_3.2`` ) and click Open.

[start=5]
. In the Platform Folders panel of the Add Java Platform wizard, ensure the platform you selected in the previous step is chosen and click Next.

[start=6]
. As soon as the IDE detects the platform, click Finish in the Detected Platforms panel of the the Add Java Platform wizard.

[.feature]
--
image::images/jpdetected-small.png[role="left", link="images/jpdetected.png"]
--

The Oracle Java ME Platform is now registered in the Netbeans IDE.

[.feature]
--
image::images/jpregistered-small.png[role="left", link="images/jpregistered.png"]
--


[start=7]
. In the Java Platform Manager dialog box, click Close.

Now your NetBeans IDE is set up for mobile development.


== Creating an Embedded Project

Creating a new project is your first step in developing a new Java ME Embedded application with the NetBeans IDE.

1. Choose File > New Project.
The New Project dialog box displays.

[start=2]
. Select the Java ME category and the Embedded Application project. Click Next.

[start=3]
. In the Name and Location panel of the New Embedded Application wizard, specify  ``EmbeddedApp``  as the project name.

[.feature]
--
image::images/newappname-small.png[role="left", link="images/newappname.png"]
--


[start=4]
. Leave the Create Default Package and IMlet Class option selected and click Next.

[start=5]
. Make sure CLDC Oracle Java(TM) Platform Micro Edition SDK is selected as the emulator platform and IMPNGPhone1 is selected as the device.

[start=6]
. Click Finish.
An IMP-NG application with an IMLet is created in a standard IDE project.

image::images/prjcreated.png[]

<<top,top>>


== Running the Application

To verify whether the application runs properly, modify the application source code as follows:

1. In the Projects window, double-click the  ``IMlet.java``  file and choose Edit.
The IDE opens the  ``IMlet.java``  file in the Source Editor.

[start=2]
. Scroll through the source code and find the  ``StartApp``  method.

[start=3]
. Insert the following line in bold in the  ``StartApp``  method's body:

[source,java]
----

 public void startApp() {
      *System.out.println("Hello, world!");*
 }
----

[start=4]
. Choose File > Save from the IDE's main menu to save the edits.

Now that you have created the application, you can run the application in the IDE as described below:

1. Right-click the  ``EmbeddedApp``  project node and choose Clean and Build.
The Output window displays the BUILD SUCCESSFUL statement.

NOTE: Choose Window > Output > Output from the the IDE's main menu if the Output window is not visible.


[start=2]
. From the IDE's menu bar, choose Run > Run Project.
The IMPNGPhone1 emulator starts and displays the EmbeddedApp application running.

[.feature]
--
image::images/emulator-small.png[role="left", link="images/emulator.png"]
--

NOTE: More information on the Java ME Embedded Emulator is available in the link:http://docs.oracle.com/javame/config/cldc/rel/3.2/get-started-win/title.htm[+Oracle Java ME Embedded Getting Started Guide for the Windows 32 Platform+].

In the Output window, you should see the output from the program, `Hello, world!`

[.feature]
--
image::images/output-small.png[role="left", link="images/output.png"]
--


[start=3]
. In the emulator, select  ``Embedded App (running)``  and click Suspend on the right.
The application is paused.

[start=4]
. Click Resume.
The application resumes running.

[start=5]
. To stop the application and close the emulator, click Stop and choose Application > Exit from the emulator's menu.
The run process is terminated in the IDE.

<<top,top>>


== Debugging the Application

Debugging embedded projects is accomplished similarly to debugging general Java projects.

Right-click on the project, and choose Debug to start a debugging session. The emulator opens and the program execution stops at any set breakpoints.

<<top,top>>


== Profiling the Application

Use common profiling tasks, such as standard CPU or memory profiling, to build a reliable mobile embedded application.

Before profiling your application, you need to install the Java ME SDK Tools plugin as follows:

1. In the NetBeans IDE, choose Tools > Plugins.
2. In the Plugins Manager, select the Available Plugins tab.
3. In the Available Plugins tab, scroll to find the Java ME SDK Tools plugin and select it for installation.

[.feature]
--
image::images/available-plugins-small.png[role="left", link="images/available-plugins.png"]
--


[start=4]
. Click Install.

[start=5]
. At the Welcome page of the Installer dialog box, click Next.

[start=6]
. At the License Agreement page, read the license agreements associated with the plugin. If you agree to the terms of all of the license agreements, click the appropriate option and then click Install.

[start=7]
. When the installation process is complete, leave the Restart IDE now option selected and click Finish.

After NetBeans IDE restarts, you can start using the IDE to profile your mobile embedded application.

1. In the Projects tab of the IDE, select the `EmbeddedApp` project name.
2. Choose Profile > Profile Project from the main menu to start a profiling session.

NOTE: You are prompted to integrate the profiler when a project is going to be profiled for the first time.

[.feature]
--
image::images/enable-small.png[role="left", link="images/enable.png"]
--


[start=3]
. (Applicable if this is first-time profiling of the project) In the Enable Profiling dialog box, click Yes to perform the integration.

[start=4]
. In the Profile dialog box, choose CPU Profiler, and optionally check Profile System Classes.

[start=5]
. Click Run.
The emulator opens with the `EmbeddedApp` application running.

[start=6]
. Interact with the application.

[start=7]
. Exit the application or close the emulator. 
The IDE displays the profile data in the `cpu:_time_` window.

[.feature]
--
image::images/cpu-small.png[role="left", link="images/cpu.png"]
--

NOTE: To save the data collected during the emulation session for future reference you can either:

* export the data to a `nps` file by clicking the Export to button (image::images/export.png[])
* save a snapshot to a `png` file by clicking the Save Current View to Image button (image::images/image.png[])
link:/about/contact_form.html?to=6&subject=Creating,%20Debugging,%20and%20Profiling%20an%20Embedded%20Application[+Send Feedback on This Tutorial+]


<<top,top>>


== See Also

* link:imp-ng-screencast.html[+Demo: Support for IMP-NG Profile in NetBeans IDE+]
* link:http://www.oracle.com/technetwork/java/javame/javamobile/training/jmesdk/index.html[+Java Mobile - Start Learning+]
* link:http://www.oracle.com/technetwork/java/embedded/resources/me-embeddocs/index.html[+Oracle Java ME Embedded Client Documentation+]
* link:https://blogs.oracle.com/javamesdk/[+Java ME SDK Team Blog+]
* link:http://www.oracle.com/pls/topic/lookup?ctx=nb8000&id=NBDAG1552[+Developing Java ME Applications+] in _Developing Applications with NetBeans IDE_

<<top,top>>

