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
NOKIA
Docsity.com
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 with roughly 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. Docsity.com 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 bytecode verification step to the vendor’s compiler.) Docsity.com MIDP Software Development MIDP applications are called MIDlets. (Because everything in Java is a somethinglet.) MIDlets are groups of classes, one of which is derrived from the abstract class javax.microedition.midlet.MIDlet. MIDlets can be packaged in MIDlet suites to group one or more MIDlets into the same space. MIDlets sharing a suite can access each other’s persistent data and are run concurrently, giving an application-level interface to multithreading. MIDlets sharing a suite are installed and uninstalled together. Classes defined in a MIDlet suite are shared between all concurrent midlets; only one instance of each class in the suite is loaded per suite. Docsity.com MIDP Software Development MIDlet packaging and installation Deploying a MIDlet requires several more steps than deploying a conventional application. JAR files and JAD files The MIDlet [suite] being deployed is packaged, along with all of 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; where the manifest is to allow installed software to be described to the user after loading, the .jad is used to describe the application to the user before it’s downloaded as part of the installation process. Docsity.com 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 Docsity.com MIDP Software Deployment Deploying MIDlets over the WWW After you’ve tested your MIDlet on your local emulator and on a locally-connected cell phone (perhaps connected over an IR port) you’ll want to ship it to the world at large. You’ll need to configure your web server to support the JAD MIME type. The JAD MIME type is text/vnd.sun.j2me.app-descriptor The user can now click on an HTML link such as Click <a href=“sample.jad”>here</a> to... This will download the JAD file. An attribute in the JAD file is the 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 Docsity.com Anatomy of a MIDlet A MIDlet consists of [at least] one class extending javax.microedition.midlet.MIDlet, plus supporting classes. You must implement three abstract methods: startApp() pauseApp() destroyApp(boolean unconditional) In startApp() you’ll create a user interface object-- a Canvas or Screen. Docsity.com Anatomy of a MIDlet “Hello World” screen class: import javax.microedition.lcdui.*; class HelloScreen extends TextBox implements CommandListener { private final HelloWorldMIDlet m_midlet; private final Command m_exitCommand; HelloScreen(HelloWorldMIDlet midlet, String string) { super("HelloWorldMIDlet", string, 256, 0); m_midlet = midlet; m_exitCommand = new Command("Exit", Command.EXIT, 1); addCommand(m_exitCommand); setCommandListener(this); } public void commandAction(Command c, Displayable d) { if (c == m_exitCommand) m_midlet.exitRequested(); } } Docsity.com Recommended Reading J2ME In A Nutshell, by Kim Topley, O’Reilly & Associates Inc., 2002 Dense yet informative; details the guts of J2ME from below CLDC on up to forms and timers. Also has a handy reference to the new J2ME Java classes. http://java.sun.com The resource of all things Java. This is where you can download the J2SDK and Wireless Toolkit. http://forum.nokia.com Good site to download phone emulators and SDKs. Non-intrusive signup process required Docsity.com