Java ME Quick Start
From Symbian Developer Community
Symbian Foundation does not have the full Java package for the time being because of licensing issues, only platform APIs and stub implementations for them are provided. The full implementation is available directly from Nokia for those S60 licensees that have relevant licenses from the appropriate 3rd party Java technology vendors.
The S60 5th Edition SDK from Nokia is being used as the SDK for Symbian^1 so it is possible to use that SDK to develop, install, manage and run Java applications.
This article provides information on how to start developing Java ME applications for the Symbian platform. It discusses the common Integrated Development Environments (IDEs) and development kits, the benefits that the Symbian platform offers Java ME developers and where to go for more detailed information.
Java ME is a mature technology and has generated a large range of technical material during the past decade. Rather than attempt to cover all aspects here, this article assumes the reader is familiar with the basics of Java ME technology and is interested in what the Symbian platform can offer Java ME applications.
This article is supported by a page that provides links to useful resources.
There is also a terminology section giving a basic glossary for some of the more commonly encountered acronyms and supporting technologies.
Contents |
What is Java ME?
Java technologies come in a number of flavours. For mobile phone development, we use a particular subset of Java referred to as Java Micro Edition. During the past decade, this has been referred to as J2ME and, more correctly and recently, Java ME.
Java ME is designed to be as flexible as possible, and targets a wide range of resource-constrained devices including pagers, PDAs and mobile phones. Applications written for mobile phones using Java ME are called MIDlets and execute in a secure Java runtime that is shipped as part of a device's firmware.
S60-based mobile phones started to support the Mobile Information Device Profile Version 2.0 (MIDP 2.0) from mid 2003. This is currently the most common profile on the market. More recent phones support newer MIDP versions such as MIDP 2.1.
The MIDP standard defines a set of libraries for building MIDlets including high-level widgets, basic sound generation, networking, local storage as well as the MIDP 2.0 Game API. The Game API supports many commonly used game concepts including sprites, tiles, layers, collision detection and a special game canvas that helps simplify game development.
A profile such as MIDP runs over the top of a configuration. A configuration defines a lowest common denominator for a category of devices that share similarities in terms of memory budgets, processing power and network connectivity. Current S60 devices use version 1.1 of the connection limited device configuration (CLDC).
The Java ME model supports extensibility so that, as new technologies emerge, they may be made available through new Java libraries for developers to utilise in their MIDlets. This is done through a community process via a Java specification request (JSR). When the standard has been agreed on by all interested parties, manufacturers such as Nokia will provide implementations that ship with the latest phones. There are currently more than 80 JSRs that relate to Java ME in some way, providing the MIDlet developer with a rich and diverse set of additional technologies. Examples of commonly available JSRs that extend MIDP 2.0 on the Symbian platform include the Bluetooth API (JSR 82), the Wireless Messaging API (JSR 205) and the Mobile 3D Graphics API (JSR 184).
Java ME has been extremely successful since its inception and has shipped on millions of devices worldwide. In particular, it has enjoyed huge success in the mobile games market with tens of thousands of game titles developed and sold during the past ten years.
However, Java ME’s industry-wide success has been set back somewhat by implementation variations among manufacturers. Not all phones support the same set of JSRs and sometimes the way a given JSR behaves may vary across devices from the same manufacturer. This is called ‘fragmentation’ and can lead to complicated MIDlet source code because the application developer must work around each issue.
As you will see in the next section, one of the benefits of using Java ME on the Symbian platform is that fragmentation is minimized because it is based on a single MIDP implementation.
Why Should I Use Java ME on the Symbian Platform?
Java on the Symbian platform provides best-of-breed implementations of the Java ME libraries, providing a consistent platform for the Java ME developer. The Symbian platform is a 32-bit multi-tasking operating system, powering more than 70% of the world’s smartphones and provides to MIDlets the following advantages:
- The large set of well-defined and mature JSRs are consistent across a wide range of S60 devices, which helps to avoid fragmentation.
- Java ME libraries take advantage of the underlying platform’s native UI widgets so that Java ME applications look more like native applications, which results in a more consistent user experience.
- By targeting the Symbian platform, you reach an extremely large market – in the last quarter of 2008 alone, roughly 11 million N-series and E-Series devices were shipped worldwide.
- Symbian OS does not place hard constraints on MIDlets so, within the bounds of available resources, there are no limits on JAR size, the number of threads or sockets you can have, and no limits on local persistent storage. In addition, Symbian OS will automatically grow or shrink the size of heap memory as required.
- Developers can focus on creativity and expressing their ideas, rather than worrying about resource restrictions.
- Developers can create libraries of code that can be re-used for many projects without worrying about different resource restrictions of a range of underlying operating systems.
- MIDlets on the platform benefit automatically from a number of performance enhancements provided by the platform, such as dynamic adaptive compilation, which results in faster runtime execution.
Java ME on Symbian may also be attractive to Symbian C++ developers. It offers a number of benefits, such as access to many familiar APIs that are often easier to use, as well as automatic garbage collection, simple container classes and a string class. The user interface designer found in NetBeans provides rapid application development facilities.
The resources section has links to more detailed information on the Java runtime on Symbian OS, including a comparative analysis of native development versus Java ME, as well as an overview of Symbian OS runtimes and where Java ME fits into the Symbian ecosystem.
How Do I Get Started?
This section walks you through the main steps to follow when getting started with Java ME on the Symbian platform. These are summarized below:
- Do some background reading. See Recommended Reading below and the terminology document at the end of this article.
- Choose and install an IDE; the two choices are Netbeans or Eclipse. Optionally, you may install the Sun Wireless Toolkit.
- Install an S60 platform SDK – this provides an S60 emulator that is very close to the target phones.
- Learn how to use the various tools: build test cases, on-device debugging and so on.
Recommended Reading
The central repository for Java ME information on the Symbian platform is Forum Nokia, which provides developer resources including user forums, a wiki, tutorials, sample applications and documentation. Some useful links to online material are listed below:
- Getting Started With Mobile Java includes a tutorial that walks you through the process of building, running, testing and deploying MIDlets to Nokia devices.
- The Java ME Developers’ Library includes known issues, developer guides and Java API documentation.
- Java ME API Support on Nokia Devices details the wide range of JSRs available for various editions of the S60 platform.
- Java ME on Symbian OS provides a good overview of the benefits Symbian OS brings to Java ME.
For more links to detailed Java ME and Symbian OS information, please consult the resources section.
Tools and SDKs
Sun Wireless Toolkit
A good starting point for Java ME development is the Wireless Toolkit (WTK) from Sun. The WTK is a toolkit, not an IDE, and as such simply provides a way to quickly build, test and deploy MIDlet suites using a standard reference implementation of MIDP and a representational set of optional JSRs. In effect, the WTK acts as an idealised Java ME emulator.
The WTK is very useful when starting Java ME development because it allows you to focus on the MIDlet development cycle without worrying about the details of any particular SDK. You can use the WTK to build, test and deploy MIDlets in a very short time and, in addition, it seamlessly integrates into IDEs such as Netbeans and Eclipse. Figure 2 shows the WTK with an opened project:
The toolkit also has a rich set of configuration options available under the Settings button on the toolbar (see Figure 3 below).
One of the most useful tools you get is the Utilities applet (see Figure 4), which is available under the File menu. This is a small collection of utility programs that perform all of the most common tasks you need in MIDlet development, including wireless-messaging simulation, a SIP server, certificate management and even a way to work with landmarks when building location-based services.
In addition, you can delete local storage a MIDlet uses and there's a network monitor for analysing socket traffic, a profiler to zero in on performance bottlenecks in your code and the memory monitor, which allows you to do heap analysis while your MIDlet executes.
For more information on how to use these tools and get the most out of the WTK, read the user guide located in the ‘docs’ sub-directory of your WTK installation.
In Java ME development, there are two competing free IDEs – Netbeans and Eclipse.
They’re both good IDEs with their respective strengths and weaknesses. For a fairly informative comparison of the two, see this article at Javaworld (note that the article refers to older versions of both IDEs).
As mentioned above, both Netbeans and Eclipse integrate the WTK discussed above, so you get all the same profiling tools as well.
Eclipse
Eclipse can be downloaded from www.eclipse.org. The Eclipse model runs largely on plug-ins and requires the Java ME plug-in to function as a mobile Java IDE. Eclipse provides a package named Pulsar. Pulsar is a tools integration platform for the mobile developer. It makes it easy to get the tools and handset SDKs you need for developing mobile applications including Java ME.
Alternatively, You can install a plug-in from www.eclipseme.org. EclipseMe has graduated to become the new Eclipse Mobile Tools for Java (MTJ) project (which is also included on the Pulsar package ), however you can still download and install EclipseME. This site has complete information on how to set up and configure Eclipse for Java ME.
Eclipse is mature, stable, flexible and well supported and is highly recommended. A wealth of support information is available online.
Some useful links to help you get started with Eclipse are:
- The Eclipse FAQ
- http://eclipsetutorial.sourceforge.net/ – a set of video tutorials
- http://www.mobilefish.com/developer/eclipse/eclipse_quickguide_j2me.html
- http://www.autexier.de/jmau/dev/j2me/j2me.html – Java ME IDE tutorial.
Netbeans
The Netbeans IDE from Sun is also extremely popular. The latest version, 6.5, comes in different flavours depending on whether you want to target the enterprise, desktop or mobile development. Netbeans is available from www.netbeans.org.
Like Eclipse, there are entire online communities dedicated to Netbeans, particularly http://community.java.net/netbeans/, which is the most useful one. One of the benefits of Netbeans is that it comes pre-bundled with the WTK by default, so you don’t need to install that as well.
For more information about the Netbeans IDE, refer to:
- Getting Started with Netbeans 6.0 Mobility for Nokia Devices Screencast at Forum Nokia
- Netbeans Mobility at Forum Nokia
- Netbeans 6.5 Release Information.
Software Development Kits
The WTK only emulates a kind of ideal generic device. When you work with real phones, it is far better to use an SDK with an emulator that matches real hardware and JSR implementation as closely as possible.
There are SDKs available for a large number of platforms. Many support the universal emulator interface (UEI), which allows IDEs such as Netbeans and Eclipse to find and import them for use in development. SDKs for various versions of the S60 platform can be downloaded the Forum Nokia website, using the following table as a guide:
| S60 Release | SDK to Use |
| S60 3rd Edition | S60 for Java |
| S60 3rd Edition Feature Pack 1 | S60 for Java |
| S60 3rd Edition Feature Pack 2 | All-in-one S60 SDKs |
| S60 5th Edition | All-in-one S60 SDKs |
The all-in-one SDKs support development using Java ME, Flash, Python and Symbian OS C++ in one installation.
Once you’ve installed your SDKs, you need to let your IDE find out about them. This is easily done in both Eclipse and Netbeans.
In Eclipse, you do this via the Windows | Preferences menu. Simply expand the J2ME node on the left and select Device Management. As Figure 5 shows, you will then see a list of the emulators that Eclipse already knows about.
Click the Import button at the top right to display the SDK detection window (Figure 5) and browse to the directory where your SDKs have been installed. When you’ve done that, simply click on the Refresh button and Eclipse will do the rest. When completed, you will see a list of all the emulators/SDKs that were found and that can now be used for Java ME projects.
With Netbeans, this process is even easier. Open the Java Platform Manager (Figure 7) via the Tools | Java Platforms menu option and click on the Add Platform button. This starts the detection wizard (Figure 8).
Because we’re only interested in standard Java ME SDKs at this point, you’d select the Java ME MIDP Platform Emulator option shown above. When you click the Next button, Netbeans will immediately scan your system for any newly installed SDKs and you can select the ones you want to add (Figure 9).
For more information, use the links supplied in the sections above.
On-Device Debugging and Testing
When using the Symbian platform, you can perform on-device debugging (ODD) using tools included with the S60 SDKs. These run between your development PC and phone using Bluetooth – the exact sequence of steps is covered in Chapter 5 of Java ME on Symbian OS: Inside the Smartphone Model.
Alternatively, you can write to local storage for runtime logging on the device. One commonly used mechanism here is the open-source MIDPLogger. This includes a MIDlet for managing and viewing log entries, as well as a simple class that you include in your code base with log-level support. The class will write log data to its own local store using the record management system (RMS), which is part of the MIDP 2.0 specification.
From S60 3rd Edition phones onwards, a new method of redirecting standard output on devices is explained in detail in the Forum Nokia article How To Get System.out From a MIDlet in S60 devices. This example also has the MIDPLogger source and allows log files to be sent via MMS for later inspection.
Developers in the fields of enterprise and desktop Java have been using the JUnit unit test framework for quite a while now. Developers write a set of test classes and run them through the framework, which uses something called Java Reflection to invoke the test cases (the Java Reflection API is explained in the terminology section).
Java ME doesn’t support reflection because it has a lot of overhead, so you need to use JMUnit, which is a simpler version that you can even run on devices. It works in much the same manner as JUnit but uses a simplified model that does not require the use of reflection libraries. JMUnit can also be used in either Netbeans or Eclipse (it is included by default in the Netbeans 6.5 installation).
Security and Signing
The MIDP 2.0 Security Model
The MIDP 2.0 security model depends on three core concepts:
1. Restricted APIs
These tend to be APIs that may incur a financial cost to the end user such as by opening a network connection or sending an SMS. MIDlet suites declare their intention to use restricted APIs in their JAD file. As an example, to be able to open a socket, a MIDlet must request the javax.microedition.io.Connector.socket permission in its JAD file.
Authorisation is determined at runtime either by user preferences or by security policies on the mobile phone itself.
2. Protection domains
A protection domain is a grouping of API permissions that grant access (or may grant access) to a set of restricted APIs. When a MIDlet is installed, it is bound to a particular protection domain and subject to the security policy of that domain – in other words, the only permissions that can be granted to MIDlets are those that are included in the protection domain that the MIDlet is bound to.
There are four commonly defined protection domains:
- Unidentified third-party protection domain – the default domain for unsigned MIDlets
- Identified third-party protection domain – for developers of MIDlets that use restricted APIs
- Operator – the network operator (AT &T, Orange, Vodaphone and so on)
- Manufacturer – for example, Nokia.
3. Trusted MIDlets
A MIDlet that has not been digitally signed will always be treated as untrusted, and will be bound upon installation to the unidentified third-party protection domain.
A trusted MIDlet is one for which the source, authenticity and integrity of the JAR file can be reliably determined by the phone itself. This is achieved by digitally signing the MIDlet. Signed MIDlets may be bound upon installation to a trusted domain (manufacturer, operator or identified third party). A trusted domain can only be bound to if
- there is an appropriate root certificate on the device for that domain AND
- the MIDlet has been signed with a certificate that can be verified using that root certificate.
Protection domains cannot be changed and are a property of the mobile phone itself. Both operators and manufacturers can add custom protection domains of their own.
In addition to the above concepts, there are two types of permission classes that can be assigned to restricted APIs: allowed and user. If set to allowed, access to the restricted API is granted without any user interaction. If set to user, a MIDlet can access a particular API only if granted permission to do so by the user. This may occur in one of three ways:
- Oneshot – the user is prompted whenever the MIDlet attempts to use the restricted API.
- Blanket – user assigns the permission once and it remains in force unless explicitly revoked.
- Session – user is prompted on first use, each time the MIDlet is executed.
Signing
Signing a Java ME MIDlet has nothing to do with Symbian Signed. Java ME operates over a wider set of devices and operating systems than Symbian OS and consequently Java ME MIDlets are exempt from the Symbian Signed process.
On S60 phones, MIDlets can be signed with certificates from Verisign or Thawte or signed through the Java Verified Program. Getting your MIDlet Java Verified allows you to use the ‘Powered by Java’ logo in your MIDlet, which is an accepted indication of code quality. It is also common for network operators to require third-party MIDlets to pass the Java Verified program before they sell them through their online portals.
Signing through the Java Verified Program produces a signed JAR file that can be authenticated using the Unified Testing Initiative (UTI) certificate. Forum Nokia has more details on the Java Verified process, as well as a detailed walk-through of MIDlet signing using a Verisign certificate. On S60 phones, you can find out what root certificates the device has by navigating as follows:
Application Menu, Tools, Settings, General, Security, Certificate Management, Authority
This will display all certificates on the device. Those that start with ‘MIDP’ are those used for JAR code signing.
Forum Nokia provides a number of useful articles for further information on Java ME security and signing:
- Java Security Domains
- MIDP 2.0 Signed MIDlet Developer’s Guide
- Java ME Signing for Dummies
- Java Verified
- Designing your MIDlet for Java Verified
There is also an excellent introduction on the Sun site called Understanding MIDP 2.0’s Security Architecture. The resources page also has links to more information on Java ME security and signing.
What’s Next?
Java ME is a technology with a lot of momentum, and new JSRs and standards emerge all the time. The Mobile Services Architecture (MSA) is an industry standard that aims to reduce fragmentation and provide a consistent Java ME platform for developers to target. In addition to specifying what component JSRs must be present on a compliant device, the MSA also clarifies behavioral requirements in order to improve the predictability and interoperability of the JSRs.
Many S60 phones are already MSA 1.1 compliant and work is in progress on finalising the MSA 2.0 specification. Many new JSRs will be part of MSA 2.0, including new versions of the Vector Graphics and OpenGL ES libraries, as well as support for XML-based user interfaces and MIDP 3.0.
MIDP 3.0 is the next major version of the Mobile Information Device Profile and defines a number of new concepts as well as adding new functionality that addresses the demands of the current market, ensuring that Java ME technology remains competitive. Here are just some of the new features MIDP 3.0 introduces:
- LIBlets – these are Java ME libraries that can be shared among all MIDlets on a device, greatly simplifying development and increasing code re-usability.
- Inter-MIDlet Communication (IMC) – MIDlets will be able to communicate with each other at runtime in a well-defined manner.
- Start-on-boot MIDlets
- Screensaver MIDlets
- Access to phone-state information such as battery level, profile, power status and so on
- Enhanced full-screen UI with cascading menus and input widgets.
MIDP 3.0 is also part of the MSA 2.0 standard. Together, these represent a huge step forward for Java ME and future development on the Symbian platform.
Summary
The Symbian platform brings many benefits to Java ME developers. Symbian OS is the world’s leading operating system for smartphones, and the Java ME implementation on top of it provides a stable, consistent and well-documented set of JSRs that provide a wide range of functionality to MIDlets.
When targeting the Symbian platform, Java ME MIDlets automatically inherit all the benefits of the underlying operating system, such as fast execution speeds, native widgets and best-of-breed implementations.
Since the Symbian platform does not place hard limits on Java ME resources, developers have the freedom to focus on application design and use cases, rather than concerning themselves with externally imposed constraints.
The Java ME/Symbian combination is mature, well supported and stable. This makes it extremely easy for Java ME developers to build highly successful applications with global reach, because millions of S60 mobile phones have already been shipped worldwide.
Further Information
The terminology page includes a glossary of some common Java ME terms. For more information and links to a wide range of additional material, please refer to the resources section.
Nokia has a lot of documentation for Symbian/S60 Java Runtime available at: http://library.forum.nokia.com/index.jsp?topic=/Java_Developers_Library/GUID-660EC670-B7DB-4005-BF2D-411E5C0B3867_cover.html
Sign in to comment…










