1. Introduc)on
to
Asha
Pla1orm
and
Java
ME
Jussi
Pohjolainen
Tampere
University
of
Applied
Sciences
2. 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
3. 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
4. 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)
5. 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
6. 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)
7. 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
9. 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
10. Java
Edi)ons
Our
course
concentrates
on
this
Op)onal
Packages
Java
EE
Java
SE
Java
ME
Personal
Profile
Op)onal
Packages
Founda)on
Profile
MIDP
CDC
CLDC
Java
Virtual
Machine
KVM
11. 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
12. Java
ME
Java
Me
Op)onal
Packages
Personal
Profile
Op)onal
Packages
Founda)on
Profile
Mobile
Informa)on
Device
Profile
(MIDP)
Connected
Device
Configura)on
(CLC)
Connected
Limited
Device
Configura)on
(CLDC)
JVM
KVM
13. 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
14. Java
ME
Java
Me
Op)onal
Packages
Personal
Profile
Op)onal
Packages
Founda)on
Profile
Mobile
Informa)on
Device
Profile
(MIDP)
Connected
Device
Configura1on
(CLC)
Connected
Limited
Device
Configura1on
(CLDC)
JVM
KVM
15. 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
16. CDC
-‐
CLDC
smaller
larger
Pagers
Mobile
Phones
PDAs
Car
Naviga)on
Systems
Internet
appliances
Set-‐top
Boxes
Connected
Limited
Device
Configura1on
(CLDC)
Connected
Device
Configura1on
(CDC)
17. CLDC
Func)onality
•
•
•
•
•
Subset
of
Java
language
Subset
of
core
Java
SE
libraries
Provides
basic
input
and
output
Provides
basic
networking
support
Security
18. 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
19. Java
ME
Java
Me
Op)onal
Packages
Personal
Profile
Op)onal
Packages
Founda)on
Profile
Mobile
Informa1on
Device
Profile
(MIDP)
Connected
Device
Configura)on
(CLC)
Connected
Limited
Device
Configura)on
(CLDC)
JVM
KVM
20. 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
21. 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..
23. Java
ME
Java
Me
Op)onal
Packages
Personal
Profile
Op1onal
Packages
Founda)on
Profile
Mobile
Informa)on
Device
Profile
(MIDP)
Connected
Device
Configura)on
(CLC)
Connected
Limited
Device
Configura)on
(CLDC)
JVM
KVM
24. 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
27. 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
28. 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 { }
}
29. 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
30. 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)
31. 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
32. 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!
}
}
}
34. 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()!
35. 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() {
// ..
}
}
38. 1.
Compile
• Compile
a
MIDlet:
– javac –classpath midp21.jar;cldc11.jar
MyApp.java
• Use
now
base
classes
from
Java
ME!
• midp
classes?
– C:NokiaDevicesNokia_Asha_SDK_1_1lib
• Aqer
the
compile,
one
must
preverify
the
result:
39. 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:NokiaDevicesNokia_Asha_SDK_1_1bin!
40. 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!
41. 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!
42. 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.
45. Opening
in
Emulator
• You
can
start
the
emulator
from
command
line
–
Nokia_Asha_SDK_1_1_e
m.exe -classpath
"MyMidlet.jar"
"MyMidlet.jad"
46. Deploying
to
Phone
• Transfer
the
.jad
and
.jar
to
phone
using
– bluetooth
or
– mass
storage
47. 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