Download J2ME: Understanding Configurations, Profiles, and MIDP Development and more Slides Fundamentals of E-Commerce in PDF only on Docsity!
J2ME Java for Mobile Environments
What is J2ME? ^ J2ME :
Java 2 Micro Edition J2ME defines two
configurations
, ranges of hardware for which it can generate software:•^ CLDC :^
Connected Limited Device Configuration – CLDC devices include cell phones, PDAs, other items withroughly up to 512Kb of RAM.– CLDC devices have very limited processors; for example,CLDC devices are not required to support
double^ or^ float
types. • CDC :^ Connected Device Configuration – CDC devices fill the gap between PDAs and desktops;typical CDC devices might include Psions, smart phones,and set-top web devices. Choice of Virtual machine is up to the hardware vendor. Many CLDC device vendors use Sun’s KVM, the
Kilobyte
Virtual Machine
J2ME :
Java 2 Micro Edition
^ CLDC hardware requirements^ ^ 128 Kb permanent storage for the J2ME engine and classes^ ^ 32 Kb of RAM for applications to run in ^ MIDP hardware requirements^ ^ A screen at least 96 pixels wide and 54 pixels tall ^ Things the CLDC does
not^ require:
^ Keyboard ^ Mouse ^ Floating-point support ^ Persistent app data storage(This is supported by the MIDP profile.) ^ Multithreading or multiprocessing(This is not required of the hardware; it’s left to the JVM.)
J2ME :
Java 2 Micro Edition
^ J2SE features missing from the CLDC:^ ^ Reflection (java.lang.reflect)^ ^ Weak references (java.lang.ref)^ ^ Object finalization (java.lang.Object has no finalize() method) ^ J2SE features reduced in the CLDC:^ ^ Advanced thread handling^ ^ Advanced error handling^ ^ JNI (the Java Native Interface) ^ J2SE behavior changed in the CLDC:^ ^ A number of security restrictions^ ^ The class verification step(J2SE verifies bytecode on load. J2ME shifts the bytecodeverification step to the vendor’s compiler.)
MIDP Software Development ^ MIDlet packaging and installation^ ^ Deploying a MIDlet requires several more steps thandeploying a conventional application. ^ JAR files and JAD files^ ^ The MIDlet [suite] being deployed is packaged, along with allof its supporting classes and data files, into a JAR file.^ ^ The JAR also needs to include a
manifest^ which will detail the contents of the JAR. The JAR must be paired with a
JAD^ ( Java Application Descriptor)^
file for installation. ^ The .jad is almost identical to the JAR’s manifest.mf; wherethe manifest is to allow installed software to be described tothe user after loading, the .jad is used to describe theapplication to the user before it’s downloaded as part of theinstallation process.
MIDP Software Development ^ Sample
.jad^ or^ manifest.mf
MIDlet-1: Tetris,, TetrisMIDletMIDlet-Description: Tetris MIDlet demoMIDlet-Name: TetrisMIDlet-Vendor: MeMIDlet-Version: 1.0.0MicroEdition-Configuration: CLDC-1.0MicroEdition-Profile: MIDP-1.
MIDP Software Development ^ Compiling and deploying a MIDlet^ 1) Java compiler^ ^ javac.exe-target 1.1-bootclasspath "[Wireless toolkit path]\lib\midpapi.zip"-d preverify*.java^ 2) Preverify^ ^ preverify.exe-classpath "[Wireless toolkit path]\lib\midpapi.zip"-cldc-d postverify .\preverify^ 3) JAR builder^ ^ jar.exe cvfm Project.jar Project.jad -C postverify.^ 4) Deploy and test
MIDP Software Deployment ^ Deploying MIDlets over the WWW^ ^ After you’ve tested your MIDlet on your local emulator and ona locally-connected cell phone (perhaps connected over an IRport) you’ll want to ship it to the world at large.^ ^ You’ll need to configure your web server to support the JADMIME type. The JAD MIME type is^ text/vnd.sun.j2me.app-descriptor^ ^ The user can now click on an HTML link such as^ Click here to...^ ^ This will download the JAD file. An attribute in the JAD file isthe^ MIDlet-Jar-URL
; if the phone user chooses to continue, the phone requests this URL from the server. The JAR file is then transmitted with MIME type^ application/java-archive
Anatomy of a MIDlet ^ J2ME provides two user interface approaches:^ ^ High-level UI:
Screen The Screen class and those derrived from it provide supportfor an assisted layout of high-level objects like buttonsand text fields. This means that while it’s easier to controlwhat goes where and how events are passed and so on,it’s harder to control
precisely^ the contents of the screen. Derived classes:
Alert ,^ Form
,^ List^ and^ TextBox
^ Low-level UI:
Canvas The Canvas class gives the developer complete control overthe contents of the screen. While this has the upshot ofgiving you advanced graphical abilities and precisescreen control, it has the downside that you have to doeverything yourself. Tetris was written on a Canvas.
Anatomy of a MIDlet ^ “Hello World”, the MIDlet:^ import^ javax.microedition.midlet.;import^ javax.microedition.lcdui.;public^ class
HelloWorldMIDlet
extends^ MIDlet { public^ HelloWorldMIDlet()
{^ }
public^ void^ pauseApp()
{^ }
public^ void^ destroyApp(boolean
unconditional)^
{^ }
public^ void^ startApp(){ if^ (Display.getDisplay(this).getCurrent()
==^ null) { HelloScreen^ helloScreen
=^ new^ HelloScreen(this,
"Hello^ World.");
Display.getDisplay(this).setCurrent(helloScreen);} } void exitRequested(){ destroyApp(false);notifyDestroyed();} }
Recommended Reading ^ J2ME In A Nutshell, by Kim Topley, O’Reilly &^ Associates Inc., 2002^ ^ Dense yet informative; details the guts of J2ME from belowCLDC on up to forms and timers. Also has a handy referenceto the new J2ME Java classes. ^ http://java.sun.com^ ^ The resource of all things Java.^ ^ This is where you can download the J2SDK and WirelessToolkit. ^ http://forum.nokia.com^ ^ Good site to download phone emulators and SDKs.^ ^ Non-intrusive signup process required