[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
BeginnersGuideToJ2ME

Beginners Guide To J2ME

What is J2ME?
J2ME is a versions of Java or as Sun Microsystems puts an edition of Java that is deisgned for Mobile devices and other environments. J2ME developers use a JAVA compiler, WirelessToolKit, and a Obfuscator to preverify the classes, compile and package the classed in a JAR and JAD combination.

What Can J2ME Be Used For?
Java was orginaly started to deploy on mobile devices such as Star7 and thus J2ME returns Sun to these roots. J2ME is deployed on such mobile devices as handsets, PDAs, SmartPhones, and RIMs in the mobile sector. It also is deployed in other small resource environments such as DigitalTV/InteractiveTV(iTV/javaTV), Automobiles/Jets( ?Telemactics), and etc.

What is the Syntax Like?
J2ME is similar to Java in that it uses the same syntax with some slight modifications. Unlike general java or J2SE, J2ME is not standalone in nature and thus their is not main method but a different set of methods that form a standard midlet.

An Example of a Midlet
//must be saved as same name that JAd referrers to as .java extension
package com.shareme.moonbuzz.midp;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
    • @author Fred Grott
    • /
public abstract class MoonBuzz extends MIDlet implements CommandListener { private Command exitCommand = new Command(Resources.getString (Resources.ID_GAME_EXIT), Command.EXIT, 1); /* * Initializing local variables */ private Display display = null; private SplashMenu splash; private boolean isStarted = false; public boolean isActive = false; /** * * */ public MoonBuzz() { Cache.numItemsPerLevelRec = Cache.setItemsPerLevel(3); Cache.numItemsPerPreferencesRec = Cache.setItemsPerPrefs(3); Cache.isPrefsInitialized = RecordStores.isPrefs(1); if (Cache.isPrefsInitialized=false){ Cache.isPrefsInitialized = RecordStores.intitializePrefsRMS( Cache.shakeMe, Cache.soundMe, Cache.levelMe); Cache.isHighScoreInitialized = RecordStores.intitializeLevelRMS(Cache.zeroScore); } } /** * */ protected void startApp() throws MIDletStateChangeException { isActive = true; if (!isStarted) { if (display == null){ display = Display.getDisplay(this); } isStarted = true; } Canvas canvas = createCanvas(); Display.getDisplay(this).setCurrent(canvas); canvas.setCommandListener(this); canvas.addCommand(exitCommand); } /** * */ protected void pauseApp() { isActive = false; } /** * */ protected void destroyApp(boolean p0) throws MIDletStateChangeException { notifyDestroyed(); isActive = false; } /** * * @param dl */ public void setDisplayable(Displayable dl){ display.setCurrent(dl); } public abstract Canvas createCanvas(); public void commandAction(Command command, Displayable displayable) { if (command == exitCommand) { notifyDestroyed(); } } }


Each application in J2ME has one class that is a midlet with the methods of startApp. pauseApp, and destroyApp.

A Visual Demo
Here is a simple Pong J2ME game demo as a jav applet which you can play to see how apps work in a mobile device such as a handset.

Pong Game on c55 Siemens handset

What is Needed To Get Started?
To start coding in J2ME you need a WirelessToolKit and a java Obfuscator for J2ME. You will also need emulators/sdk for the device you are targeting. Some developers will add an IDE and J2ME Ant extensions, such as Antenna or J2ME Polish, to this list but there is a light J2ME code editor in Sun's WirelessToolKit.

Common J2ME Problems
J2ME as implemented on cell phone devices does not properly call the pauseApp method in the midlet correctly and thus you have to check if the canvas isVisible within the midlet application. J2ME is commonly deployed to devices with different screen sizes and input methods and thus you need to adjust for this in using images and code detecting user input.

J2ME Polish can be used to handle the multitude of different J2ME devices.

Further Reading
J2ME FAQ

last edited (June 22, 2004) by enough, Number of views: 18989, Current Rev: 11 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.