! ""#
::. Contenuti della lezione $%&' % ('))')') *+ ') $ &,!!!$!-,.../- ' % + &
::. Le diverse edizioni di Java: J2EE,J2SE,J2ME!" # " $
::. Le diverse edizioni di Java: J2EE,J2SE,J2ME % & ' () * +, ( + -., / 0) * 1-
::. Profili e Configurazioni!"!# "! $%!& ' #( )"& % #( * + *+,-.../
::. Profili e Configurazioni!$/0&2 1 *2-, 1$34#,5(6-7,34 $34#,5(6-7,34. 63#,02 /'0&)"$%1&/' *$1 1 ')* 1
::. Profili e Configurazioni CLDC Mobile phones PDS. KVM (160k-512k) CDC Set-top boxes Personal video recorders. CVM (512k-2MB) Native Operating System
::. CDC vs. CLDC 0 0 '82 $01$/ $1$ $1$$01$ '82 ) 0 #()0
::. Configurazione CLDC (JSR 139)!! " #$%$&'()"* 0) * 2 %& # +
::. Configurazione CLDC (JSR 139), -,. / 01 01'4,'4, 01 9 01 01 01 01%!& ++23 (molte classi derivate da Java.lang.error non esistono) 45 6,
::. Configurazione CLDC (JSR 139) -. 0 #778 / 01 01 6*, ++23 4!,3 -: +')* $01$ '
::. Configurazione CLDC (JSR 139) /9 6:!
::. Configurazione CDC (JSR 218)! 3 $) ;$);1* 2') *",%& java.lang" + "#$! "%! 1- +; ++ +!< + ),
::. Configurazione CDC (JSR 218) + <-<=+. 2 0<=+ 6"<=+ 1 1 9 25(, 2 $ ;5 4 5(,?7+57@ *& 0<=+: 5(,7 + -=7 &' (" >)5, >! &' (" ;<=+:, 2-5(, ( )!!!
::. Configurazione CDC (JSR 218) / 20103 $*09 9 public static void main(string[] args) MainAppClass #*java MainAppClass
::. Configurazione CDC (JSR 218) /6632 = > )5 A,B! = C 8,! D7*0 ')* C 0')* *-$ + 0)/ <=+? -> 2.
::. Configurazione CDC (JSR 218) /@32 A 5(,,4/ +E -=7 F +!! (*)! 5 ;* 0; 6*,6*,
::. I profili: Foundation Profile (JSR 219) $1$ % & #,3 45(, 6: java.io, java.lang, java.lang.ref, java.lang.reflect, java.math, java.net, java.security, java.security.acl, java.security.cert, java.security.interfaces, java.security.spec, java.text, java.util, java.util.jar, java.util.zip, javax.microedition.io ('82 5$#!
::. I profili: Personal Basis Profile (JSR 217) $1$ %& #, -=7 #'B ; 6: java.awt, java.awt.color, java.awt.event, java.awt.image java.beans java.rmi, java.rmi.registry javax.microedition, javax.microedition.xlet.ixc java.applet G # 2 2 ;
::. I profili: Personal Profile (JSR 216) $1$ %&, -=7 '%<& '
::. I profili: Mobile Information Device (JSR 118) 2 2 +7 +6 2 (,+ + +G 2 D772+220+=702 = 7 0<2<+ $HIJK - <! + ++ +2*2+ +G
//*, /+ 2$1$$10$$1$AJA+$01$AA 1=! +0;;LM+=! $+0;-6*+32+ );= +G 0$ 2"! (, #!!! )- 5$$./ 0 *AA ' 23
//*, /+)B 2$1$$10$$1$AJA+$01$AA 1=! +0;;LM+=! $+0;-6*+32+ );= +G 0 -',7',7-37$-37 *AA$1$ * ')*$01$ 1*.!!2 5$%&! 3 +! 4) "!)!
//*, / 4 + 2$1$ 1=! $+0;;LM+0;-6* 0$0 $',7 5$5 *AA ' 23 2'4,'4,+') *1,')*1,+') *,')*, > ')* 5(6#!!!!7$.8
//*, / (, -(,. ) *$01$ AJ 10;+32+2+2<4 0$0 $',7-37 5$5 * ')* 1 ) * IJF LJ@B # 0' A8L@B6-* '4,
//*, / 4 + ) *$01$ AA 10;- ;LM+2<4 0$0 $',7% &+D 2-37 5$5 * ')*, 0')*+ : >
//*, / 4 + 2:,A C 2%:& 0 )* * 23, * 6 :
::. Application Models: MidLet, 0*0/ /!!! - 9 * 2: > + *0 0*0/ / %& 5$ 0*0> -$7,)
::. Ciclo di sviluppo di una MidLet,-H07/ : ' #* F '8*N $* 6?, F $01$ D* 6: F *0 + N +'-1 E* 2 F *0
::. Java Application Descriptor (JAD) $O+ O!O!,'-19'-6 +*,1 > +< > *,1 '-6!+ + '-1,'-1/ $: *,14 *,1) *,1) *,1 *,1'(60
::. Java Application Descriptor (JAD) MIDlet-Version: 1.0.2 MIDlet-Vendor: Totore Consulting MIDlet-Jar-URL: http://www.mobilab.unina.it/hello.jar MicroEdition-Configuration: CLDC-1.1 MicroEdition-Profile: MIDP-2.0 MIDlet-1: Demo1, /image/img1.png, org.mobilab.midlets.helloworld MIDlet-Jar-Size: 10819 MIDlet-Name: HelloWorld
::. Sviluppo MIDP: Elementi Base 3*0 javax.microedition.midlet.midlet, 9-*2++ *0 (*0 void startapp() void pauseapp() void destroyapp(boolean unconditional)
::. Application Models: MidLet import javax.microedition.midlet.*; *-! -*2F - *2< 09-*2 + public class BasicMIDlet extends MIDlet { public BasicMIDlet() { // constructor - don't do much here } protected void destroyapp(boolean unconditional) throws MIDletStateChangeException { // the system destroys the MIDlet } protected void pauseapp() { // the system pauses the MIDlet } } protected void startapp() throws MIDletStateChangeException { // the system activates the MIDlet }
::. Application Models: MidLet 1 3 9 getproperty 5 9!! " ( 6 *0resumeRequest 5"$':!!9 +! $!5!!" * *0notifyPaused 1*0notifyDestroyed
::. NetBeans ) " 0$110 5;!*;!',,*' 7! 1> 5F GFF1 ( ' '8*-3 5(' 4!(25 6768 (' 4!(5 669 ) * 4 + -. 4 + -. (60!www.netbeans.org
::. NetBeans /!(, 3 "! '!4 &- 0<.! "#! =! 1->?'! 7!* "#'@1-=#A
::. NetBeans Screen Designer 65 9 : : ; 6 =+ 9 H
::. NetBeans Flow Designer "
::. NetBeans Source Editor? < -. 3
::. NetBeans Configurazione Emulatore $ 9*9$1$ ($3 $1$$01$ - 9< 9!
::. NetBeans Esecuzione I5" 0$4&- 0<. 6 0$4&- 00 '73 1-B?8C! (D$#(
::. Applicazioni di rete con J2ME 0!1 2,0!1- ' % *.3+45+,'67-
::. Generic Connection Framework (GCF) H 4+ 2*2**2 B =# (*72 7$+(1+67+GG D77+D772+#7+G
::. Generic Connection Framework (GCF) H '8*!:,3 9 9,3 /! %5& 7!/ <303;+10032+109;3> 1;( $01$ AJ,5$#/ $1$+. '82'26AKP
::. Generic Connection Framework (GCF) J <9K 9,3! -E! #-, - 8 <7; 2* 2 $ B 2
::. Generic Connection Framework (GCF) + :! <+ 3 #! (! 9"!! = ; -=;.!!+
::. Generic Connection Framework (GCF) <+
::. Generic Connection Framework (GCF) + 6 Connection, DatagramConnection F,61 (1+7$ InputConnection+OutputConnection F,61 2 StreamConnection F $ ContentConnection F 2StreamConnection+ StreamConnectionNotifier ( Connector F#<,(60 (60
::. Generic Connection Framework (GCF) 3 H <9 L 4226 M)N 0 O 5:*I :
::. Generic Connection Framework (GCF) =; 26#$APCL8CKM scheme://user:password@host:port/url-path;parameters F,5$# F + 65 F!+ F #?14,: (60 F +?F % &,>
::. Generic Connection Framework (GCF) < -#FE. import java.io.*; import javax.microedition.midlet.*; import javax.microedition.io.*; import javax.microedition.lcdui.*; public class GCFConn extends MIDlet { private Display display; private String url = "http://wpage.unina.it/saorland/hellocms.txt"; public GCFConn() { display = Display.getDisplay(this); } public void startapp() { try { downloadpage(url); } catch(ioexception e) { alert = new Alert(message,e.toString(), null, AlertType.WARNING); alert.settimeout(alert.forever); display.setcurrent(alert); } } [CONTINUA...]
::. Generic Connection Framework (GCF) < -$FE. private void downloadpage(string url) throws IOException { StringBuffer b = new StringBuffer(); StringBuffer h = new StringBuffer(); String hf = ""; // not null InputStream is = null; HttpConnection c = null; TextBox t = null; try { long len = 0 ; int ch = 0; c = (HttpConnection)Connector.open(url); is = c.openinputstream(); // Fetch the HTTP Header for (int i = 0 ; hf!= null; i++) { hf = c.getheaderfieldkey(i); h.append(i+": "+hf); hf = c.getheaderfield(i); if (hf!= null && hf!= "") h.append("="+hf+"\n"); } [CONTINUA...]
::. Generic Connection Framework (GCF) < -DFE. [CONTINUA METODO downloadpage] len = c.getlength(); if ( len!= -1) { // Read exactly Content-Length bytes for (int i =0 ; i < len ; i++ ) if ((ch = is.read())!= -1) b.append((char) ch); } else { // Read till the connection is closed. while ((ch = is.read())!= -1) { len = is.available() ; b.append((char)ch); } } } [CONTINUA...]
::. Generic Connection Framework (GCF) < -EFE. [CONTINUA METODO downloadpage] // Dump file data to the device screen t = new TextBox("hello again...",h.tostring()+b.tostring(),2048,0); // Dump file data to ktoolbar System.out.println("Headers"); System.out.println(h.toString()); System.out.println("Body"); System.out.println(b.toString()); } finally { is.close(); c.close(); } display.setcurrent(t); } } public void pauseapp() {} public void destroyapp(boolean unconditional) {}
::. Java APIs for Bluetooth (JSR-82) -,+ B' 0 ' B '26L8/ 8 1) javax.bluetooth 4-,B 2) javax.obex -, %3N;& QBR
::. Java APIs for Bluetooth (JSR-82) ;M *IA8@63*6-* $ B,'8*$01$ 6: B 5-21<- 2 21< -6. 6#:<$3** -;91. 0 0$- -$6. B$$-).
::. Java APIs for Bluetooth (JSR-82) 6+;?%$ 6B 6 2 6#$3**+08$-3BH,3 5 #% <& : 3'4 -, 9')* @4,
::. Java APIs for Bluetooth (JSR-82) ) 0'B> M #* + : $* < D* ; E* ; &* ; '*
::. Java APIs for Bluetooth (JSR-82) + : :) H A :) M M A J -). + ( ::: 6+ ) ;?%$ -!!! : 6+A
::. Java APIs for Bluetooth (JSR-82) < 3 ;!!!!... // retrieve the local Bluetooth device object LocalDevice local = LocalDevice.getLocalDevice(); // retrieve the Bluetooth address and name of the local device String address = local.getbluetoothaddress(); String name = local.getfriendlyname();... ; : ::... // retrieve the device that is at the other end of the Bluetooth connection RemoteDevice remote = RemoteDevice.getRemoteDevice(Connection c); // retrieve the Bluetooth address and name of the remote device String remoteaddress = remote.getbluetoothaddress(); String remotename = local.getfriendlyname(true);...
::. Java APIs for Bluetooth (JSR-82) ;-#F$. + /J 0M ;DiscoveryAgent A DiscoveryListener DiscoveryAgent - startinquiry. 1 M devicediscovered A DiscoveryListener inquirycompleted DiscoveryListener DiscoveryAgent!! retrievedevices!! @ A +!! +!
::. Java APIs for Bluetooth (JSR-82) ;-$F$. 3,+3+0I=+;P... // retrieve the discovery agent DiscoveryAgent agent = local.getdiscoveryagent(); // place the device in inquiry mode boolean complete = agent.startinquiry();... ;3=63;1+2+61+2+,+012+... // retrieve the discovery agent DiscoveryAgent agent = local.getdiscoveryagent(); // return an array of pre-known devices RemoteDevice[] devices = agent.retrievedevices(discoveryagent.preknown); //usare CACHED per //risultati inquiries precedenti...
::. Java APIs for Bluetooth (JSR-82) ; J M + DiscoveryAgent /6+;?%$
::. Java APIs for Bluetooth (JSR-82) ; J ) #* $* "! -)). D* ; + / ) ; ))
::. Java APIs for Bluetooth (JSR-82) ) 0'26L8 $6F 0B 9 : 9 A *;; 8 2-6 < ;91 F 628C8B+ 08$- 1)3@ = BS
::. Java APIs for Bluetooth (JSR-82) 6 6 -#F$. ;91$6 3 -;?$D$. # ;91 G'7! ;91 = )QGD7;91-1#L 1D7. = Q ;91
::. Java APIs for Bluetooth (JSR-82) 6 6 -$F$. ; / =; * =; ) ; - N. 3=;/ btspp://102030405060740a1b1c1d1e100:5 Proto Address Port (porta COM)
::. Java APIs for Bluetooth (JSR-82) 36 6 -#F$.?... // service URL String ServiceURL = "btspp://localhost:10203040607040a1b1c1de100;name=spp Server1"; try { // create a server connection StreamConnectionNotifier notifier = (StreamConnectionNotifier) Connector.open(serviceURL); // accept client connections StreamConnection connection = notifier.acceptandopen(); // prepare to send/receive data byte buffer[] = new byte[100]; String msg = "hello there, client"; InputStream is = connection.openinputstream(); OutputStream os = connection.openoutputstream(); // send data to the client os.write(msg.getbytes()); // read data from client is.read(buffer); connection.close(); } catch(ioexception e) { e.printstacktrace(); }...
::. Java APIs for Bluetooth (JSR-82) 36 6 -$F$.?... // (assuming we have the service record) // use record to retrieve a connection URL String url = record.getconnectionurl( record.noauthenticate_noencrypt, false); // open a connection to the server StreamConnection connection = (StreamConnection) Connector.open(url); // Send/receive data try { byte buffer[] = new byte[100]; String msg = "hello there, server"; InputStream is = connection.openinputstream(); OutputStream os = connection.openoutputstream(); // read data from the server is.read(buffer); // send data to the server os.write(msg.getbytes); connection.close(); } catch(ioexception e) { e.printstacktrace(); }...