Starting With J2ME in Java

Starting With J2ME
 
For the last few days I am working on J2ME. The Java Platform, Micro Edition, or Java ME, is a Java platform designed for embedded systems (mobile devices are one kind of such systems). Target devices range from industrial controls to mobile phones (especially feature phones) and set-top boxes. Java ME was formerly known as Java 2 Platform, Micro Edition (J2ME).

Just use the following to develop a simple HelloWorld app in Java. You can also install it's jar file in your Java phone.

Step 1

Our basic requirement is an Integrated Development Environment (IDE). I will use the "Netbeans IDE 7.2.1" and Java Development Kit (JDK) version 6 or 7.
 
Step 2

Create the project as in the following:

  1. Start the NetBeans IDE.
  2. In the IDE, choose File > New Project (Ctrl-Shift-N), as shown in the figure below.

J2ME-in-Java.jpg

Step 3

Choose the Java ME category and select MobileApplication and click on "Next", as in:

J2ME-in-Java1.jpg

Enter the project name as "HelloWorld". Leave the emulater platform as "CLDC Oracle Java(TM) platform microedition SDK 3.2" and click on "Finish".

Step 4

Click on the helloworld package and press CTRL-N. Select "CLDC" and then "MIDlet". The name of the MIDlet should be the same as the CLASS name.

For example, "HelloWorld".
 
Step 5
 
Each MIDlet must extend the abstract MIDlet class found in the javax.microedition.midlet package, much like creating an applet by extending the java.applet.Applet class. At the minimum, your MIDlet must override three methods of this abstract class, startApp(), pauseApp(), and destroyApp (boolean unconditional) that we will be using.

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
 
Step 6

Code in the given sections.

/**

* @author Shashank

*/

public class HelloWorld extends MIDlet {

private Form form;

private Display display;

public HelloWorld(){

super();

}

Step 7

public void startApp() {

form = new Form("Hello World");

String msg = "Hello World!!!!!!!";

form.append(msg);

display = Display.getDisplay(this);

display.setCurrent(form);

}

Step 8

public void pauseApp()

{

}

public void destroyApp(boolean unconditional) {

notifyDestroyed();

}

}

Step 9

Now run your project (F6).

Output

J2ME-in-Java2.jpg

Up Next
    Ebook Download
    View all
    Learn
    View all