In this recipe we will use Mobile Information Device Profile (MIDP) as the profile for our Mobile application.
MIDP is the best-known JME profile and provides core functionality that will run across many devices, giving apps more portability.
In later recipes we will also favor MIDP since the market for those applications has exploded in recent years and it is more enticing for developers to work in.
Keep in mind that MIDP applications should be written with memory consumption and processing power constraints/limitations in mind.
If NetBeans is not currently installed visit the download sections on:
It is possible to find the full version of NetBeans that contains Java ME; upon installation remember to select the Java ME option.
With NetBeans ready, we can start coding.
MyMIDPApp
, leave the other options with their default values and click Next.The folder structure created by NetBeans for a Java ME project is rather extensive. The project is created with an Ant build file, which already includes several targets. On top of that .properties
files are created for the convenience of the developer.
To have access to all of the files shown in the screenshot below it is necessary to build the project. To do this right-click on the project and select Build.
After the build step, navigate to the Files window and expand the nodes to see the properties files. They each have different roles:
Also present is a MANIFEST file. This file is accessed by the device to show the version number and name of the application when installed in the mobile.
NetBeans then creates the HelloMidlet.java
, which is our main class for developing with Java ME. For now, this is where the entire code of our project placed.
It is possible to edit the code in different ways:
To run our first Mobile Application, simply right-click on our projects node and select run.
There is more than one way to run your project with different devices.
On project creation, we can pick the device we are designing our app for and will be deploying on.
Click on the Default Platform Selection dropdown and the list will be presented.
If a project already exists we can change the target device:
The function of the optional packages selected in the above screenshot is to enable features in the JME application that would otherwise be not supported. For example, the ContentHandler API lets applications execute other registered applications by URL. To learn more about this specific API visit:
http://download.oracle.com/javame/config/cldc/opt-pkgs/api/ch/jsr211/index.html
For the other available APIs please refer to:
http://download.oracle.com/javame/
Alternatively, when testing, it is possible to select the device prior to running the application. Right-click on the project node and select Run With... and you will be presented with the Quick Project Run dialog:
Java comes pre-loaded in many different devices. One of the biggest deployments of Java in the mobile phone world is in Symbian phones. Symbian contains many different types, Symbian^3, S40, and so on.
We will add the SDK to work with S40 devices.
First visit:
http://www.forum.nokia.com/Library/Tools_and_Downloads/
Create an account and download the S40 fifth edition Java SDK.
Upon installation completion, go to NetBeans:
3.144.242.235