Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 16:27, 17 November 2011 by marcelobarrosalmeida (Talk | contribs)

Hello World in Java ME

From Wiki
Jump to: navigation, search
Article Metadata
Platform(s): Series 40 and later Java Enabled phones
Created: tyborg (07 Jun 2007)
Last edited: marcelobarrosalmeida (17 Nov 2011)

If we want to learn a new language, the first program is always the classical "Hello World!"

This program creates a new form with a string item and an exit button.

To install the tools needed for developing in Java ME for Nokia devices, see articles Getting started with Java ME, Getting started with Java ME], and Creating your first MIDlet using EclipseME.

Code for

package com.example.helloworld;
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
public class HelloWorldMidlet extends MIDlet implements CommandListener {
public HelloWorldMidlet() {
// Display
private Display display;
// Main form
private Form form;
// For the message
private StringItem stringItem;
// For the exit command
private Command exitCommand;
public void commandAction(Command command, Displayable displayable) {
if (displayable == form) {
if (command == exitCommand) {
public void startApp() {
// Create form
stringItem = new StringItem("Hello", "Hello World!");
form = new Form(null, new Item[] {stringItem});
exitCommand = new Command("Exit", Command.EXIT, 1);
// Get display for drawning
display = Display.getDisplay(this);
// Your MIDlet should not call pauseApp(), only system will call this life-cycle method
public void pauseApp() {
// Your MIDlet should not call destroyApp(), only system will call this life-cycle method
public void destroyApp(boolean unconditional) {
public void exitMIDlet() {



256 page views in the last 30 days.