Now that we have discussed the introductory aspects of J2ME we should come to the most important question that is coming in your mind – ‘How should I write programs in J2ME?’ In this unit we will discuss the answers to this question. Before coming to the specific aspects of programming, we will discuss the alternatives available to us in terms of the development environments which we can use to aid us in programming using J2ME.
The available alternatives
As a Java programmer many of you must be familiar with the command line tools available for programming Java applications. These tools are also available for the Java 2 Platform, Micro Edition (J2ME). But we are not going to discuss such ugly looking and low productivity tools. We will discuss some of the tools which have been provided to us free of cost by Sun Microsystems and the mobile phone manufacturers for developing applications. These tools have been built keeping in mind the needs of the programmers. Thus we are able to steer into J2ME at a fast pace from day one. Some of the alternatives available to us in terms of development kits are:
a. Sun ONE Studio 4 update 1, Mobile Edition
Sun ONE Studio 4 update 1, Mobile Edition is an integrated development environment (IDE) which has been provided to us by the Sun Microsystems Inc. This software allows us to develop, edit, customize, compile, build, run and test the code. This is the best alternative that is available to us if we want to develop applications in J2ME without spending any money on buying a software development kit. We will discuss the workings of Sun ONE Studio 4 update 1, Mobile Edition in detail within this chapter.
Screen Shot: Sun ONE Studio 4 update 1, Mobile Edition
b. J2ME Wireless Toolkit
J2ME Wireless Toolkit is also a free alternative which has been made available to us by the Sun Microsystems Inc. This is a toolkit which provides us the facilities for developing and running J2ME applications. This toolkit has many versions which include 1.0.4_01, 2.0_01, 2.1 and 2.2. This toolkit also provides us with some of the basic emulators which are very helpful in testing the applications on the PC itself. J2ME Wireless Toolkit is an absolute must for any J2ME programmer. In fact even Sun ONE Studio 4 update 1, Mobile Edition includes J2ME Wireless Toolkit and uses its emulators for executing the applications. We will also look at J2ME Wireless Toolkit 2.2 in this book in detail.
Screen Shot: J2ME Wireless Toolkit
c. Nokia Developer’s Suite for J2ME
Nokia has also provided us with a good development tool for building J2ME applications. Although applications developed through Nokia Developer’s Studio can run on non – Nokia phones, this development toolkit is better suited for the development of software for Nokia phones. Also this development toolkit has an option of integrating with the Sun ONE Studio 4 update 1, Mobile Edition. Thus you can enjoy the benefits of this development kit from Sun ONE Studio 4 update 1, Mobile Edition itself. Some of the newer versions of the Nokia Developer’s Suite contain the facilities for deploying the applications, signing the JAR files and even converting the audio files to formats suitable for mobile phones.
Screen Shot: Nokia Developer’s Suite for J2ME
d. Sony Ericsson J2ME SDK (Beta)
SonyEricsson’s J2ME Software Development Toolkit is modeled on the lines of the J2ME Wireless Toolkit. In fact some of the parts of this toolkit are common with the J2ME Wireless Toolkit. KToolbar contained in this toolkit is a good example of this. This toolkit provides us the facilities for executing and testing applications on the SonyEricsson phone emulators. Emulators for T610 and P800 are particularly supported.
Screen Shot: Sony Ericsson J2ME SDK
e. Motorola iDEN SDK
Motorola iDEN Software Development Kit provides us with the emulators and tools for testing for Motorola iDEN phones. It is one of the better toolkits among the toolkits of handset manufacturers. The versions of this toolkit have been updated quite speedily in the past. I will suggest you to download the latest version from Motorola’s developer website.
f. Siemens Mobility Toolkit
Like the toolkits of all the other mobile manufacturers the Siemens Mobility Toolkit has been specifically build to facilitate the testing of mobile applications for Siemens phones. We are provided with the support for testing applications on Siemens phone emulators. This toolkit also supports the integration with the various versions of Borland JBuilder.
Screen Shot: Siemens Mobility Toolkit Manager
Any experienced programmer will vouch for the sharp increase in productivity that occurs when he/she uses a good integrated development environment (IDE) for writing, compiling and debugging programs. Therefore in the section below I have discussed the workings of Sun ONE Studio, Mobile Edition. I will personally recommend you to use Sun ONE Studio 4 update 1, Mobile Edition if you want a good development kit for free. Otherwise J2ME Wireless Toolkit 2.2 is also a good alternative. Also J2ME Wireless Toolkit 2.2 supports most of the new APIs discussed in this book. Thus J2ME Wireless Toolkit 2.2 should also be used if you want to fully utilize this book.
The Workings of Sun ONE Studio 4 update 1, Mobile Edition
Sun ONE Studio 4 update 1, Mobile Edition is a good integrated development environment available to us for developing industrial scale J2ME applications. In fact at SKJ Technologies this is the predominant development tool in use along with J2ME Wireless Toolkit 2.1 and J2ME Wireless Toolkit 2.2. Also if you have used Visual Studio for developing desktop applications then you will find it the most convenient to use development tool out of all the tools discussed so far. We will now discuss the inner workings of the Sun ONE Studio 4 update 1, Mobile Edition in detail. Please remember during all the discussions below that we have discussed the development of applications using Sun ONE Studio within the MS Windows desktop environment.
Procedure for creating a project:
Screen Shot: Project Manager
Screen Shot: Create New Project Dilaog
Screen Shot: Project Configuration Wizard
You have created a new project in Sun ONE Studio 4 update 1, Mobile Edition. This new project remembers all the compiler properties for you. Every time you open the project the properties set by you for compiling and building the applications automatically get set in the IDE. You can also add folders and files for editing in a project. Below I have discussed the procedure for mounting a directory for storing code of the project.
Procedure for mounting a directory:
Sun has introduced a concept called the MIDletSuite. This MIDletSuite is the container which can contain multiple MIDlets. The MIDletSuite also has some properties which are used by the Sun 1 Studio for automatically generating the JAD manifest and the JAR file. Now we will discuss the procedure for creating a MIDletSuite.
Procedure for creating a MIDletSuite:
This template creates a MIDlet which displays text on the screen of the mobile device. I would recoomed you to choose this option for your first MIDlet.
This template constructs a simple MIDlet.
In the image above you are viewing the Explorer [Filesystems] which contains the icon for a MIDletSuite named ‘CrimeSuite’.
Procedure for creating a new MIDlet:
Procedure for creating a sub class of MIDPCanvas:
Procedure for creating a Class:
Procedure for editing the contents of a MIDletSuite:
The contents of your MIDletSuite and its corresponding JAR file have been changed.
Procedure for viewing the Manifest/JAD file:
Procedure for viewing and editing the properties of the MIDletsuite:
Alternate procedure for viewing and editing the properties of the MIDletsuite:
MIDletsuite property tabs:
This tab contains the ‘Compression Level’ and ‘File Filter’ options. I would recommend you to give 9 as the ‘Compression Level’.
Screen Shot: ‘Properties’ Tab
This tab helps you choose the emulator which can be used for running the application.
Screen Shot: ‘Execution’ Tab
This tab has the following fields:
o Jar Size
This is calculated and populated automatically by the Sun 1 Studio.
o Jar URL
Enter the location of the Jar file on the server from which the application is to be downloaded. If you want the application to be downloaded from just the PC through Infra Red or Bluetooth port then only the name of the JAR file.
o MicroEdition Configuration
CLDC-1.0 will automatically be filled by the Sun 1 Studio although you can change it.
o MicroEdition Profile
MIDP-1.0 will automatically be filled by the Sun 1 Studio although you can change it.
The name of the MIDletSuite is set as the value for this field automatically although you can change it.
The name of your organization can be entered here. Sun 1 Studio will fill this field with name of the user account you are working with under Windows.
The version number can be entered here. By default the version number is 1.0.
Screen Shot: ‘Required’ Tab
The ‘Optional Tab’ has the following fields under it:
You can enter a short description of you application here. This can be accessed by the mobile application portals for explaining you application.
The path and name of the image file of icon of your application can be entered here.
The URL of the page which contains more information about the application can be entered here. This helps the user to learn more about your application.
User defined variables can be entered here.
Screen Shot: ‘Optional’ Tab
This field contains only one field which is ‘Encoding’.
Procedure for adding classes in a project:
Screen Shot: Adding a class to the project
Procedure for executing an application
Although clicking on the ‘Play’ button will execute the application; out of experience I will recommend you the following practice.
Screen Shot: Build menu
Procedure for opening an existing project:
Screen Shot: Project menu
Procedure for deleting an existing project:
Screen Shot: Project Manager
The Workings of J2ME Wireless Toolkit 2.2
The Sun Microsystems Inc. has launched its newest version of J2ME Wireless Toolkit as a set of tools for creating Java applications that run on devices compliant with the Java Technology for the Wireless Industry (JTWI, JSR 185) specification. The J2ME Wireless Toolkit 2.2 contains the software development tools, utilities, and 4 device emulators.
The J2ME Wireless Toolkit 2.2 contains the following features among others such as:
ü 4 Inbuilt Emulators
ü Obfuscation support ( Discussed later)
ü MIDlet signing
ü Certificate management
ü Integrated over-the-air (OTA) emulation
ü Screens for customizing the MIDletSuite settings in great detail
ü Push registry emulation
The J2ME Wireless Toolkit 2.2 helps us develop the J2ME applications using the following APIs:
System Requirements for installing J2ME Wireless Toolkit 2.2
Minimum hardware requirements for installing J2ME WTK 2.2 are:
Procedure for Installation
To install the J2ME Wireless Toolkit 2.2 on Windows PC run the installer file, j2me_wireless_toolkit-2_2-windows.exe. Then follow the instructions provided by the installer.
To install the J2ME Wireless Toolkit 2.2 on Linux, run the self-extracting installer j2me_wireless_toolkit-2_2-bin-linuxi386.bin.
Downloading J2ME Wireless Toolkit 2.2
For downloading J2ME Wireless Toolkit 2.2 please visit the following web page:
To download the SDK or JRE you can visit http://java.sun.com/j2se/downloads.html.
Procedure for creating a new project:
ü Click on the ‘New Project…’ button in the KToolbar or choose ‘New Project…’ menu item from the File menu in the KToolbar for opening the ‘New Project’ dialog.
ü Give the name of your project.
ü Give the name of your MIDlet’s class.
ü A new project will be created. A folder dedicated to the code, resources, library files and application for the project will be created in the ‘apps’ folder of the directory in which the J2ME WTK 2.2 has been installed. You can write your code in any text editor program like NOTEPAD, WORDPAD, EDITPLUS etc. and save that in the ‘src’ folder within the project’s folder.
Procedure for opening an existing project:
ü Click on the ‘Open Project…’ button in the KToolbar or choose ‘Open Project…’ menu item from the File menu in the KToolbar for opening the ‘Open Project’ dialog.
ü Select the name of your project.
ü The selected project will be loaded in the KToolbar.
Procedure for building a project:
ü Click on the ‘Build’ button in the KToolbar or choose ‘Build’ menu item from the Project menu in the KToolbar for building your project.
Procedure for executing a project:
ü Click on the ‘Run’ button in the KToolbar or choose ‘Run’ menu item from the Project menu in the KToolbar for building your project.
Given below is a screen shot of a project executing within an emulator.
Procedure for packaging the JAR file of the project:
ü Choose the Project ->Package -> Create Package menu item in the KToolbar for packaging a Java Archive File (JAR file) of your project.
Procedure for packaging an obfuscated JAR file of the project:
ü Choose the Project ->Package -> Create Obfuscated Package menu item in the KToolbar for packaging an obfuscated Java Archive File (JAR file) of your project.
Procedure for changing the settings in a project:
J2ME WTK 2.2 gives us an option to tinker with the following types of settings:
ü API Selection
ü Required Fields
ü Optional Fields
ü User Defined Fields
ü MIDlet management information
ü Push Registry
Just click on the ‘Settings…’ button in KToolbar or ‘Settings…’ menu item in the Project menu in the KToolbar for opening the ‘Settings’ dialog. Choose your desired settings and press OK button.
Procedure for choosing between the emulators in KToolbar:
ü Click on the device combo box in the KToolbar and select the needed emulator.
Procedure for adding new emulators:
ü Open the directory in which the J2ME WTK 2.2 is installed.
ü Open the ‘wtklib’ directory within that directory.
ü Open the ‘devices’ directory within the ‘wtklib’ directory.
ü Copy the folder containing the data for the emulator in this directory.Now open the KToolbar. You will see your emulator added in the ‘Device’ combo box within the KToolbar. In case your emulator does not appear than you must have not copied the correct files for that emulator from the internet.
Mobile Technology > Java ME (J2ME) > Book - Mobile Phone Programming using Java ME (J2ME) > UNIT II >