Hello World in Java ME
Article Metadata
Compatibility
Platform(s): Series 40 and later Java Enabled phones
Article
Created: tyborg
(07 Jun 2007)
Last edited: hamishwillee
(21 May 2013)
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 HelloWorldMidlet.java
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) {
exitMIDlet();
}
}
}
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);
form.addCommand(exitCommand);
form.setCommandListener(this);
// Get display for drawning
display = Display.getDisplay(this);
display.setCurrent(form);
}
// 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() {
display.setCurrent(null);
notifyDestroyed();
}
}



13 Sep
2009
Best For Beginners
When you are getting started any language, the first step is to know how to print a simple line in the output screen. And in the programming world,the first line we print generally is "Hello World". And this article shows how you can start J2ME with a starting basic midlet.This article also explains the basic methods like startApp,pauseApp,etc...
13 Sep
2009
Start from the base
Simple, with working code. Just copy&paste, but you should know a bit about programming in Java. And there's even a picture :)!
Article helps beginners to create application in Java ME. In most language programmer learn to create a program from the basic program like “Hello world” a simple print line. Using this use can understand that hoe many thing or header files are needed to run the application