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 its 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 emulator platform as "CLDC Oracle Java(TM) platform micro edition 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.
  1. import javax.microedition.lcdui.*;  
  2. import javax.microedition.midlet.*;   
Step 6
Code in the given sections.
  1. public class HelloWorld extends MIDlet   
  2. {  
  3.  private Form form;  
  4.  private Display display;  
  5.  public HelloWorld()   
  6.  {  
  7.   super();  
  8.  }  
Step 7
  1. public void startApp()   
  2. {  
  3.  form = new Form("Hello World");  
  4.  String msg = "Hello World!!!!!!!";  
  5.  form.append(msg);  
  6.  display = Display.getDisplay(this);  
  7.  display.setCurrent(form);  
  8. }   
Step 8
  1.    public void pauseApp()  
  2.    {  
  3.    }  
  4.    public void destroyApp(boolean unconditional)   
  5.    {  
  6.       notifyDestroyed();  
  7.    }  
  8. }  
Step 9
Now run your project (F6).
 
Output
 
J2ME-in-Java2.jpg 


Similar Articles