[Link]
php/1443961
What is Java 2 Micro Edition?
By Eric Gigure
!ava i" #$ow$ primarily a" a "erver%"ide programmi$g e$viro$me$t& ce$tered arou$d the tech$ologie" that ma#e
up the !ava 2 E$terpri"e Editio$ '!2EE(& "uch a" E$terpri"e !avaBea$" 'E!B"(& "ervlet"& a$d !ava)erver page"
'!)*"(. Early adopter" o+ !ava& however& will recall that it wa" origi$ally promoted a" a clie$t%"ide applicatio$
e$viro$me$t. ,$ +act& !ava wa" origi$ally de"ig$ed a" a programmi$g la$guage +or co$"umer applia$ce". -ow
!ava i" retur$i$g to it" root" with !ava 2 .icro Editio$& or !2.E +or "hort. /hi" article& the +ir"t i$ a "erie" o$
!2.E programmi$g& e0plai$" what !2.E i".
/he !ava 2 *lat+orm
1hat we commo$ly re+er to a" 2!ava2 i" more +ormally #$ow$ a" the !ava 2 *lat+orm. /he !ava 2 *lat+orm i"
"plit i$to three editio$": !ava 2 )ta$dard Editio$ '!2)E(& !ava 2 E$terpri"e Editio$ '!2EE(& a$d !ava 2 .icro
Editio$ '!2.E(. Each editio$ o+ the plat+orm provide" a complete e$viro$me$t +or ru$$i$g !ava%3a"ed
applicatio$"& i$cludi$g the !ava virtual machi$e '4.( a$d ru$time cla""e".
/he three editio$" all target di++ere$t #i$d" o+ applicatio$" ru$$i$g o$ di++ere$t #i$d" o+ device". 5e"#top%3a"ed
applicatio$" are developed u"i$g !2)E& which provide" the $ece""ary u"er i$ter+ace cla""e". )erver%3a"ed
applicatio$" are developed u"i$g !2EE& which empha"i6e" compo$e$t%3a"ed programmi$g a$d deployme$t.
7a$dheld a$d em3edded device" are targeted 3y !2.E.
1hat "eparate" o$e editio$ +rom a$other& the$& i" primarily the "et o+ cla"" li3rarie" that each editio$ de+i$e".
8oo"ely "pea#i$g& you ca$ thi$# o+ !2.E a" a "u3"et o+ !2)E a$d !2)E a" a "u3"et o+ !2EE. ,t i" po""i3le to ru$
the "ame !ava 3ytecode i$ each editio$& providi$g the cla""e" re+erred to 3y the 3ytecode are availa3le i$ all three
editio$". /he catch& o+ cour"e& i" that !2.E%3a"ed device" have +ewer cla""e" tha$ what !2)E a$d !2EE provide&
e"pecially the "maller device". 9+ter all& there are "everal thou"a$d core !2)E ru$time cla""e"& ta#i$g up te$ to
twe$ty mega3yte" o+ "pace& which i" "imply too 3ig +or the majority o+ device" out there today a$d i$ the $ear
+uture.
/he variou" "peci+icatio$" that compri"e !2.E are all de+i$ed through the !ava :ommu$ity *roce"" '!:*(& a" i"
do$e with !2)E a$d !2EE. /oday& there are clo"e to +orty "eparate !ava )peci+icatio$ ;e<ue"t" '!);"( deali$g
with !2.E: )mall device programmi$g i" de+i$itely a hot topic withi$ the !ava commu$ity. '=or more
i$+ormatio$& "ee the mai$ !:* 1e3 "ite at [Link].(
!ava 2 .icro Editio$
,$ !2.E& the !ava ru$time e$viro$me$t i" adapted +or co$"trai$ed device" % device" that have limitatio$" o$
what they ca$ do whe$ compared to "ta$dard de"#top or "erver computer". =or low%e$d device"& the co$"trai$t"
are +airly o3viou": e0tremely limited memory& "mall "cree$ "i6e"& alter$ative i$put method"& a$d "low proce""or".
7igh%e$d device" have +ew& i+ a$y& o+ the"e co$"trai$t"& 3ut they ca$ "till 3e$e+it +rom the optimi6ed
e$viro$me$t" a$d $ew programmi$g i$ter+ace" that !2.E de+i$e".
8ear$i$g a3out !2.E i" $ot hard: >$ce you u$der"ta$d the $ew termi$ology& it?" mo"tly a3out lear$i$g $ew
9*," 'applicatio$ programmi$g i$ter+ace"( a$d lear$i$g how to wor# i$ co$"trai$ed e$viro$me$t". ',+ you thi$#
writi$g a$ applet i" challe$gi$g& wait u$til you try to +it a$ applicatio$ i$to the 3@A o+ memory "ome cellpho$e"
provideB( Cou ca$ u"e mo"t o+ the "ame tool" you already u"e i$ your code developme$t& a$d with care+ul codi$g
you ca$ develop li3rarie" o+ cla""e" that are porta3le to a$y device or computer with a !ava virtual machi$e.
*er"o$al!ava a$d Em3edded!ava
!2.E i" $ot the +ir"t attempt at adapti$g !ava +or co$"trai$ed e$viro$me$t". /wo other tech$ologie"&
*er"o$al!ava a$d Em3edded!ava& made it po""i3le to ru$ !ava 1.1.0 applicatio$" o$ high%e$d device".
*er"o$al!ava u"e" the 3a"ic !ava 1.1 ru$time cla""e" a$d throw" i$ a +ew +eature" +rom !ava 2. )upport +or "ome
o+ the ru$time cla""e" i" optio$al& 3ut a *er"o$al!ava impleme$tatio$ "till re<uire" a couple o+ o+ mega3yte" o+
memory a$d a +a"t proce""or to ru$& "o it?" $ot a practical "olutio$ +or truly co$"trai$ed device" li#e cellpho$e"
a$d ma$y per"o$al digital a""i"ta$t".
Em3edded!ava ma#e" every 3ehavior o+ 3oth the !ava 4. a$d the ru$time cla""e" optio$al % the impleme$tor
ca$ choo"e e0actly which cla""e" a$d method" are re<uired. /here i" o$e limitatio$& however: /he !ava ru$time
e$viro$me$t ca$ o$ly 3e u"ed 3y the impleme$tor a$d ca$$ot 3e e0po"ed to third partie". ,$ other word"& you
ca$ u"e it to write !ava code that ru$" i$"ide a device& u"ually a" part o+ the "o+tware to co$trol the device& 3ut $o
o$e el"e ca$ write applicatio$" +or the device. /hi" i" do$e to pre"erve the 2write o$ce& ru$ a$ywhere2 $ature o+
!ava& "i$ce a$ Em3edded!ava e$viro$me$t ca$ do away with +u$dame$tal thi$g" li#e ru$time cla"" veri+icatio$
a$d cha$ge the pu3lic i$ter+ace" o+ core cla""e". Em3edded!ava i" really a way to 3uild a 2private2 !ava ru$time
e$viro$me$t.
Both *er"o$al!ava a$d Em3edded!ava are 3ei$g pha"ed out. /here i" a migratio$ path +rom *er"o$al!ava to
!2.E& a" we?ll "ee later i$ thi" "erie"& though the curre$t ver"io$ o+ *er"o$al!ava co$ti$ue" to 3e "upported.
Em3edded!ava i" $o lo$ger "upported 3ecau"e !2.E de+i$e" "uita3le "mall%+ootpri$t ru$time e$viro$me$t".
What's Next
,$ the $e0t article& we?ll e0ami$e the core co$cept" o+ !2.E % co$+iguratio$"& pro+ile"& a$d optio$al pac#age" %
a$d "ome other term" li#e A4. a$d :4.. Cou ca$?t write a !2.E applicatio$ without #$owi$g which
co$+iguratio$ a$d pro+ile you?re targeti$g& or #$owi$g which optio$al pac#age" are re<uired& "o it?" importa$t to
u$der"ta$d the termi$ology 3e+ore you attempt your +ir"t applicatio$.
,+ you ca$?t wait to get "tarted with !2.E& dow$load )u$?" !2.E 1irele"" /ool#it a$d read through "ome o+ the
e0te$"ive !2.E docume$tatio$ o$ the )u$ 1e3 "ite.
J2ME Core Concepts
9t the heart o+ !ava 2 .icro Editio$ '!2.E( are three core co$cept": co$+iguratio$"& pro+ile"& a$d optio$al
pac#age". Cou ca$?t write a !2.E applicatio$ without u$der"ta$di$g the"e co$cept"& 3ecau"e they determi$e the
+eature" o+ !ava that you ca$ u"e& which applicatio$ programmi$g i$ter+ace" '9*,"( are availa3le& a$d how your
applicatio$" are pac#aged.
:o$+iguratio$"
9 co$+iguratio$ i" a complete !ava ru$time e$viro$me$t& co$"i"ti$g o+ three thi$g":
D 9 !ava virtual machi$e '4.( to e0ecute !ava 3ytecode.
D -ative code to i$ter+ace to the u$derlyi$g "y"tem.
D 9 "et o+ core !ava ru$time cla""e".
/o u"e a co$+iguratio$& a device mu"t meet certai$ mi$imum re<uireme$t" a" de+i$ed i$ the co$+iguratio$?"
+ormal "peci+icatio$. 9lthough a co$+iguratio$ doe" provide a complete !ava e$viro$me$t& the "et o+ core cla""e"
i" $ormally <uite "mall a$d mu"t 3e e$ha$ced with additio$al cla""e" "upplied 3y !2.E pro+ile" or 3y
co$+iguratio$ impleme$tor. ,$ particular& co$+iguratio$" do $ot de+i$e a$y u"er i$ter+ace cla""e".
!2.E de+i$e" two co$+iguratio$"& the :o$$ected 8imited 5evice :o$+iguratio$ ':85:( a$d the :o$$ected
5evice :o$+iguratio$ ':5:(. /he :85: i" +or very co$"trai$ed 'limited( device" %% device" with "mall amou$t"
o+ memory a$d/or "low proce""or". /he 4. u"ed 3y the :85: omit" importa$t +eature" li#e +i$ali6atio$& while
the "et o+ core ru$time cla""e" i" a ti$y +ractio$ o+ the !2)E core cla""e"& ju"t the 3a"ic" +rom the [Link]$g&
[Link] a$d [Link] pac#age"& with a +ew additio$al cla""e" +rom the $ew [Link]$.io pac#age. /he
:5:& o$ the other ha$d& i$clude" a +ull !ava 4. a$d a much larger "et o+ core cla""e"& "o it re<uire" more
memory tha$ the :85: a$d a +a"ter proce""or. /he :5: i" i$ +act a "uper"et o+ the :85:. 1e?ll di"cu"" the
co$+iguratio$" i$ detail i$ the $e0t two article" i$ thi" "erie".
*ro+ile"
9 pro+ile add" domai$%"peci+ic cla""e" to a co$+iguratio$ to +ill i$ mi""i$g +u$ctio$ality a$d to "upport "peci+ic
u"e" o+ a device. =or e0ample& mo"t pro+ile" de+i$e u"er i$ter+ace cla""e" +or 3uildi$g i$teractive applicatio$".
/o u"e a pro+ile& the device mu"t meet all the mi$imum re<uireme$t" o+ the u$derlyi$g co$+iguratio$ a" well a"
a$y additio$al re<uireme$t" ma$dated 3y the pro+ile?" +ormal "peci+icatio$.
/here are "everal pro+ile" i$ variou" "tage" o+ developme$t. /he +ir"t pro+ile to 3e relea"ed wa" the .o3ile
,$+ormatio$ 5evice *ro+ile '.,5*(& a :85:%3a"ed pro+ile +or ru$$i$g applicatio$" o$ cellpho$e" a$d
i$teractive pager" with "mall "cree$"& wirele"" 7//* co$$ectivity& a$d limited memory. 9$other :85:%3a"ed
pro+ile u$der developme$t i" the *er"o$al 5igital 9""i"ta$t *ro+ile '*59*(& which e0te$d" .,5* with additio$al
cla""e" a$d +eature" +or more power+ul ha$dheld device". ,$ term" o+ :5:%3a"ed pro+ile"& the =ou$datio$ *ro+ile
'=*( e0te$d" the :5: with additio$al !2)E cla""e"& the *er"o$al Ba"i" *ro+ile '*B*( e0te$d" the =* with
lightweight '91/%derived( u"er i$ter+ace cla""e" a$d a $ew applicatio$ model& a$d the *er"o$al *ro+ile e0te$d"
the *B* with applet "upport a$d heavyweight E, cla""e". 1e?ll al"o 3e di"cu""i$g the"e pro+ile" later o$ i$ thi"
"erie".
Optional Packages
9$ optio$al pac#age i" a "et o+ 9*," i$ "upport o+ additio$al& commo$ 3ehavior" that do$?t really 3elo$g i$ o$e
"peci+ic co$+iguratio$ or pro+ile. Bluetooth "upport& +or e0ample& i" de+i$ed a" a$ optio$al pac#age. .a#i$g it
part o+ a pro+ile would$?t wor#& 3ecau"e $o$e o+ the 3ehavior" o+ a pro+ile ca$ 3e optio$al %% i+ a device "upport"
a pro+ile& it mu"t "upport the e$tire pro+ile %% a$d that would limit the pro+ile to Bluetooth%e$a3led device".
>ptio$al pac#age" have their ow$ mi$imum re<uireme$t"& o+ cour"e& ju"t li#e co$+iguratio$" a$d pro+ile".
>ptio$al pac#age" al"o have "peci+ic depe$de$cie" o$ a particular co$+iguratio$ a$d/or o$e or more pro+ile" %%
they do $ot de+i$e a complete ru$time e$viro$me$t& ju"t "et" o+ related 9*,".
/here are ma$y optio$al pac#age" i$ developme$t& i$cludi$g the ;., >ptio$al *ac#age& which add" ;.,
"upport to :5:/=*%3a"ed pro+ile"& the !ava 9*," +or Bluetooth& which add" Bluetooth "upport to :85:%3a"ed
pro+ile"& a$d the !5B: >ptio$al *ac#age +or :5:/=ou$datio$ *ro+ile& which de+i$e" a "u3"et o+ !5B: 'data3a"e
acce"" 9*,"( +or u"e with :5:/=*%3a"ed pro+ile". 9gai$& we?ll 3e coveri$g the"e later o$ i$ the "erie" a" the $eed
ari"e".
The KVM and CVM
/wo other term" you?ll "ee me$tio$ed i$ !2.E literature are A4. a$d :4.. /he"e are the $ame" o+ !ava
virtual machi$e" +or the :85: 'A4.( a$d the :5: ':4.(& writte$ "peci+ically to wor# i$ the co$"trai$ed
e$viro$me$t o+ a ha$dheld or em3edded device a$d to 3e ea"ily ported to di++ere$t plat+orm". ,t "hould 3e $oted&
however& that the :85: a$d :5: "peci+icatio$" do $ot re<uire the u"e o+ the A4. or the :4.& o$ly the u"e o+
a 4. that adhere" to the re<uireme$t" o+ the "peci+icatio$ i$ <ue"tio$. 1hile ma$y device ma$u+acturer" lice$"e
the A4. or :4. +rom )u$ .icro"y"tem" to "erve a" the core o+ their !2.E impleme$tatio$& they are $ot
re<uired +or !2.E complia$ce. ,t i" a mi"ta#e& there+ore& to co$"ider the :85: a$d A4. a" "y$o$ymou"& a$d
"imilarly +or the :5: a$d the :4..
What It All Means
,t "hould $ow 3e appare$t that 2!2.E applicatio$2 i" a$ am3iguou" term. =or what pro+ile i" the applicatio$
i$te$dedF 1hich optio$al pac#age" doe" it re<uireF 7ow much memory doe" it ta#eF /he"e are the <ue"tio$"
you mu"t a"# your"el+ 3e+ore you "tart applicatio$ developme$t& 3ecau"e they determi$e which la$guage +eature"
a$d which cla""e" your applicatio$ ca$ u"e. ,+ you limit your applicatio$ to :5:%3a"ed pro+ile"& +or e0ample&
you ma#e developme$t "impler o+ the ma$y +amiliar !2)E 9*,"& 3ut you cut out the low%e$d device" +rom your
pote$tial i$"tall 3a"e. /argeti$g :85:%3a"ed pro+ile"& o$ the other ha$d& ma#e" your developme$t ta"# harder&
e"pecially whe$ tryi$g to "hri$# the "i6e o+ your applicatio$ to ru$ o$ a" ma$y o+ the "maller device" a" po""i3le.
/he"e are the #i$d" o+ tradeo++" you?ll have to ma#e a" you 3egi$ to wor# with !2.E. /he i$+ormatio$ i$ thi"
"erie" will help you decide what?" really importa$t.
The Connected Limited Device Configuration (CLDC
9t the core o+ !ava 2 .icro Editio$ '!2.E( are the co$+iguratio$"& the "peci+icatio$" that de+i$e the mi$imal
+eature "et o+ a complete !ava ru$time e$viro$me$t. !2.E curre$tly de+i$e" two co$+iguratio$". ,$ thi" article
we loo# at the +ir"t o+ the"e& the :o$$ected 8imited 5evice :o$+iguratio$& or :85: +or "hort.
/he :85: )peci+icatio$
8i#e all !2.E tech$ology& the :85: i" de+i$ed 3y a "peci+icatio$ that ha" pa""ed through the !ava :ommu$ity
*roce"" '!:*(. 9t thi" time& there are two ver"io$" o+ the :85:. 4er"io$ 1.@& relea"ed i$ .ay o+ 2@@@& i" #$ow$
a" !ava )peci+icatio$ ;e<ue"t '!);( 3@. 4er"io$ 1.1& curre$tly i$ pu3lic review& i" !); 139. Becau"e ver"io$ 1.@
i" the o$e that i" curre$tly "hippi$g i$ device"& we?ll co$ce$trate o$ it.
/he :85: "peci+icatio$ de+i$e" three thi$g":
1. /he capa3ilitie" o+ the !ava virtual machi$e '4.(& which i" $ot a +ull%+eatured !ava 4..
2. 9 very "mall "u3"et o+ the !2)E 1.3 cla""e".
3. 9 $ew "et o+ 9*," 'applicatio$ programmi$g i$ter+ace"( +or i$put/output called the Ge$eric :o$$ectio$
=ramewor#.
,t?" al"o importa$t to u$der"ta$d what the :85: doe" $ot de+i$e. /he :85: doe" $ot de+i$e a$y 9*," related to
u"er i$ter+ace". /he :85: doe" $ot de+i$e how applicatio$" are loaded o$to a device or how they are activated
or deactivated. /he"e a$d other thi$g" are de+i$ed 3y the !2.E pro+ile" that u"e the :85: a" their 3a"e. )o
while it?" true that the :85: doe" de+i$e a complete !ava ru$time e$viro$me$t& the additio$al 9*," de+i$ed 3y a
pro+ile or "upplied 3y the ve$dor are really $ece""ary to 3uild u"e+ul applicatio$".
The !irtua" Machine
/he !ava 4. u"ed i$ the :85: i" re"tricted i$ certai$ importa$t way" whe$ compared to a +ull%+eatured !2)E
4.. /he"e re"trictio$" allow the 4. to +it the memory a$d power co$"trai$t" o+ the "mall device" that the
:85: target: the :85: 4. a$d cla""e" ca$ +it i$ 12GA o+ memory.
/he primary re"trictio$" o$ the 4. are:
D -o +loati$g poi$t type".
D -o o3ject +i$ali6atio$ or wea# re+ere$ce".
D -o !-, or re+lectio$ 'he$ce $o o3ject "eriali6atio$(.
D -o thread group" or daemo$ thread" '$ote that thread" are "upported& ju"t $ot thread group"(.
D -o applicatio$%de+i$ed cla"" loader".
-ote that :85: 1.1 rela0e" "ome o+ the"e re"trictio$"& i$ particular ree$a3li$g "upport +or +loati$g poi$t type"
a$d wea# re+ere$ce".
,$ additio$ to the a3ove re"trictio$"& the :85: al"o re<uire" cla"" veri+icatio$ to 3e do$e di++ere$tly. :la"" +ile"
are proce""ed 3y a$ o++%device cla"" veri+ier& a proce"" called preveri+icatio$. 9t ru$time& the 4. u"e"
i$+ormatio$ i$"erted i$to the cla"" +ile" 3y the preveri+ier to per+orm the +i$al veri+icatio$ "tep". =ile" that have
$ot 3ee$ proce""ed 3y the preveri+ier are $ot loaded "i$ce they ca$$ot 3e veri+ied.
/he !2)E )u3"et
/he "u3"et o+ !2)E 1.3 i$cluded i$ the :85: co$"i"t" o+ cla""e" +rom the"e three pac#age":
D [Link]$g
D [Link]
D [Link]
>$ly "elected cla""e" +rom each pac#age are i$cluded: +or e0ample& the [Link].4ector a$d [Link].7a"hta3le
cla""e" are i$cluded& 3ut $o$e o+ the collectio$ cla""e" are. /he large"t pac#age i" the [Link]$g pac#age& which
de+i$e" the cla""e" that are +u$dame$tal to a$y java applicatio$& cla""e" li#e [Link]$g.>3ject or [Link]$g.,$teger.
/he [Link] "u3"et o$ly i$clude" a3"tract a$d memory%3a"ed cla""e" a$d i$ter+ace" li#e [Link].5ata,$put or
[Link].Byte9rray,$put)tream. /he [Link] "u3"et o$ly i$clude" a +ew utility cla""e".
)ome o+ the cla""e" are "u3"et" o+ their !2)E e<uivale$t". :o$+iguratio$" are allowed to remove u$$ece""ary
method" or +ield"& 3ut they ca$$ot add $ew pu3lic or protected method" or +ield".
The #eneric Connection $rame%or&
!2)E i$clude" ma$y cla""e" +or per+ormi$g i$put a$d output& cla""e" that are +ou$d i$ the [Link] a$d the java.$et
pac#age". E$+ortu$ately& there are a large $um3er o+ ,/> cla""e" a$d they te$d to e$cap"ulate ,/> model" that are
$ot $ece""arily +ou$d o$ all device". =or e0ample& "ome ha$dheld device" do $ot have +ile "y"tem". )oc#et
"upport i" $ot u$iver"al& either.
1hat the :85: ha" do$e& the$& i" to de+i$e a $ew "et o+ 9*," +or ,/> called the Ge$eric :o$$ectio$ =ramewor#.
/he G=:& part o+ the $ew [Link]$.io pac#age& de+i$e" i$ter+ace" +or the di++ere$t #i$d" o+ ,/> that are
po""i3le a$d a +actory cla"" +or creati$g o3ject" that impleme$t tho"e i$ter+ace". /he type o+ o3ject to create i"
"peci+ied i$ the protocol part o+ the E;8 'u$iver"al re"ource locator( pa""ed to the +actory cla"".
=or e0ample& a "oc#et co$$ectio$ ca$ 3e made u"i$g code li#e thi":
import [Link].*;
import [Link].*;
StreamConnection conn = null;
InputStream is = null;
String url = "socket://[Link]:!"#"";
tr$ %
conn = &StreamConnection' [Link]& url ';
is = [Link]&';
.... // etc. etc.
(
catc& Connection)ot*ound+xception cn,e '%
// andle it
(
catc& I-+xception e '%
// andle it
(
,inall$ %
i,& is .= null ' tr$ % [Link]&'; ( catc& +xception e '%(
i,& conn .= null ' tr$ % [Link]&'; ( catc& +xception e '%(
(
/he code a3ove a""ume" that the device #$ow" how to map the 2"oc#et2 protocol i$ the E;8 to a$ o3ject that
impleme$t" the G:=?" )tream:o$$ectio$ i$ter+ace& which de+i$e" method" +or o3tai$i$g the i$put a$d output
"tream" o+ a "oc#et co$$ectio$. ,t "hould 3e $oted& however& that the :85: doe" $ot actually de+i$e a$y ,/>
impleme$tatio$". ,$ other word"& the :85: de+i$e" the i$ter+ace" o+ the G:=& 3ut the impleme$tatio$ cla""e" %%
the o$e" that do the actual ,/> %% are le+t to the pro+ile" a$d/or the device ve$dor to de+i$e. =or e0ample& the
.o3ile ,$+ormatio$ 5evice *ro+ile '.,5*( %% a :85:%3a"ed pro+ile %% re<uire" "upport +or a "u3"et o+ 7//* 1.1
a$d "o it recog$i6e" the 2http2 protocol i$ E;8" a$d retur$" o3ject" that impleme$t the G:=?"
:o$te$t:o$$ectio$ i$ter+ace.
E"i$g the :85:
By it"el+& the :85: i" a limited programmi$g plat+orm. Becau"e it doe" $ot de+i$e a$y u"er i$ter+ace cla""e" or
impleme$t a$y ,/> model"& a3out all you ca$ do +or output i" write to the )y"[Link] "tream& which may or may
$ot 3e captured to a co$"ole or +ile. Cou really $eed the e0tra cla""e" de+i$ed 3y a !2.E pro+ile 'li#e tho"e o+ the
.,5*( or device%"peci+ic cla""e" 'li#e tho"e o$ the ;,. Blac#Berry device" or certai$ !apa$e"e i%.ode pho$e"(
to do a$ythi$g i$teractive.
,+ you?re "till i$tere"ted i$ tryi$g out the :85:& )u$ ha" a re+ere$ce impleme$tatio$ ho"ted o$ 1i$dow" or
)olari" availa3le +or dow$load +rom it" we3"ite. /hi" re+ere$ce impleme$tatio$ i$clude" the preveri+y o++li$e
veri+icatio$ utility a" well a" a :85: 4. a$d the :85: ru$time cla""e". )ee )u$?" mai$ :85: page +or li$#"
to it a$d to the :85: "peci+icatio$. Cou ca$ al"o u"e tool#it" or i$tegrated developme$t e$viro$me$t" li#e )u$?"
!2.E 1irele"" /ool#it& .etrower#"? :ode1arrior 1irele"" )tudio& or Borla$d?" !Builder .o3ile)et to e0plore
:85: programmi$g.
'nderstanding The Connected Device Configuration (CDC
/he "eco$d co$+iguratio$ at the core o+ !ava 2 .icro Editio$ '!2.E( i" the :o$$ected 5evice :o$+iguratio$& or
:5: +or "hort./he :5: i" a "uper"et o+ the :o$$ected 8imited 5evice :o$+iguratio$ ':85:(. ,t provide" a
much more co$ve$tio$al !ava 2 ru$time e$viro$me$t.
The CDC (pecification
8i#e the :85: '"ee my previou" article& /he :o$$ected 8imited 5evice :o$+iguratio$ ':85:((& the :5: i"
de+i$ed 3y a "peci+icatio$ that ha" pa""ed through the !ava :ommu$ity *roce"" '!:*(. /he :5:& #$ow$ a" !ava
)peci+icatio$ ;e<ue"t '!);( 36& wa" relea"ed i$ .arch 2@@2.
/he :5: "peci+icatio$ i" a much "maller docume$t tha$ the :85: "peci+icatio$ 3ecau"e the :5: i" much
clo"er to a !ava 2 )ta$dard Editio$ '!2)E( ru$time e$viro$me$t tha$ the :85:. /he :5: "peci+icatio$ de+i$e"
+our thi$g" i$ particular:
1. /he capa3ilitie" o+ the !ava virtual machi$e '4.(. E$li#e the :85:& the :5: 4. i" a +ull%+eatured 4..
2. 9 "u3"et& much larger tha$ the :85:?"& o+ the !2)E 1.3 cla""e".
3. /he "ame 9*," 'applicatio$ programmi$g i$ter+ace"( that are $ew to the :85: %% i$ other word"& the
Ge$eric :o$$ectio$ =ramewor# 'G:=(.
4. )upport +or +ile% a$d datagram%3a"ed i$put/output u"i$g 3oth the G:= a$d the +amiliar [Link] a$d java.$et
cla""e".
-ote that& ju"t li#e the :85:& the :5: doe" $ot de+i$e a$y u"er i$ter+ace cla""e" or how applicatio$" are loaded
a$d activated: the"e are le+t +or the pro+ile" to de+i$e.
/he 4irtual .achi$e
/he :5: "upport" a complete& +ull%+eatured !ava 2 virtual machi$e '4.( a" de+i$ed i$ /he !ava 4irtual .achi$e
)peci+icatio$. /he low%level i$ter+ace" +or calli$g $ative code& co$$ecti$g to de3ugger"& a$d pro+ili$g code are
optio$al& 3ut i+ "upported they mu"t 3e the "ta$dard i$ter+ace" %% !ava -ative ,$ter+ace '!-,(& !ava 4irtual
.achi$e 5e3uggi$g ,$ter+ace '!4.5,(& a$d !ava 4irtual .achi$e *ro+ili$g ,$ter+ace '!.4*,( %% u"ed i$ !ava
1.3.
-ote that the :5: doe" $ot re<uire preveri+icatio$ o+ cla""e"& a" +ull cla"" veri+icatio$ i" do$e o$ the device 3y
the 4.. :la""e" that have 3ee$ preveri+ied ca$ al"o 3e u"ed& o+ cour"e& "i$ce the additio$al i$+ormatio$ added to
the cla"" +ile" 3y the preveri+ier i" ig$ored.
Becau"e the 4. i" +ull%+eatured& a$d there are more cla""e"& the mi$imum memory +ootpri$t +or the :5: i"
larger tha$ the :85:?": the device $eed" at lea"t H12A +or the ru$time e$viro$me$t& plu" at lea"t 2H6A to hold
a$d ru$ applicatio$".
/he !2)E )u3"et
/he "u3"et o+ !2)E 1.3 i$cluded i$ the :5: co$"i"t" o+ cla""e" +rom the"e pac#age":
D [Link]
D [Link]$g
D [Link]$[Link]+
D [Link]$[Link]
D java.$et
D java."ecurity
D java."[Link]
D java.te0t
D [Link]
D [Link]
D [Link].6ip
9" you ca$ "ee& the :5: i$clude" ma$y more pac#age" tha$ the :85:& a$d ma$y more cla""e" eve$ i$ the
"hared pac#age". =or e0ample& the :5: i$clude" the collectio$" cla""e" +rom the [Link] pac#age& while the
:85: doe" $ot. /hi" ma#e" the :5: a much more !2)E%li#e e$viro$me$t tha$ the :85:. /here are "till
cla""e" mi""i$g& o+ cour"e. =or e0ample& the java.$et pac#age a" de+i$ed 3y the :5: o$ly i$clude" the cla""e"
related to datagram "oc#et"& $ot "tream "oc#et".
The #eneric Connection $rame%or&
)i$ce the :5: i" a "uper"et o+ the :85:& it i$clude" the Ge$eric :o$$ectio$ =ramewor# 'G:=(. E$li#e the
:85:& however& the :5: al"o re<uire" G:= "upport +or two "peci+ic co$$ectio$ type": +ile" a$d datagram".
/hi" ma#e" "e$"e 3ecau"e the :5: i$clude" the +ile cla""e" +rom the [Link] pac#age a$d the datagram cla""e"
+rom the java.$et pac#age. ,t i" there+ore "traight+orward +or the device ma$u+acturer to write G:=
impleme$tatio$ cla""e" that "imply map G:= re<ue"t" 'u"i$g the +ile or datagram protocol at the "tart o+ a E;8(
i$to their [Link] a$d java.$et e<uivale$t".
=ile a$d 5atagram )upport
7ere i" a$ e0ample o+ ope$i$g a +ile +or writi$g u"i$g the G:=:
import [Link]
import [Link]$.[Link]
try J
)tri$g url K 2+ile:/log"/mylog.t0t2I
>utput:o$$ectio$ co$$ K
'>utput:o$$ectio$( :o$$[Link]$' url&
:o$$ector.1;,/E (I
>utput)tream out K co$$.ope$>utput)tream'(I
..... // write to the output "tream
[Link]"e'(I
co$$.clo"e'(I
L
catch' ,>E0ceptio$ e (J
// ha$dle error
L
5atagram "upport i" a 3it more comple0& 3ut <uite "imilar.
1hy $ot ju"t u"e the [Link] a$d java.$et cla""e" directlyF /he G:= provide" a co$"i"te$t ,/> model that wor#"
acro"" all !2.E plat+orm" that "upport the re<uired protocol". ,+ you do$?t $eed i$teropera3ility with !2)E& u"e
the G:= whe$ever po""i3le to ope$ your ,/> co$$ectio$".
'sing the CDC
8i#e the :85:& the :5: i" 3y it"el+ a limited programmi$g plat+orm. 9gai$& 3ecau"e it doe" $ot de+i$e a$y u"er
i$ter+ace cla""e" or impleme$t a$y ,/> model"& a3out all you ca$ do +or output i" write to the )y"[Link] "tream&
which may or may $ot 3e captured to a co$"ole or +ile. /he e0tra cla""e" de+i$ed 3y o$e or more !2.E pro+ile"
are really re<uired to write i$teractive applicatio$".
)u$ ha" a re+ere$ce impleme$tatio$ o+ the :5: ho"ted o$ 8i$u0 availa3le +or dow$load +rom it" we3"ite. )ee
)u$?" mai$ :5: page +or li$#" to it a$d to the :5: "peci+icatio$.
The )mportance of the Mo*i"e )nformation Device +rofi"e (M)D+
By Eric Gigure
9lthough co$+iguratio$" are at the heart o+ !ava 2 .icro Editio$ '!2.E(& it?" the pro+ile" that are o+ real i$tere"t.
*ro+ile" de+i$e the applicatio$ programmi$g i$ter+ace" '9*,"( that are re<uired to write u"e+ul applicatio$" +or a
particular group or +amily o+ !2.E device". /he .o3ile ,$+ormatio$ 5evice *ro+ile '.,5*( de+i$e" a !ava
ru$time e$viro$me$t +or cellpho$e"& i$teractive pager"& a$d "imilar ma""%produced& re"ource%co$"trai$ed
ha$dheld device".
.o3ile ,$+ormatio$ 5evice"
.,5* i" targeted at a cla"" o+ device" #$ow$ a" mo3ile i$+ormatio$ device" '.,5"(. /he"e are device" that have
the +ollowi$g mi$imal characteri"tic":
D E$ough memory to ru$ .,5* applicatio$" '"ee 3elow(
D 9 3it addre""a3le di"play at lea"t 96 pi0el" wide 3y H6 pi0el" high& either mo$ochrome or color.
D 9 #eypad& #ey3oard& or touch "cree$.
D /wo%way wirele"" $etwor#i$g capa3ility.
9lmo"t a$y wirele"" device 3uilt the"e day" +it" the de+i$itio$ o+ a .,5& i$cludi$g low%e$d cellpho$e". *er"o$al
digital a""i"ta$t" '*59"( ca$ al"o 3e co$"idered to 3e .,5" 3ecau"e wirele"" $etwor#i$g i" $ow a$ optio$ +or
mo"t *59"& 3ut .,5* doe"$?t target the"e device" "peci+ically: *59" have more memory& larger "cree$"& a$d
i$tere"ti$g i$+ormatio$ ma$ageme$t capa3ilitie" that are more e++ectively e0ploited u"i$g other pro+ile".
/he .,5* )peci+icatio$
/here are two ver"io$" o+ the .o3ile ,$+ormatio$ 5evice *ro+ile& 3oth de+i$ed u"i$g the !ava :ommu$ity
*roce"" '!:*(. .,5* 1.@& #$ow$ a" !ava )peci+icatio$ ;e<ue"t '!);( 3M& wa" relea"ed i$ )eptem3er 2@@@.
.,5* 2.@& !); 11G& i" curre$tly i$ propo"ed +i$al dra+t +orm& the +i$al "tep 3e+ore +ormal relea"e a" a +i$al
"peci+icatio$. -o device" yet "upport .,5* 2.@& 3ut there are ma$y device" curre$tly o$ the mar#et that "upport
.,5* 1.@. 1e?ll co$ce$trate "olely o$ .,5* 1.@ +or $ow& de+erri$g di"cu""io$ o+ .,5* 2.@ u$til later i$ thi"
"erie".
/he .,5* 1.@ "peci+icatio$ wa" de+i$ed 3y a$ e0pert group co$"i"ti$g o+ all the major player" i$ the wirele""
a$d ha$dheld device are$a& i$cludi$g +amiliar $ame" li#e .otorola& -o#ia& Eric""o$& ;e"earch i$ .otio$& a$d
)ym3ia$. ,t ha" a lot o+ "upport i$ the telecommu$icatio$" i$du"try& a$d ha$d"et ma$u+acturer" li#e .otorola
a$d -o#ia i$ particular are devoti$g a lot o+ developme$t e++ort to "upporti$g .,5* i$ a wide ra$ge o+ their
device".
/he co$+iguratio$ u"ed 3y .,5* i" the :o$$ected 8imited 5evice :o$+iguratio$ ':85:(& which we?ve already
di"cu""ed i$ a previou" article i$ thi" "erie". /he :85: ha" the "mall +ootpri$t re<uired to ru$ o$ low%e$d
device". 5evice" that are capa3le o+ ru$$i$g the other co$+iguratio$& the :o$$ected 5evice :o$+iguratio$
':5:(& ca$ al"o ru$ .,5*& o+ cour"e& "i$ce the :5: i" a "uper"et o+ the :85:.
/he .,5* add" 9*," i$ a $um3er o+ area" to the very 3a"ic 9*," de+i$ed 3y the :85:. /he $ew +eature"
i$clude:
D )upport +or applicatio$ li+ecycle ma$ageme$t "imilar to the way applet" are de+i$ed i$ !ava 2 )ta$dard
Editio$.
D *er"i"te$t "torage o+ data.
D 7//*%3a"ed $etwor# co$$ectivity 3a"ed o$ the :85:?" Ge$eric :o$$ectio$ =ramewor#.
D )imple u"er i$ter+ace "upport& with e$ough +le0i3ility to 3uild game" or 3u"i$e"" applicatio$".
/he .,5* "peci+icatio$ i" "ile$t a3out a $um3er o+ thi$g"& however. =or e0ample& i$ .,5* 1.@ there i" $o
"ta$dard way to i$ter+ace to the device?" pho$e3oo#& i+ it ha" o$e& i$ order to i$itiate voice call". /here are $o
"ta$dard +acilitie" +or data "y$chro$i6atio$& eve$ i+ the device "upport" the +eature. 5evice ma$u+acturer" ca$
a$d do provide their ow$ device%"peci+ic 9*," +or the"e #i$d" o+ +eature"& though& 3ut u"i$g them limit" your
applicatio$?" porta3ility.
-ote that the .,5* "peci+icatio$ i" particularly "ile$t i$ o$e area: how .,5* applicatio$" are loaded o$to a
device a$d how they are activated or deactivated. 9" "uch& di++ere$t device" will do the"e i$ di++ere$t way". /he
.,5* "peci+icatio$ 3a"ically co$cer$" it"el+ with what the applicatio$ doe" o$ce it?" ru$$i$g& $ot how it?"
activated.
.,5let" a$d .,5let )uite"
9" me$tio$ed& .,5* de+i$e" a$ applicatio$ li+ecycle model "imilar to the applet model. ,$ +act& .,5* doe" $ot
"upport the ru$$i$g o+ traditio$al applicatio$" that u"e a "tatic mai$ method a" their e$try poi$t. -or ca$ .,5*
applicatio$" call the )y"tem.e0it method i$ order to termi$ate. .,5* applicatio$" mu"t +ollow "peci+ic
pac#agi$g rule".
9 .,5* applicatio$ i" re+erred to a" a .,5let. ,t" e$try poi$t i" a cla"" that e0te$d" the
[Link]$.midlet..,5let cla""& much i$ the "ame way that a$ applet e0te$d" the [Link].9pplet
cla"". /hi" cla"" i" re+erred to a" the .,5let?" mai$ cla"". /he .,5let cla"" de+i$e" a3"tract method" that the
mai$ cla"" impleme$t": the"e method" are called 3y the "y"tem to $oti+y the .,5let that it" "tate i" cha$gi$g. =or
e0ample& whe$ever the .,5let i" 3ei$g activated it" "tart9pp method i" called. 9gai$& thi" i" very "imilar to the
way applet" 3ehave.
7ere i" the code +or a very 3a"ic .,5let& draw$ +rom :hapter 3 o+ .o3ile ,$+ormatio$ 5evice *ro+ile +or !ava 2
.icro Editio$:
// 9 trivial .,5let
pac#age [Link].j2meI
import [Link]$.[Link]
import [Link]$.[Link]
pu3lic cla"" .y.,5let e0te$d" .,5let
impleme$t" :omma$d8i"te$er J
private 5i"play di"playI
private :omma$d e0it:omma$d K $ew :omma$d' 2E0it2&
:omma$[Link],/& 1 (I
// :o$"tructor& doe"$?t do a$ythi$g really
pu3lic .y.,5let'(J
)y"[Link]$tl$' 2.y.,5let co$"tructed2 (I
L
// :alled whe$ the "y"tem i" de"troyi$g the .,5let.
protected void de"troy9pp' 3oolea$ u$co$ditio$al (
throw" .,5let)tate:ha$geE0ceptio$ J
e0it.,5let'(I
L
// :alled whe$ the "y"tem i" pau"i$g the .,5let.
protected void pau"e9pp'(J
)y"[Link]$tl$' 2.y.,5let pau"ed2 (I
L
// :alled whe$ the "y"tem i" activati$g the .,5let.
protected void "tart9pp'( throw" .,5let)tate:ha$geE0ceptio$ J
i+' di"play KK $ull (J // +ir"t time called...
i$it.,5let'(I
L
)y"[Link]$tl$' 2.y.,5let "tarted2 (I
L
// :alled to i$itiali6e the .,5let. E0ecute" o$ly
// o$ce. >3tai$" the 5i"play i$"ta$ce a""ociated
// with thi" .,5let a$d create" a "imple
// u"er i$ter+ace +or it.
private void i$it.,5let'(J
di"play K 5i"play.get5i"play' thi" (I
di"play."et:urre$t' $ew /rivial=orm'( (I
L
// :alled to e0it the .,5let. :e$trali6e" all the
// clea$up wor#.
pu3lic void e0it.,5let'(J
$oti+y5e"troyed'(I
)y"[Link]$tl$' 2.y.,5let de"troyed2 (I
L
// Eve$t ha$dli$g. :alled 3y the "y"tem whe$ the
// u"er activate" a comma$d& $ormally 3y pre""i$g
// a 3utto$.
pu3lic void comma$d9ctio$' :omma$d c& 5i"playa3le d (J
e0it.,5let'(I
L
// 9 trivial E, "cree$. 9 titled 3la$# "cree$
// to which a "i$gle comma$d i" a""ociated. /he "y"tem
// will map that comma$d to a 3utto$ or a me$u item.
cla"" /rivial=orm e0te$d" =orm J
/rivial=orm'(J
"uper' 2.y.,5let2 (I
add:omma$d' e0it:omma$d (I
"et:omma$d8i"te$er' .y.,[Link]" (I
L
L
L
>$e or more .,5let" are pac#aged together i$to what i" re+erred to a" a .,5let "uite& which i" 3a"ically a
"ta$dard !9; '!ava archive( +ile a$d a "eparate +ile called a$ applicatio$ de"criptor. 9ll the u"er%de+i$ed cla""e"
re<uired 3y the "uite?" .,5let" mu"t 3e i$ the !9; +ile& alo$g with a$y other re"ource" '"uch a" image"( that the
.,5let" re<uire. /he !9; +ile mu"t al"o i$clude a ma$i+e"t with a $um3er o+ .,5*%"peci+ic e$trie" that de"cri3e
the .,5let" i$ the "uite. /he applicatio$ de"criptor co$tai$" "imilar i$+ormatio$& a$d i" u"ed 3y device" to o3tai$
i$+ormatio$ a3out a .,5let "uite without havi$g to dow$load a$d i$"tall the .,5let "uite +ir"t.
7ere i" a$ e0ample o+ the ma$i+e"t that goe" alo$g with the "imple .,5let "how$ a3ove:
.,5let%1: .y.,5let& .y.,5let.p$g& [Link].j2me..y.,5let
.,5let%-ame: .y.,5let
.,5let%4e$dor: Eric Giguere
.,5let%4er"io$: 1.@
.icroEditio$%:o$+iguratio$: :85:%1.@
.icroEditio$%*ro+ile: .,5*%1.@
9$d here i" a$ e0ample o+ a$ applicatio$ de"criptor +or the "ame .,5let:
.,5let%1: .y.,5let& .y.,5let.p$g& [Link].j2me..y.,5let
.,5let%!ar%)i6e: 423G
.,5let%!ar%E;8: [Link]
.,5let%-ame: .y.,5let
.,5let%4e$dor: Eric Giguere
.,5let%4er"io$: 1.@
/he"e are o$ly e0ample"& o+ cour"e& a$d we?ll 3e di"cu""i$g the"e i$ more detail a" the "erie" progre""e".
5evelopi$g .,5* 9pplicatio$"
9" the +ir"t !2.E pro+ile to 3e relea"ed a$d to "hip commercially& there are actually "everal .,5* programmi$g
tool" availa3le& o+te$ a" add%i$" +or your +avorite !ava developme$t e$viro$me$t. 9 developme$t e$viro$me$t i"
$ot e$ough& however.
/he reality o+ .,5* programmi$g today i" that the applicatio$" you ca$ write are co$"trai$ed i$ ma$y way".
/he"e co$"trai$t" o+te$ re<uire you to thi$# a3out thi$g" that you would$?t thi$# o+ twice o+ with !2)E
programmi$g. .emory i" a particularly "carce re"ource& +or e0ample. /he early .otorola !2.E%e$a3led pho$e"
limited the "i6e o+ a .,5let "uite to H@A '"i$ce rai"ed to 1@@A o$ more rece$t model"( a$d "ome -o#ia pho$e"
limit them to eve$ le""& a3out 3@A. Becau"e .,5* 1.@ applicatio$" ca$$ot "hare cla""e" 3etwee$ "uite"& thi"
really limit" what you ca$ do o$ the device. Cou?ll +i$d that placi$g part o+ your applicatio$ i$ a we3 or
applicatio$ "erver 'a" a "ervlet& typically( that the .,5* applicatio$ call" i" almo"t a re<uireme$t +or a$ythi$g
"eriou". /hi" will cha$ge over time& o+ cour"e& a" memory limit" are ea"ed i$ $ewer device".
Eric Gigure is the author of Java 2 Micro Edition, the first book about J2ME, and co-author of Mobile
Information Device Profile for Java 2 Micro Edition, both ublished b! John "ile! # $ons% &e 'orks as a
soft'are develoer for i(n!'here $olutions, a subsidiar! of $!base% )or more information about Eric, see his
'eb site or dro him a note at ericgiguere*ericgiguere%com%