Intro to Java ME and Asha Platform
-
Upload
jussi-pohjolainen -
Category
Technology
-
view
610 -
download
0
Transcript of Intro to Java ME and Asha Platform
Introduc)on to Asha Pla1orm and Java ME Jussi Pohjolainen
Tampere University of Applied Sciences
About Java ME
• Java ME (J2ME is older name..) is the world’s most widespread mobile applica1on pla3orm
• Developed by Sun Microsystems and bought by Oracle
Why?
• So why? Poten1al market reach! • It’s possible to create awesome apps with new really powerful APIs: GPS, Sensors, 3D Graphics, Touch etc..
• Hardware geQng more powerful and less expensive
Some history • Java ME (J2ME) was targeted to be cross-‐pla1orm solu)on for
mobile • Mobile opera)ng system must support Java for enabling Java
apps
• Available opera)ng systems – Symbian and it's varia)ons: S60, S90 – S40
• Symbian is now dead and S40 has evolved to Asha • Today: Java ME is available for Asha (forget about the cross-‐
pla1orm)
Asha Pla1orm
• Asha series is a range for low-‐end or feature phones produced by Nokia (and soon MS)
• First genera1on Asha phones (S40 OS) – 200 and 300 series
• Second genera1on Asha phones (Asha Pla1orm) – 500 series
Asha Pla1orm
• UI similari)es from Symbian and Meego (N9) – Swipe, fast lane..
• Phones – Asha 500, 501, 502 and 503
• Apps are wri]en in Java ME or Web apps – Powered by gecko rendering engine (Nokia Browser)
Lot of possibili)es • Here API • Gestures API • Image Scaling API • Contact API • Web Services API • Loca)on API • Mobile Sensor API • Bluetooth API • 3D Graphics API
• Internaliza)on API • File and PIM API • Mobile Media API • Messaging API • Share API • VoIP API
JAVA ME TECHNOLOGY
Java Pla1orms
• Java Standard Edi1on (Java SE) – Designed for desktop computers – Runs on top of OS X, Linux, Windows …
• Java Enterprise Edi1on (Java EE) – Mul)user, enterprise-‐wide applica)ons – Based on J2SE + several APIs for server-‐side compu)ng
• Java Micro Edi1on (Java ME) – For )ny, small and resource-‐constrained devices
Java Edi)ons
Java Virtual Machine KVM
Java EE Java SE
Java ME
CDC CLDC
MIDP Founda)on Profile
Personal Profile
Op)onal Packages
Op)onal Packages
Our course concentrates
on this
JCP and JSR
• Java Community Process, JCP, is a formalized process which creates defini1ons of future versions and features of the Java pla1orm.
• These defini)ons are called Java Specifica)on Requests, JSR
• JSR is a formal document that describes proposed specifica)on and technology
• There are lot of JSRs. – h]ps://jcp.org/ja/jsr/all
Java ME Java Me
JVM KVM
Connected Device Configura)on (CLC)
Connected Limited Device Configura)on (CLDC)
Mobile Informa)on Device Profile (MIDP) Founda)on Profile
Personal Profile
Op)onal Packages
Op)onal Packages
Kilo Virtual Machine
• KVM is similar to JVM, runs apps wri]en in Java – language
• KVM is used in cell phones, where JVM is used on computers
• Op)mized for small size • More info about KVM
– h]p://www.oracle.com/technetwork/java/javame-‐old/kvmwp-‐150240.pdf
Java ME Java Me
JVM KVM
Connected Device Configura1on (CLC)
Connected Limited Device Configura1on (CLDC)
Mobile Informa)on Device Profile (MIDP) Founda)on Profile
Personal Profile
Op)onal Packages
Op)onal Packages
Configura)ons: CLDC
• CLDC (JSR 139) – Small wireless devices with intermiRent network connec)ons
– Low power consump)on – Phones, Pagers, Bar code scanners..
• CDC (JSR 36) – Larger Devices with a robust network connec)on – Set top boxes, Internet appliances
CDC -‐ CLDC
Connected Device Configura1on (CDC)
Connected Limited Device Configura1on (CLDC)
Pagers Mobile Phones PDAs Car Naviga)on Systems Internet appliances Set-‐top Boxes
smaller larger
CLDC Func)onality
• Subset of Java language • Subset of core Java SE libraries • Provides basic input and output • Provides basic networking support • Security
CLDC Libraries
• CLDC has 37 common classes from Java SE – java.lang: Boolean, Byte, Integer, Long, String… – java.u1l: Calendar, Date, Enumera)on, Hashtable..
– java.io: InputStream, OutputStream…
• CLDC 1.0 does not have floa)ng point support • CLDC 1.1 supports floa)ng point
Java ME Java Me
JVM KVM
Connected Device Configura)on (CLC)
Connected Limited Device Configura)on (CLDC)
Mobile Informa1on Device Profile (MIDP) Founda)on Profile
Personal Profile
Op)onal Packages
Op)onal Packages
The Mobile Informa)on Device Profile (MIDP)
• Specifica)on for wireless devices • Provides general Java libraries for developing apps for wireless devices
• Versions: MIDP 1.0 (JSR 37) and MIDP 2.x (JSR 118)
• MIDP 3.0 (JSR 271) also available but not not implemented in any phones
MIDP Differences
• MIDP 1.0 – Limited graphics and sound – Only HTTP, no Sockets
• MIDP 2.X – Game API – Network and Mul)media support
• MIDP 3.0 – Background MIDlets, Improved UI, Localisa)on..
MIDP Soqware Components
Device Opera)ng System
CLDC
MIDP
Op)onal Java Packages
MIDP Java App
Op)onal Device Specific Packages
Device Specific Java App
Na)ve Applica)on
Java ME Java Me
JVM KVM
Connected Device Configura)on (CLC)
Connected Limited Device Configura)on (CLDC)
Mobile Informa)on Device Profile (MIDP) Founda)on Profile
Personal Profile
Op)onal Packages
Op1onal Packages
Op)onal Packages, JSRs • File Connec)on and PIM • Bluetooth • Wireless Messaging API (WMA) • Mobile Media API (MMAPI) • Web Services • Security and Trust Services • Loca)on API • SIP API • Mobile 3D Graphics • Java Technology for the Wireless
Industry (JTWI) • Wireless Messaging 2.0 (WMA)
• Content Handler API • SVG 1.0 • Payment API • Advanced Mul)media
Supplements (AMMS) • Mobile Interna)onaliza)on API • Java Bindings for the OpenGL ES
API • Mobile Service Architecture • Mobile Sensor API • SVG 2.0
Problems
• Different screen sizes • Bugs in phones • Performance • Fragmenta)on, JSRs
MIDlet Development
How to Build MIDlets?
• MIDlet = MIDP Applica)on • If Java SE is familiar, MIDlet development is easy
• Part of the API works exactly like Java SE • Building process is different
Example MIDlet import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class MyMidlet extends MIDlet {
public MyMidlet() { }
protected void destroyApp(boolean unconditional)
throws MIDletStateChangeException { }
protected void pauseApp() { }
protected void startApp() throws MIDletStateChangeException { }
}
Lifecycle: startApp
• startApp – method is called when MIDlet has been started (aqer constructor) – Applica1on Management SoVware (AMS) calls the method
– Aqer the method, the MIDlet is in Ac1vate state
• Method is called only once in Asha pla1orm • What to do here?
– Acquire needed resources
Lifecycle: pauseApp
• pauseApp – method is called when MIDlet is moved to paused state – In S40: when phone rings – In Asha: pauseApp is never called!
• What to do here – In S40: release any resources – In Asha: don't do anything. You must implement the method (leave it blank)
Lifecycle: destroyApp
• destroyApp – method is called when MIDlet is moved to destroyed state (app terminates) – Five seconds 1me to do cleaning
• When this method is called? – Leaving app (back-‐bu]on, swipe) – AMS – Removing memory card – Out of memory or excep)on in app
• What to do here – Release resources
boolean unconditional
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class MyMidlet extends MIDlet {
protected void destroyApp(boolean unconditional)
throws MIDletStateChangeException {
if(unconditional) {
// You must cleanup and release resources, we
// are going to exit!
} else {
// You may cancel the exit request by throwing
// a MIDletStateChangeException!
}
}
}
MIDlet’s Life Cycle
Paused
Ac)ve
Destroyed
Constructor
startApp() pauseApp()
destroyApp()
Applica)on Manager
• Applica1on Manager controls all the methods in the previous slide
• You can try to change the state by using methods like: – void notifyDestroyed()!– notifyPaused()!– resumeRequest()!
Exi)ng using no)fyDestroyed() import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class MyMidlet extends MIDlet {
protected void destroyApp(boolean unconditional)
throws MIDletStateChangeException {
cleanUpResources();
}
protected void pauseApp() { }
protected void startApp() throws MIDletStateChangeException {
cleanUpResources();
notifyDestroyed(); // destroyApp is NOT called!
}
private void cleanUpResources() {
// ..
}
}
HOW TO BUILD MIDLETS?
Building Process
1. Compile 2. Preverify 3. Compress 4. Create JAD-‐file 5. Upload to client
1. Compile
• Compile a MIDlet: – javac –classpath midp21.jar;cldc11.jar MyApp.java
• Use now base classes from Java ME! • midp classes?
– C:\Nokia\Devices\Nokia_Asha_SDK_1_1\lib • Aqer the compile, one must preverify the result:
2. Preverify • It is checked in the preverifing process that your MIDlet does
not harm the client-‐machine. • In Java SE this checking is done by JVM. KVM does not have
this kind of security checking! • Security checking is done in two parts
– Preverify before sending MIDlet to the client machine – Client machines own check
• Command line: – preverify –classpath .;\ midp\ classes –d . Midlet!
• Preverify loca1on? – C:\Nokia\Devices\Nokia_Asha_SDK_1_1\bin!
3. Compress
• Aqer the MIDlet is compiled and preverified, you must compress all the classes (and resources) into one jar-‐file.
• Jar-‐file contains also MANIFEST.MF -‐ file, which describes the contents of the jar-‐file.
• Compressing with the jar-‐tool: – jar cvmf MANIFEST.MF MIDlet.jar MIDlet.class!
Example of Manifest file MIDlet-1: MyMIDlet, MyMIDlet.png, MyMIDlet!MIDlet-Name: MyMIDlet!MIDlet-Vendor: Jussi Pohjolainen!MIDlet-Version: 1.0!MicroEdition-Configuration: CLDC-1.1!MicroEdition-Profile: MIDP-2.1!
4. Create JAD -‐ file
• Java Applica)on Descriptor file describes the contents of MIDlet.
• JAD-‐file is used so that the client machine can have informa)on about the soqware before installing it.
Example of JAD-‐file MIDlet-1: MyMidlet, MyMidlet.png, MyMidlet!MIDlet-Jar-Size: 1056 // CHECK THIS!!MIDlet-Jar-URL: MyMidlet.jar!MIDlet-Name: MyMidlet!MIDlet-Vendor: Unknown!MIDlet-Version: 1.0!MicroEdition-Configuration: CLDC-1.1!MicroEdition-Profile: MIDP-2.1!
Distribu)on
Preverified classes
Resource files
Manifest file
jar Jar-‐file
Jad-‐file
Mobile Phone
Opening in Emulator
• You can start the emulator from command line – Nokia_Asha_SDK_1_1_em.exe -classpath "MyMidlet.jar" "MyMidlet.jad"
Deploying to Phone
• Transfer the .jad and .jar to phone using – bluetooth or – mass storage
In Conclusion
• Mobile app must – extend MIDlet class which control's the lifecycle – package all files in JAR
• include MANIFEST.MF file contained in JAR file
– include a Java Applica)on Descriptor (JAD) file – have all .class preverified before deployment