intro to java me and asha platform

47
Introduc)on to Asha Pla1orm and Java ME Jussi Pohjolainen Tampere University of Applied Sciences

Upload: jussi-pohjolainen

Post on 10-May-2015

609 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Intro to Java ME and Asha Platform

Introduc)on  to  Asha  Pla1orm  and  Java  ME  Jussi  Pohjolainen  

Tampere  University  of  Applied  Sciences  

Page 2: Intro to Java ME and Asha Platform

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  

   

Page 3: Intro to Java ME and Asha Platform

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  

Page 4: Intro to Java ME and Asha Platform

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)  

Page 5: Intro to Java ME and Asha Platform

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  

Page 6: Intro to Java ME and Asha Platform

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)  

Page 7: Intro to Java ME and Asha Platform

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  

Page 8: Intro to Java ME and Asha Platform

JAVA  ME  TECHNOLOGY  

Page 9: Intro to Java ME and Asha Platform

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  

Page 10: Intro to Java ME and Asha Platform

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  

Page 11: Intro to Java ME and Asha Platform

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  

Page 12: Intro to Java ME and Asha Platform

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  

Page 13: Intro to Java ME and Asha Platform

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  

Page 14: Intro to Java ME and Asha Platform

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  

Page 15: Intro to Java ME and Asha Platform

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  

Page 16: Intro to Java ME and Asha Platform

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  

Page 17: Intro to Java ME and Asha Platform

CLDC  Func)onality  

•  Subset  of  Java  language    •  Subset  of  core  Java  SE  libraries  •  Provides  basic  input  and  output  •  Provides  basic  networking  support  •  Security  

Page 18: Intro to Java ME and Asha Platform

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  

Page 19: Intro to Java ME and Asha Platform

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  

Page 20: Intro to Java ME and Asha Platform

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  

 

Page 21: Intro to Java ME and Asha Platform

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..  

Page 22: Intro to Java ME and Asha Platform

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  

Page 23: Intro to Java ME and Asha Platform

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  

Page 24: Intro to Java ME and Asha Platform

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  

Page 25: Intro to Java ME and Asha Platform

Problems  

•  Different  screen  sizes  •  Bugs  in  phones  •  Performance  •  Fragmenta)on,  JSRs  

Page 26: Intro to Java ME and Asha Platform

MIDlet  Development  

Page 27: Intro to Java ME and Asha Platform

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  

Page 28: Intro to Java ME and Asha Platform

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 { }

}

Page 29: Intro to Java ME and Asha Platform

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  

 

Page 30: Intro to Java ME and Asha Platform

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)  

Page 31: Intro to Java ME and Asha Platform

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  

Page 32: Intro to Java ME and Asha Platform

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!

}

}

}

Page 33: Intro to Java ME and Asha Platform

MIDlet’s  Life  Cycle  

Paused  

Ac)ve  

Destroyed  

Constructor

startApp() pauseApp()

destroyApp()

Page 34: Intro to Java ME and Asha Platform

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()!

Page 35: Intro to Java ME and Asha Platform

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() {

// ..

}

}

Page 36: Intro to Java ME and Asha Platform

HOW  TO  BUILD  MIDLETS?  

Page 37: Intro to Java ME and Asha Platform

Building  Process  

1.  Compile  2.  Preverify  3.  Compress  4.  Create  JAD-­‐file  5.  Upload  to  client  

Page 38: Intro to Java ME and Asha Platform

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:  

Page 39: Intro to Java ME and Asha Platform

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!

Page 40: Intro to Java ME and Asha Platform

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!

Page 41: Intro to Java ME and Asha Platform

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!

Page 42: Intro to Java ME and Asha Platform

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.  

Page 43: Intro to Java ME and Asha Platform

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!

Page 44: Intro to Java ME and Asha Platform

Distribu)on  

Preverified  classes  

Resource  files  

Manifest  file  

jar   Jar-­‐file  

Jad-­‐file  

Mobile  Phone  

Page 45: Intro to Java ME and Asha Platform

Opening  in  Emulator  

•  You  can  start  the  emulator  from  command  line  – Nokia_Asha_SDK_1_1_em.exe -classpath "MyMidlet.jar" "MyMidlet.jad"

Page 46: Intro to Java ME and Asha Platform

Deploying  to  Phone  

•  Transfer  the  .jad  and  .jar  to  phone  using  – bluetooth  or  – mass  storage  

Page 47: Intro to Java ME and Asha Platform

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