×
Namespaces

Variants
Actions
(Difference between revisions)

Getting started with Java ME

From Nokia Developer Wiki
Jump to: navigation, search
firt (Talk | contribs)
leisti (Talk | contribs)
(many updates; added a section on required software tools for S60 JavaME development)
Line 1: Line 1:
 
[[Category:Java]][[Category:How To]][[Category:IDE/SDK]]
 
[[Category:Java]][[Category:How To]][[Category:IDE/SDK]]
  
'''(This page is very much work in progress, please add more information, and screenshots link to other relevant pages and edit it to give more complete view of this)'''
+
''(This page is very much work in progress.  Please add more information, screenshots, and links to other relevant pages.)''
  
Basically getting your first [[Java ME]] application ([[MIDlet]]) running on a real device, requires a number of steps. This Wiki page tries to guide through the process. As this is targeted to first time MIDlet developers, some things are simplified, and more detailed information can be found elsewhere
 
  
==Analyze the situation==
+
Getting your first [[Java ME]] application ([[MIDlet]]) running on a real device requires a number of steps.  This Wiki page is a guide through that process.  As it is targeted at first-time MIDlet developers, some things are simplified, and more detailed information can be found elsewhere.
  
[[Java ME]] is a limited subset of the standard Java ([[Java SE]]) available on the desktop computers. Additionally there are some mobile phone related APIs available. There are a number of limitations you need to keep in mind
+
 
* MIDlets run in a sandbox because of security reasons (there are confirmations when using certain functionalities, like networking or sending SMS messages)
+
== Is Java ME the right tool for your requirements? ==
* There is no JNI (Java Native Interface) so you cannot extend the capabilities of Java ME environment on the phone
+
 
* There is no Swing or AWT classes, MIDlets use their own (simplistic) UI classes
+
[[Java ME]] is a limited subset of the standard Java ([[Java SE]]) available on the desktop computers, with some additional mobile phone-related APIs. There are a number of limitations you need to keep in mind:
 +
* MIDlets run in a sandbox because of security reasons. (There are confirmations when using certain functionalities, like networking or sending SMS messages.)
 +
* There is no JNI (Java Native Interface) so you cannot extend the capabilities of Java ME environment on the phone.
 +
* There are no Swing or AWT classes. MIDlets use their own (simplistic) UI classes.
 
* The capabilities of the Java ME environment vary widely, meaning that the phones have different set of optional APIs implemented (examples include access to files, access to phonebook, video/audio recording, 3D graphics, etc.)
 
* The capabilities of the Java ME environment vary widely, meaning that the phones have different set of optional APIs implemented (examples include access to files, access to phonebook, video/audio recording, 3D graphics, etc.)
So first of all, before starting anything else, think if Java ME is the right choice for you or should you try to use Flash Lite for your application (runs both on Series 40 and S60 phones), or should you start using Symbian C++ programming (those apps work on S60 phones).
 
  
If Java ME seems to be the way to go, you can find a lot of good information in this Wiki or in the FN [http://discussion.forum.nokia.com/forum/forumdisplay.php?f=3 Java Discussion Forums]. There is also documentation available on Forum Nokia web site, as well at [http://java.sun.com/javame/reference/index.jsp Sun Web site] and [http://www.ibm.com/developerworks/wireless IBM DeveloperWorks Web site].
+
So first of all, before starting anything else, think whether Java ME is the right choice for you, or whether you should instead use Flash Lite for your application (runs both on Series 40 and S60 phones), or whether you should program in native Symbian C++ (for S60 phones only).  (However, native C++ development for SymbianOS is quite tedious and error-prone, so just for productivity reasons, Java ME might be a better choice.)
 +
 
 +
If Java ME seems to be the way to go, you can find a lot of good information in this Wiki or in Forum Nokia's [http://discussion.forum.nokia.com/forum/forumdisplay.php?f=3 Java Discussion Forums]. There is also documentation available elsewhere on [http://forum.nokia.com/ the Forum Nokia web site], as well at [http://java.sun.com/javame/reference/index.jsp Sun Web site] and [http://www.ibm.com/developerworks/wireless IBM DeveloperWorks Web site].
 +
 
 +
 
 +
== Overview of the development process ==
 +
 
 +
First note that you have to code, compile and package the MIDlet on your development computer. You cannot create a MIDlet on the phone itself (yet).
 +
 
 +
To write MIDlet code, use whatever text editor or [[IDE]] (Integrated Development Environment) you prefer.  (But see the Nokia-supported IDEs below.)  Then compile the code with the javac compiler which is comes with a Java SE SDK (JDK). Even though you do not need to worry about it right now, your code is also preverified at this stage.
 +
 
 +
Before being able to install the MIDlet on a real device, you still need to package the MIDlet classes and resources to a [[JAR]] (Java Archive) file and generate a [[JAD]] (Java Application Descriptor) file. The JAR file contains all the code needed to run the application. The JAD file is a text file containg descriptive information about the MIDlet (size, needed APIs, MIDlet name, Vendor name, optional signing information), which the phone (and user) can use to decide whether or not to download the MIDlet at all. You need only to install the JAR file on the phone to be able to run the MIDlet; however, it is strongly recommended to use both of the files to install the application.
 +
 
 +
At this stage, you can test the MIDlet on your development workstation using the phone [[emulator]], and then most probably make changes, then recompile and repackage it.  When you are satisfied with the result, you can transfer the generated JAR and JAD files to a real phone, install the app, and test it.  (You should always test a MIDlet on a real device before distributing it.)
 +
 
 +
You can also use some online resources to test your application on real devices, such [http://www.forum.nokia.com/main/technical_services/testing/rda_introduction.html Remote Device Access (RDA)] or [http://www.deviceanywhere.com Device Anywhere].
 +
 
  
==Overview of the development process==
+
== Required hardware ==
  
First note, that you have to code, compile and package the MIDlet on a computer. You cannot create a MIDlet on the phone itself (yet).
+
Because of the requirements of Nokia's development tools, your development computer has to be a PC running Microsoft Windows 2000 (SP 4) or Microsoft Windows XP (SP 2).
  
You can use whatever text editor or [[IDE]] (Integrated Development Environment) you like to write the MIDlet code (for example, [[Eclipse]] or [[NetBeans]] [[Mobility Pack]]. Then compile the code with the javac compiler which is comes with the Java SE SDK (JDK). Even though you do not need to worry about it right now, your code is also preverified at this stage.
 
  
Before being able to install the MIDlet on a real device, you still need to package the MIDlet classes and resources to a [[JAR]] (Java Archive) file and generate a [[JAD]] (Java Application Descriptor) file. The JAR file contains all the code needed to run the application. The JAD file is a text file containg descriptive information about the MIDlet (size, needed APIs, MIDlet name, Vendor name, optional signing information), which the phone (and user) can use to decide whether or not to download the MIDlet at all. You need only to install the JAR file on the phone to be able to run the MIDlet, however it is recommended to use both of the files to install the App (you will be thankful for this tip in the future :-)
+
== Required software for S60 ==
  
At this stage you can test the MIDlet on your development workstation using the phone [[emulator]] (and of course make some changes to the app and compile/package it again). When you are satisfied to the MIDlet you can transfer the JAR and JAD file to the phone, install it and test the application on the phone (it is always advised to test the MIDlet on a real device also).
+
The combination of tools listed here (all free) has been tested by the writer ('''note: not yet!''') to work for developing applications for S60 using Java ME.  For future editors of this article: please make sure that your edits have been tested in practice, to prevent developer frustration.
  
You can also use some online resources to test your application on real devices, such [http://www.forum.nokia.com/main/technical_services/testing/rda_introduction.html Remote Device Access (RDA)] or [http://www.deviceanywhere.com Device Anywhere]
+
{| border=1 style="valign=top"
 +
|-
 +
! tool
 +
! recommended version
 +
! download at
 +
! notes
 +
|-
 +
| a Java SE (Standard Edition) Development Kit (JDK)
 +
| JDK 6 Update 4 (note: Java* 6 was formerly known as J2* 1.6)
 +
| [http://java.sun.com/javase/downloads/index.jsp download here (search for "JDK 6 Update 4")]
 +
| Select the Windows platform, then select the "Windows Offline Installation" option (or if you're feeling more adventurous, the "Windows Online Installation" option).  Save the installation file, then run it.  The installation directory is <tt>C:\Program Files\Java\jdk1.6.0_04</tt>.  Do not move the installation elsewhere, because other tools look for Java installations in this directory.
 +
|-
 +
| the [[Sun Java Wireless Toolkit for CLDC]]
 +
| 2.5.2
 +
| [http://java.sun.com/products/sjwtoolkit/ download here] (search for "Sun Java Wireless Toolkit 2.5.2 for CLDC")
 +
| The installation program should automatically detect that you have JDK 6 Update 4 installed in directory <tt>C:\Program Files\Java\jdk1.6.0_04</tt>.  If not, browse for that directory at the "Java (TM) Virtual Machine Location" phase of the installation.  The default installation directory is <tt>C:\WTK2.5.2</tt>; change it if you want to.
 +
|-
 +
| Nokia SymbianOS/S60 SDK for Java ([[JDK]])
 +
| S60 3rd edition, Feature Pack 2, MIDP SDK Beta
 +
| [http://www.forum.nokia.com/info/sw.nokia.com/id/6e772b17-604b-4081-999c-31f1f0dc2dbb/S60_Platform_SDKs_for_Symbian_OS_for_Java.html download here]
 +
|
 +
|-
 +
| the [[Eclipse]] IDE
 +
| 3.2.2
 +
| [http://archive.eclipse.org/eclipse/downloads/drops/R-3.2.2-200702121330/index.php download here]
 +
| The default installation directory is <tt>C:\Program Files\eclipse</tt>.  The writer prefers to append the version number to the installation; i.e., <tt>C:\Program Files\eclipse-3.2.2</tt>.
 +
|-
 +
| the [[EclipseME]] plugin for Eclipse
 +
| 1.7.7
 +
| [http://sourceforge.net/project/showfiles.php?group_id=86829 download here]
 +
| This is the last EclipseME version that runs on top of Eclipse v3.2.  Follow the installation instructions [http://eclipseme.org/docs/installEclipseME.html here].
 +
|-
 +
| Java ME Developer's Library
 +
| 2.1
 +
| [http://www.forum.nokia.com/info/sw.nokia.com/id/3cfc525e-f0ec-491c-badd-085c0e2df8bf/Java_ME_Developers_Library.html download here] (search for "Java ME Developer's Library v2.1 (Eclipse plug-in)")
 +
| This documentation is not absolutely necessary for development, but it is very useful.  After you've installed it, it is available to you from Eclipse's Help function.
 +
|}
  
==What tools to use==
 
  
You will be better off using a Windows-based computer for development, as many of the phone SDKs do not work properly on Linux.
+
Note that in addition to Eclipse, Nokia also supports the [[NetBeans]] IDE (plus its [[Mobility Pack]]) for S60/Java ME development.  See [http://www.forum.nokia.com/main/resources/tools_and_sdks/index.html#java here] for more details.
  
JDK
 
* (insert description here)
 
  
Full-blown IDEs
+
== Emulators and SDKs for Series 40 and Series 80 ==
* [[NetBeans]] with [[Mobility Pack]]
+
*[http://www.forum.nokia.com/info/sw.nokia.com/id/cc48f9a1-f5cf-447b-bdba-c4d41b3d05ce/Series_40_Platform_SDKs.html Java Tools from Nokia Series 40]
* [[Eclipse ME]]
+
*[http://www.forum.nokia.com/info/sw.nokia.com/id/449a2f84-2a8a-44fa-a7f4-93b53cb9c89a/Series_80_Platform_SDK_s_for_Symbian_OS_for_Java.html  Java Tools from Nokia Series 80]
  
Please note: As of right now, in order to maintain full compatibility with Nokia SDKs, you need to have Eclipse 3.1x and therefore will not be able to use newer Eclipse ME than 1.2.3. Newer versions will work to some extent, but not reliably.
+
You should also download and test your application in other vendors' emulators, too. (Motorola, Sony Ericsson, Samsung, etc.)
  
* etc
+
As for S60 development, use a PC with Windows 2000 or Windows XP.  Use the NetBeans or Eclipse IDEs.
  
Phone SDK
 
  
==Coding and compiling your first MIDlet==
+
== Coding and compiling your first MIDlet ==
  
 
See [[Hello World in Java ME]]
 
See [[Hello World in Java ME]]
  
==Typical pitfalls==
+
== Typical pitfalls ==
  
===Compiling the Java ME code with wrong Java compliance option===
+
=== Compiling the Java ME code with wrong Java compliance option ===
 
The correct compliance is 1.3 or 1.4. Compiling with 5.0 or 6.0 compliance makes it impossible to install the MIDlet.
 
The correct compliance is 1.3 or 1.4. Compiling with 5.0 or 6.0 compliance makes it impossible to install the MIDlet.
  
===Compiling and packaging the MIDlet for incorrect CLDC or MIDP version===
+
=== Compiling and packaging the MIDlet for incorrect CLDC or MIDP version ===
 
This is especially true when using Sun Wireless Toolkit, which by default builds the MIDlet for MIDP 2.1. However, most of the current phones have only MIDP 2.0 available. (Note, that you can install on a phone a MIDlet with lower CLDC/MIDP version than what the phone supports, but you cannot install a MIDlet with higher CLDC/MIDP version on the phone. Check the supported CLDC and MIDP versions on [http://www.forum.nokia.com/devices FN device specification pages].)
 
This is especially true when using Sun Wireless Toolkit, which by default builds the MIDlet for MIDP 2.1. However, most of the current phones have only MIDP 2.0 available. (Note, that you can install on a phone a MIDlet with lower CLDC/MIDP version than what the phone supports, but you cannot install a MIDlet with higher CLDC/MIDP version on the phone. Check the supported CLDC and MIDP versions on [http://www.forum.nokia.com/devices FN device specification pages].)

Revision as of 09:47, 29 January 2008


(This page is very much work in progress. Please add more information, screenshots, and links to other relevant pages.)


Getting your first Java ME application (MIDlet) running on a real device requires a number of steps. This Wiki page is a guide through that process. As it is targeted at first-time MIDlet developers, some things are simplified, and more detailed information can be found elsewhere.


Contents

Is Java ME the right tool for your requirements?

Java ME is a limited subset of the standard Java (Java SE) available on the desktop computers, with some additional mobile phone-related APIs. There are a number of limitations you need to keep in mind:

  • MIDlets run in a sandbox because of security reasons. (There are confirmations when using certain functionalities, like networking or sending SMS messages.)
  • There is no JNI (Java Native Interface) so you cannot extend the capabilities of Java ME environment on the phone.
  • There are no Swing or AWT classes. MIDlets use their own (simplistic) UI classes.
  • The capabilities of the Java ME environment vary widely, meaning that the phones have different set of optional APIs implemented (examples include access to files, access to phonebook, video/audio recording, 3D graphics, etc.)

So first of all, before starting anything else, think whether Java ME is the right choice for you, or whether you should instead use Flash Lite for your application (runs both on Series 40 and S60 phones), or whether you should program in native Symbian C++ (for S60 phones only). (However, native C++ development for SymbianOS is quite tedious and error-prone, so just for productivity reasons, Java ME might be a better choice.)

If Java ME seems to be the way to go, you can find a lot of good information in this Wiki or in Forum Nokia's Java Discussion Forums. There is also documentation available elsewhere on the Forum Nokia web site, as well at Sun Web site and IBM DeveloperWorks Web site.


Overview of the development process

First note that you have to code, compile and package the MIDlet on your development computer. You cannot create a MIDlet on the phone itself (yet).

To write MIDlet code, use whatever text editor or IDE (Integrated Development Environment) you prefer. (But see the Nokia-supported IDEs below.) Then compile the code with the javac compiler which is comes with a Java SE SDK (JDK). Even though you do not need to worry about it right now, your code is also preverified at this stage.

Before being able to install the MIDlet on a real device, you still need to package the MIDlet classes and resources to a JAR (Java Archive) file and generate a JAD (Java Application Descriptor) file. The JAR file contains all the code needed to run the application. The JAD file is a text file containg descriptive information about the MIDlet (size, needed APIs, MIDlet name, Vendor name, optional signing information), which the phone (and user) can use to decide whether or not to download the MIDlet at all. You need only to install the JAR file on the phone to be able to run the MIDlet; however, it is strongly recommended to use both of the files to install the application.

At this stage, you can test the MIDlet on your development workstation using the phone emulator, and then most probably make changes, then recompile and repackage it. When you are satisfied with the result, you can transfer the generated JAR and JAD files to a real phone, install the app, and test it. (You should always test a MIDlet on a real device before distributing it.)

You can also use some online resources to test your application on real devices, such Remote Device Access (RDA) or Device Anywhere.


Required hardware

Because of the requirements of Nokia's development tools, your development computer has to be a PC running Microsoft Windows 2000 (SP 4) or Microsoft Windows XP (SP 2).


Required software for S60

The combination of tools listed here (all free) has been tested by the writer (note: not yet!) to work for developing applications for S60 using Java ME. For future editors of this article: please make sure that your edits have been tested in practice, to prevent developer frustration.

tool recommended version download at notes
a Java SE (Standard Edition) Development Kit (JDK) JDK 6 Update 4 (note: Java* 6 was formerly known as J2* 1.6) download here (search for "JDK 6 Update 4") Select the Windows platform, then select the "Windows Offline Installation" option (or if you're feeling more adventurous, the "Windows Online Installation" option). Save the installation file, then run it. The installation directory is C:\Program Files\Java\jdk1.6.0_04. Do not move the installation elsewhere, because other tools look for Java installations in this directory.
the Sun Java Wireless Toolkit for CLDC 2.5.2 download here (search for "Sun Java Wireless Toolkit 2.5.2 for CLDC") The installation program should automatically detect that you have JDK 6 Update 4 installed in directory C:\Program Files\Java\jdk1.6.0_04. If not, browse for that directory at the "Java (TM) Virtual Machine Location" phase of the installation. The default installation directory is C:\WTK2.5.2; change it if you want to.
Nokia SymbianOS/S60 SDK for Java (JDK) S60 3rd edition, Feature Pack 2, MIDP SDK Beta download here
the Eclipse IDE 3.2.2 download here The default installation directory is C:\Program Files\eclipse. The writer prefers to append the version number to the installation; i.e., C:\Program Files\eclipse-3.2.2.
the EclipseME plugin for Eclipse 1.7.7 download here This is the last EclipseME version that runs on top of Eclipse v3.2. Follow the installation instructions here.
Java ME Developer's Library 2.1 download here (search for "Java ME Developer's Library v2.1 (Eclipse plug-in)") This documentation is not absolutely necessary for development, but it is very useful. After you've installed it, it is available to you from Eclipse's Help function.


Note that in addition to Eclipse, Nokia also supports the NetBeans IDE (plus its Mobility Pack) for S60/Java ME development. See here for more details.


Emulators and SDKs for Series 40 and Series 80

You should also download and test your application in other vendors' emulators, too. (Motorola, Sony Ericsson, Samsung, etc.)

As for S60 development, use a PC with Windows 2000 or Windows XP. Use the NetBeans or Eclipse IDEs.


Coding and compiling your first MIDlet

See Hello World in Java ME

Typical pitfalls

Compiling the Java ME code with wrong Java compliance option

The correct compliance is 1.3 or 1.4. Compiling with 5.0 or 6.0 compliance makes it impossible to install the MIDlet.

Compiling and packaging the MIDlet for incorrect CLDC or MIDP version

This is especially true when using Sun Wireless Toolkit, which by default builds the MIDlet for MIDP 2.1. However, most of the current phones have only MIDP 2.0 available. (Note, that you can install on a phone a MIDlet with lower CLDC/MIDP version than what the phone supports, but you cannot install a MIDlet with higher CLDC/MIDP version on the phone. Check the supported CLDC and MIDP versions on FN device specification pages.)

552 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×