System News
June 17, 2002
Article #6890
Volume 52, Issue 3
Java Technology
Introduction to Sun[TM] ONE Studio, Mobile Edition Software
Installation, Features and MIDlet Example

Full Source:

      Introduction to Sun ONE Studio Mobile Edition
(formerly Forte for Java Developer Resources)
Installation, features and MIDlet Example

Sun ONE Studio 4 Mobile Edition - in conjunction with the Java 2
Platform, Micro Edition (J2ME) - provides a complete Mobile Information
Device Profile (MIDP) development environment, including full Java
Platform Debugger Architecture (JPDA) debugging with mobile device
emulators which implement the Universal Emulator Interface (UEI). This
article introduces the Mobile Edition features, and provides a
step-by-step guide to creating and debugging a simple MIDlet suite.

by Vaughn Spurlin

- Introduction
- Installing Mobile Edition
- Quick Tour of Mobile Edition's Features
- Creating and Testing a MIDlet
- Importing an Existing MIDlet
- Debugging a MIDlet


The Sun ONE Studio 4, Mobile Edition packages the essential modules for
creating wireless applications, plus modules used specifically for J2ME
development - creating a smaller footprint with a more targeted
utility. The IDE's highly modular architecture makes it easy to add and
delete features, and to plug in third party tools. Further modules can
easily be added to Mobile Edition - without charge - by downloading
them from the Sun ONE Studio Update Center (or the NetBeans Update
Center). Mobile Edition provides the basic tools for generic Java
development, plus two modules specific to J2ME:

- J2ME Wireless module - supports MIDP development with templates, a
wizard, emulation integration, and Connected Limited Device
Configuration (CLDC) compilation

- J2ME Wireless Toolkit - the WTK wrapped as a NetBeans technology
module for integration with Sun ONE Studio

Installing Mobile Edition

JDK and system requirements for Mobile Edition are outlined below.
Download and installation instructions follow.

JDK Requirements

Installation of the Java 2 SDK is a prerequisite for installing Mobile
Edition, as the IDE itself runs on a Java 2 JVM. The latest Java 2
Platform, Standard Edition (J2SE), version 1.4.0 is strongly
recommended, but version 1.3.1 also works well. Earlier releases of the
J2SE cannot be used to run the IDE, but can be configured as additional
compilers if needed to support older Java source.

The J2SE can be downloaded from the following URL:

System Requirements

The Mobile Edition Release Notes provide full details of system
requirements. Mobile Edition requires at least a 350 MHz Pentium II or
333 MHz Sparc Ultra 10, with 128 Mbytes RAM and 100 Mbytes available
disk space

While only the officially supported platforms (that is, Solaris 8,
Windows NT/2K, and RedHat Linux 6.2 and 7.1) have undergone extensive
Quality Assurance testing, the IDE runs well on most Unix-style
operating systems - including Mac OS/X. Mobile Edition and Community
Edition also run well on Windows 98/ME.


Sun ONE Studio 4, Mobile Edition can be downloaded from the following

Alternatively, you may download and install Sun ONE Studio 4, Community
Edition, then install the Mobile Edition modules from the Sun ONE
Studio Update Center.

Installation Instructions

Install Sun ONE Studio Mobile Edition according to the instructions
provided in the Getting Started Guide. Mobile Edition is be ready for
use upon completion of the installation process. However, if you prefer
to install Mobile Edition modules into Community or Enterprise Edition,
follow the instructions below. (These instructions are also applicable
in the case adding Community Edition features to a Mobile Edition

1.Start the IDE, and from the IDE main menu, choose Tools > Update
Center to launch the Update Center wizard.

2.Ensure that the radio button, "Check the Web for Available Updates
and New Modules" and the location, "Forte for Java Update Center", are
selected, then click Next.  (The Forte for Java Update Center will soon
be renamed Sun ONE Studio Update Center).

3.Enter your Developer Resources login and password in the appropriate
fields, then click Next.

4.In the "Available Updates and New Modules" panel select all Mobile
Edition Modules, together with any additional modules you wish to
install. Click the top button to move these modules into the "Include
in Install" panel, then click Next (see Figure 1).

5.Once you accept the License Agreement, the module installation will
proceed automatically.

Figure 1: Selecting modules to install using the
Update Center Wizard.[illustration here]

Installing the J2ME Wireless Toolkit - Standalone Version

The J2ME Wireless Toolkit module included with Sun ONE Studio 4 Mobile
Edition bundles the J2ME Wireless Toolkit (J2MEWTK) 1.0.3. All Sun ONE
Studio 4 editions also can be configured to use a standalone
installation of the J2ME Wireless Toolkit instead of - or in addition
to - the module.

The latest release of the J2MEWTK can be downloaded from the following

NOTE: The installation process will ask which setup you prefer:
Integrated or Standalone? Choose the Standalone option - the Integrated
option would attempt to install the J2MEWTK module into an existing Sun
ONE Studio installation.

NOTE: The module included with the J2MEWTK 1.0.3 download is compatible
with Sun ONE Studio 3.0, but not with Sun ONE Studio 4. This issue will
be addressed with future releases of the J2MEWTK.

Emulator Installation

After the Sun ONE Studio installation is complete, you should verify
that the emulators in J2MEWTK are installed correctly. You may also use
this procedure to install additional emulators, or if you installed
J2MEWTK as a standalone product.

1.Start the IDE, and at the bottom of the Explorer window, click the
Runtime tab.

2.Open nodes for Device Emulator Registry > Installed Emulators > J2ME
Wireless Toolkit 1.0.3.

The J2MEWTK emulators should be listed under the J2ME Wireless Toolkit
node. If the emulators you wish to use are all listed, then they are
correctly installed and you may skip the remaining steps.

However, in some configurations, version compatibility problems have
interfered with automatic installation of J2MEWTK emulators, requiring
them to be installed manually. If any of the following conditions are
true, then you will need to complete the remaining steps:

- some or all of the J2MEWTK emulators are missing 
- J2ME Wireless Toolkit 1.0.3 is missing 
- you installed J2MEWTK as a standalone product 
- you have additional emulators to install

3.Right-click the Installed Emulators node, and from the context menu
choose Add Emulator.

4.In the Select emulator installation directory dialog box, navigate to
the desired installation directory for the emulator(s) you wish to
install (see Figure 2).

On the Windows platform, for example, the default installation
directory for standalone installation of J2MEWTK is C:\j2mewtk.

If you used the Mobile Edition module (which bundles the J2MEWTK), look
in /emulator.

The Windows default location for J2MEWTK bundled in a Forte module is

Quick Tour of Mobile Edition's Features

A brief overview of the full-featured Sun ONE Studio Mobile Edition IDE
is presented below. The intention is to provide enough basic knowledge
to enable an understanding of the MIDlet building demonstration which


Upon starting the Mobile Edition IDE, the Editing workspace is active,
and the following three windows are open:

- Main Window - consisting of menus, toolbars, and the workspace tabs
for Editing, Running, Debugging.

- Explorer Window - including tabs for choosing alternative views for
Filesystems, Project, Javadoc, and Runtime (with the Filesystems view
initially chosen).

- Properties Window - displays the properties of the object currently
selected in the Explorer Window.

Object-Based Views

Each Explorer view displays a tree of object nodes, each of which can
be opened to display child object nodes contained within it. For
example, in the Filesystems view the objects under the top-level
Filesystems node represent mounted source trees - typically directories
in a local file system, or JAR files which contain directory
structures. Opening an upper-level node exposes the nodes contained
within it, such as subdirectories, Java objects, or other files. For
example, opening a Java object node exposes a class node, which itself
may contain field nodes, constructor nodes, method nodes, and bean
pattern nodes etc. See Figure 3 for an illustration of objects and
properties belonging to the UIDemo example.

Options and Properties

The entire IDE can be thought of as one big tree of interconnected
objects with a surprisingly large number of user-configurable
properties. IDE objects can be easily and dynamically added, removed,
and manipulated.

For example, to demonstrate IDE configuration, the following steps
explain how to set a property to display the extensions of file objects
in the Explorer window.

1.From the main menu, choose Tools > Options to open the Options
window.  2.Navigate through the nodes, IDE Configuration > System.
3.Click the System Settings node, and notice the property sheet which
opens in the right pane of the Options window.  4.Set Show File
Extensions to True.

Immediately, the extensions of file objects appear in the Explorer

Code Samples

Sun ONE Studio 4, Mobile Edition comes with an assortment of sample
MIDlets and MIDlet Suites which users are encouraged to experiment with
in preparation for development work. These samples can be accessed from
the Filesystem tab of Explorer window, and inside the sampledir
directory. The sampledir directory is shown in Figure 2, immediately
below the Filesystems node.

The sampledir node itself contains various child nodes. The example and
midp nodes contain MIDlet source code used by the MIDlet suites
discussed in the examples below. The icons node contains, as might be
imagined, icons. The bottom four nodes - UIDemo, demos, games, and
photoalbum - are MIDlet suites, and ready to run. To run these MIDlet
suites, right-click any of them, then choose Execute from the context
menu. The IDE will compile the classes, build a JAR, deploy it to the
default emulator, switch to the Running workspace, and launch the
emulator. As can be seen, testing a functional MIDlet suite in the IDE
is a very simple procedure, as the compiling, preverifying, and
building of the JAR all happen automatically.

Creating and Testing a MIDlet

A number of tasks are involved in creating and testing a MIDlet.

Creating a Practice Package

The first task is to create a Java package in which to hold the MIDlet
suite demo:

1.Create (or choose) a practice work area in your local environment -
that is, outside of the IDE. For example, in a Windows environment you
could create C:\practice_j2me.

2.In the IDE Explorer window, Filesystems view, right-click the
top-level Filesystems node, and from the context menu choose Mount >
Local Directory.

3.Navigate through the New Wizard to choose your practice work area
(from step #1), then click Finish.

The work area that you selected will appear as a mounted filesystem.

4.Right-click the newly mounted practice work area, and from the
context menu choose New > Java Package.

5.The New Wizard this time prompts for a name for the new Java package.
Name it demo, and click Finish.

Creating MIDlet Suite with an Initial MIDlet

The next task is to create a new MIDlet suite from Sun ONE Studio's
templates. When creating a new MIDlet Suite, there is an option to
initially create a single MIDlet in it - additional MIDlets may be
added later as desired.

1.In the Explorer window, right-click the demo package created above,
and from the context menu choose New > MIDP > MIDletSuite.

2.In the New Wizard, name the new MIDlet Suite, demoSuite, and click

3.In the following screen of the New Wizard (see Figure 4), choose the
"Create New MIDlet" option.  Select the HelloMIDlet template, naming
the new MIDlet, demoHello, then click Finish.

Alternatively, you may click Next to add an icon, or just to explore
the subsequent screen of the New Wizard.

The IDE will create a new MIDlet and a MIDlet Suite.

4.Open the demoHello MIDlet in the Source Editor, and locate the
startApp() method (about halfway through the code). Change "Test
string" to a greeting in your favorite language/dialect - for example,
"G'day, Mate!" if you're fond of Australia. The line is shown in Figure
6 below.

5.Right-click anywhere in the source, and choose Compile from the
context menu.

6.In the Explorer window right-click demoSuite and from the context
menu choose Update JAR. This command must be executed every time you
modify any of the JAR content.

7.Right-click demoSuite again, this time choosing Execute from the
context menu.

The default emulator will be launched, with the demoHello MIDlet ready
to run.

8.Launch the demoHello MIDlet, and verify that your greeting appears as
it should. Then dismiss the emulator and return to the Editing

The emulator should resemble the illustration in Figure 5, except the
System Props MIDlet has not yet been added.

Adding an Existing MIDlet to a MIDlet Suite

As many MIDlets may be added to a MIDlet suite as the target device can

1.In the Explorer window, right-click the demoSuite node and choose
Edit Suite from the context menu.

The Edit Suite specialized editor will open, and includes MIDlets and
Jar Contents tabs. In the MIDlets tab you may add, remove, and
rearrange MIDlets within a suite. In the Jar Contents tab you may add
or remove other resources in the MIDlet suite's JAR.

2.With the MIDlets tab active, click the Add button. 

A new row with default values will be added to the list of MIDlets in
the suite.

3.With reference to the following definitions, edit the new row to make
it usable, then click OK when done.

- MIDlet Name - The display name which the user will see in the MIDlet
suite menu.  Change it to "System Props".

- MIDlet Class - The existing MIDlet to be added to the suite.  Browse
through the sampledir > example nodes, and choose PropExample.

NOTE: This only adds a reference in the menu - the compiled and
preverified class file must still be added for the MIDlet.

- Icon - An icon to display in the menu next to the MIDlet Name. This
can be ignored for the time being.

4.Now with the Jar Contents tab active, browse to sampledir > example
node again, select PropExample and click Add.

The MIDlet will be added to the Selected Content pane.

5.Click OK to close the Edit Suite window.

6.Right-click demoSuite node again, and choose Update JAR from the
context menu. (Remember to update the JAR content every time you modify
its contents).

7.Again right-click the demoSuite node, and choose Execute from the
context menu.

The default emulator will be launched again. Verify that the menu looks
as it should, and that both demoHello and PropExample run correctly
(see Figure 5).

Importing an Existing MIDlet

Sun ONE Studio performs well with Java source which has been developed
elsewhere. To use externally developed Java code, simply copy the code
into a mounted filesystem, or mount the directory which contains the
code. However, there is one pitfall when importing MIDlets. The default
compiler assigned to imported Java source is External Compilation,
while MIDlets must have the Preverify Compiler assigned. Moreover, if
you use the wrong compiler, the MIDlet will compile without error, but
fail in the emulator because the preverify step was omitted.

Use the following instructions to ensure that an imported MIDlet has
the right compiler, executor, and debugger settings, or to correct the
settings if necessary. This example uses a MIDlet in sampledir, instead
of a newly imported MIDlet. All objects in sampledir already have
correct settings, so this example shows how to verify correct settings,
instead of demonstrating and fixing a problem.

1.In the Explorer, browse to sampledir > example node, right-click
PropExample, choose Properties from the context menu, and click the
Execution tab.

Notice that the Compiler property is set to Preverify Compiler, as it
should be. If the source had been imported from an external location,
you would need to change it from the default.

2.Click the Compiler property value to expose the list of available

Notice also that the Debugger is set to Emulator Debugger, and the
Executor is set to Emulator Executor. They also would default
incorrectly with imported source, and should be corrected.

Debugging a MIDlet

Sun ONE Studio's debugger makes full use of JPDA. There are several
specialized debugger types built on the basic debugger to support
different technologies, such as the Emulator Debugger, Applet Debugger,
and J2EE Server Debugger. MIDlets require the Emulator Debugger.

Setting Breakpoints

For the sake of simplicity, only one breakpoint will set, on a code
line in the demoHello MIDlet:

1.Double-click demoHello in the Explorer window to open it in the
Source Editor.

2.Set the cursor on the first executable statement in the startApp()
method, the line:

TextBox t = new TextBox("Hello MIDlet", "G'day, Mate!", 256, 0);

3.In the IDE main window open the Debug menu. A quick way to set a
breakpoint on this line would be to choose Toggle Breakpoint menu item.
But for the purposes of this example, choose Add Breakpoint to launch
the Add Breakpoint dialog.

4.In the Add Breakpoint dialog open the Breakpoint Type list. As can be
seen, the debugger offers a wider range of break point options than the
simple arrival at a specified line:

- Line - the classic breakpoint type, breaking when execution reaches a
specified line number.
- Method - break on entry to a specified method. 
- Exception - break when a specified exception type is thrown. 
- Variable - break when a specified variable is accessed. 
- Thread - break on thread start or death. 
- Class - break when a specified class is loaded or unloaded.

5.Choose Line for Breakpoint Type, then click OK. 

Notice that you can even specify a condition that must be satisfied
before the break will happen. However, this is beyond the scope of the
present discussion. Once the breakpoint is set, the line is highlighted
in pink, as shown in the Figure 6. 

Running the Debugger

All preparations being ready, the following step describe how to run
the debugger:

1.In the Explorer window choose demoSuite.

2.From the IDE main menu choose Debug > Start.

The IDE will switch to the Debugging workspace and launch the emulator.
The Debugger window has view panels which may be opened or closed by
buttons at the top of the window.
- Sessions - monitor multiple simultaneous debugging sessions. 
- Breakpoints - work with breakpoints. 
- Threads - monitor multiple execution threads. 
- Call Stack - dynamic stack trace information. 
- Watches - watches variable values change during execution. 
- Variables - examine or set variable values. 
- Classes - examine classes that are available during execution. 
- Properties - work with properties for any object selected in the
panels above.

3.In the Breakpoints view panel right-click the breakpoint which was
set, then choose Go to Source from the context menu. The Source Editor
window will open to the breakpoint line in the class which is being

4.In the emulator launch demoHello. If execution breaks at a location
in the KVM (Sun's K virtual machine), then choose Debug > Continue from
the IDE main menu. Execution will break when it reaches the breakpoint
that was set. At this point you may examine the Call Stack, modify
variable values, or any other debugging activity. The Debugger Window
is shown in Figure 7.
Introduction to Sun[TM] ONE Studio, Mobile Edition Software


News and Solutions for Users of Solaris, Java and Oracle's Sun hardware products
30,000+ Members – 30,000+ Articles Published since 1998