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 returnsSun 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.
Performance considerations
Code for performance. Here are some ways to code with the aim to achieve the best
performance:
* Use local variables. It is quicker to access local variables than to access class
members.
* Avoid string concatenation. String concatenation decreases performance and can
increase the application's peak memory usage.
* Use threads and avoid synchronization. Any operation that takes more than 1/10 of a
second to run requires a separate thread. Avoiding synchronization can increase
performance as well.
* Separate the model using the model-view-controller (MVC). MVC separates the
logic from the code that controls the presentation.
Reference document: Click here
No comments:
Post a Comment