Java SE 6 includes several new features including improved support for scripting languages, web services, databases, desktop applications, monitoring and management. It also includes enhancements to dialog modality, text printing, Swing utilities like SwingWorker and a new GroupLayout class. Developers can now easily add scripting support, build and run web services clients and servers, and take advantage of additional desktop integration capabilities in their Java applications.
Java SE 6 includes several new features including improved support for scripting languages, web services, databases, desktop applications, monitoring and management. It also includes enhancements to dialog modality, text printing, Swing utilities like SwingWorker and a new GroupLayout class. Developers can now easily add scripting support, build and run web services clients and servers, and take advantage of additional desktop integration capabilities in their Java applications.
Java SE 6 includes several new features including improved support for scripting languages, web services, databases, desktop applications, monitoring and management. It also includes enhancements to dialog modality, text printing, Swing utilities like SwingWorker and a new GroupLayout class. Developers can now easily add scripting support, build and run web services clients and servers, and take advantage of additional desktop integration capabilities in their Java applications.
Java SE 6 includes several new features including improved support for scripting languages, web services, databases, desktop applications, monitoring and management. It also includes enhancements to dialog modality, text printing, Swing utilities like SwingWorker and a new GroupLayout class. Developers can now easily add scripting support, build and run web services clients and servers, and take advantage of additional desktop integration capabilities in their Java applications.
Java SE 6 Top 10 Java SE 6 Top 10 Features Features Sang Shin Sang Shin Michle Garoche Michle Garoche http://www.javapassion.com http://www.javapassion.com
Learn with Passion!
Learn with Passion! 2 2 The JDK 6 Top 10 1.Scripting 2.Web Services 3.Database (JDBC 4.0, Java DB) 4.More Desktop !"s #.Monitoring an$ Manage%ent &.Co%pi'er ccess (.!')ggab'e nnotations *.Desktop Dep'o+%ent ,.Sec)rit+ 10.-)a'it+, Co%patibi'it+, Stabi'it+ 1. Scripting 1. Scripting Motivation for Scripting Support !rovi$es $eve'opers an opport)nit+ to 'everage t.e a$vantages o/ $i//erent 'ang)ages in t.e sa%e app'ication 01ten$s scripting 'ang)ages )sing t.e po2er/)' Java tec.no'og+ 'ibraries > 3e)se o/ co$e %o$)'es in ot.er progra%%ing 'ang)ages !ro$)ces an environ%ent in 2.ic. $eve'opers an$ en$ )sers can co''aborate to create %ore )se/)', $+na%ic app'ications > B+ $e'ivering Java app'ications t.at can be c)sto%i4e$ via scripts b+ )sers o/ t.e app'ications 5 Scripting Scripting /or t.e Java !'at/or% (JS3 223) > Mec.anis% /or con/ig)ring script engines into Java S0 > !"s /or %i1ing script /rag%ents into Java app'ications JavaScript engine is inc')$e$ in S)n5s i%p'e%entation o/ Java S0 & > Mo4i''a 3.ino engine Con/or%ant scripting engines > scripting.6ava.net 6 Scripting Developer Exaple // create a ScriptEngineManager ScriptEngineManager m = new ScriptEngineManager(); // get an instance of JavaScript script engine ScriptEngine engine = m.getEngineByName("js"); // eva!ate a script engine.eva("aert(""#eo $or%&"")");
7 Deo! Scripting over Java SE 3)nning Script!a$ sa%p'e app 01ec)ting JavaScript co$e "nvoking Java %et.o$s /ro% JavaScript co$e 7o) can tr+ t.is +o)rse'/ > 8.is sa%p'e app'ication co%es 2it. JD9 & as rea$+ to open :etBeans pro6ects ". #e$ Services ". #e$ Services 9 #e$ Services Support on Java SE 6 %latfor J;<WS Data bin$ing )sing J;B 2.0 =p$ates to t.e J;!, 2.ic. inc')$es Sta; Stan$ar$s s)pporte$ > S>! 1.2 > WS<" Basic !ro/i'e 1.1 > ;M?<binar+ >pti%i4e$ !ackaging (;>!) an$ S>! Message 8rans%ission >pti%i4ation Mec.anis% (M8>M) > 3epresentationa' State 8rans/er (30S8) > 8ota''+ on ;M? sc.e%a 10 &%' Support Java S0 & provi$es s)pport /or t.e J;< WS 2eb services stack. > @or t.e c'ient si$eA Service c'ass /or creating pro1+ > @or t.e server si$eA 0n$point c'ass /or p)b'ication 11 Server(Si)e %rograing Mo)el 1. Write a !'ain >'$ Java >b6ect (!>J>) i%p'e%enting t.e service. 2. $$ '$e(Service to it. 3. >ptiona''+, in6ect a $e(Service)onte*t 4. !)b'is. t.e Web service en$point t.ro)g. En%point.p!(is+() %et.o$ > WSD? is a)to%atica''+ generate$ at r)nti%e #. !oint +o)r c'ients at t.e Web Services Description ?ang)age (WSD?), /or e1a%p'eA > +ttp,//myserver/myapp/MyService-$S./. 12 8.e p!(is+ %et.o$s can be )se$ to start p)b'is.ing an en$point, at 2.ic. point it starts accepting inco%ing reB)ests. 8.e stop %et.o$ can be )se$ to stop accepting inco%ing reB)ests an$ take t.e en$point $o2n !)b'is. )sing t.e C88! server e%be$$e$ in Java S0 &. S)pports reasonab'e $e/a)'ts /or t.rea$ing. Creates WSD? an$ p)b'is.es it at r)nti%eA > +ttp,//oca+ost/cac!ator-$S./ %u$lishing En)point 13 %u$lishing an En)point '$e(Service p!(ic cass )ac!ator 0 '1eso!rce $e(Service)onte*t conte*t; p!(ic int a%%(int a2 int () 0 ret!rn a3(; 4 4 // )reate an% p!(is+ an en%point )ac!ator cac!ator = new )ac!ator(); En%point en%point = En%point.p!(is+ (5+ttp,//oca+ost/cac!ator62cac!ator); 14 *lient(si)e %rograing 1.!oint a too' at t.e WSD? /or t.e service 2.Denerate annotate$ c'asses an$ inter/aces t.ro)g. a too' 3.Ca'' ne2 on t.e service c'ass. 4.Det a pro1+ )sing a get***7ort %et.o$. #."nvoke an+ re%ote operations. 15 Exaple! Java SE($ase) *lient // )reate a Service o(ject )ac!atorService svc = new )ac!atorService(); // )reate a pro*y from t+e Service o(ject )ac!ator pro*y = svc.get)ac!ator7ort(); // 8nvo9e a $e( service operation int answer = pro*y.a%%(:;2 <); 16 Deo! #e$ Services over Java SE B)i'$ an$ r)n 0Ba+ Web service an$ c'ient /ro% JD9 & sa%p'es 7o) can tr+ t.is +o)rse'/ > 8.is sa%p'e app'ications co%e 2it. JD9 & as rea$+ to open :etBeans pro6ects +. Data$ase +. Data$ase 18 JD,* -.0 Support =p$ate$ t.e $eve'oper !"s (JDBC 4.0 ) > 01ception .an$'ing i%prove%ent >:e2 s)bc'asses o/ S-?01ception > 0n.ance$ B?>BEC?>B /)nctiona'it+ >SetC'ob(), createC'ob() > S-?;M? Data 8+pe (/ro% S-? 2003) >;M? is a /irst<c'ass $ata t+pe F no 'onger nee$ to )se C?>Bs to access ;M? $ata e'e%ent 19 Java D, Java DB base$ on pac.e Derb+ > JDBC con/or%ant a''<Java re'ationa' $atabase > B)n$'e$ an$ pre<con/ig)re$ in JD9 -. Des.top &%'s -. Des.top &%'s 21 -. Des.top &%'s W8 i%prove%ents > 8ra+ icon > Sp'as. screen > Desktop c'ass > Dia'og Mo$a'it+ en.ance%ents an$ !" > 8e1t printing S2ing i%prove%ent > Dro)p?a+o)t F basis /or :etBeans D=" B)i'$er (Matisse) > J8ab'e sorting an$ /i'tering > S2ingWorker 22 Tra/ 'con ?ets +o) access t.e s+ste% tra+ in +o)r Java app'ication > SystemTray > TrayIcon Dive +o) t.e abi'it+ to a$$ grap.ics, pop)p %en)s, an$ /'oating tip /)nctiona'it+ to t.e s+ste% tra+ 23 Tra/ 'con! 0sage // )onstr!ct a =ray8con =ray8con tray8con = new =ray8con(image2 "=ray .emo"2 pop!pMen!); // >%% event istener tray8con.a%%>ction/istener(action/istener); // >%% t+e tray icon to t+e System tray System=ray.getSystem=ray().a%%(tray8con); 24 Splash Screen! 1vervie2 Be/ore Java S0 &, Java r)nti%e nee$s to be /)''+ 'oa$e$ an$ initia'i4e$ be/ore a vis)a' i%age can be $isp'a+e$ ''o2s $isp'a+ing a sp'as. screen /or t.e app'ication instant'+Gbe/ore t.e Java r)nti%e so/t2are startsH > D"@, !:D, an$ J!0D i%ages s)pporte$ > 8ransparenc+, trans')cenc+, an$ ani%ation s)pporte$ > C'ose$ a)to%atica''+ 2.en /irst top<'eve' 2in$o2 $isp'a+s 25 Splash Screen! 0sage Disp'a+ /ro% co%%an$ 'ine java ?spas+,image.gif =+e>pp Disp'a+ /ro% M:"@0S8.M@ (in a 6ar /i'e) Spas+screen?8mage, image.gif !ainting < 7o) can c.ange t.e i%age s.o2n a/ter t.e sp'as. screen is 'oa$e$, b)t be/ore t.e app'ication starts. Spas+Screen spas+ = Spas+Screen.getSpas+Screen(); @rap+icsA. g = spas+.create@rap+ics(); // yo!r painting co%e +ere spas+.!p%ate(); 26 Des.top *lass :e2 c'assA java.awt..es9top > Cas an en)%eration o/ actions t.at %a+ be s)pporte$ /or a /i'e or =3" > B3>WS0, 0D"8, M"?, >!0:, an$ !3":8 8.ings +o) can $o in +o)r Java apps > ?a)nc. t.e .ost s+ste%5s $e/a)'t bro2ser 2it. a speci/ic =ni/or% 3eso)rce "$enti/ier (=3") > ?a)nc. t.e .ost s+ste%5s $e/a)'t e%ai' c'ient > ?a)nc. app'ications to open, e$it, or print /i'es associate$ 2it. t.ose app'ications Depen$s on p'at/or% capabi'ities to 2orkA > .es9top.is.es9topS!pporte%() 27 Deo! Des.top &%' B)i'$ an$ r)n sa%p'e app'ications > 8ra+ icon > Sp'as. screen > Desktop c'ass 7o) can tr+ t.is +o)rse'/ > 222.6avapassion.co%E.an$son'absE6avase&/e at)res 28 Dialog Mo)alit/ Enhanceent :e2 %o$a'it+ %o$e' is intro$)ce$ > 8.is ne2 %o$e' a''o2s t.e $eve'oper to scope, or 'i%it, a $ia'og bo15s %o$a'it+ b'ocking, base$ on t.e %o$a'it+ t+pe t.at t.e $eve'oper c.ooses > ''o2s 2in$o2s an$ $ia'og bo1es to be tr)'+ parent'ess > So'ves t.e prob'e% o/ interacting 2it. JavaCe'p in J2S0 1.# 2.en %o$a' $ia'og bo1 is on t.e /ront 29 Mo)alit/ T/pes %o$e'ess > $oes not b'ock an+ ot.er 2in$o2 $oc)%ent<%o$a' > b'ocks inp)t to a'' top<'eve' 2in$o2s /ro% t.e sa%e $oc)%ent app'ication<%o$a' > b'ocks a'' 2in$o2s /ro% t.e sa%e app'ication too'kit<%o$a' > b'ocks a'' 2in$o2s t.at r)n in t.e sa%e too'kit 30 3e2 Dialog Mo)alit/ &%' 31 Text %rinting 0asi'+ print a S2ing te1t co%ponentA > !rints t.e entire contents o/ t.e te1t co%ponent > Does not .ave to be visib'e > java*.swing.te*t.J=e*t)omponent.print(); 3e/or%ats /or printe$ page >ptiona''+ $isp'a+s print $ia'og an$ progress bo1 S)pports optiona' .ea$erE/ooter Wi'' not sp'it 'ines in .a'/H 32 Deo! Des.top &%' B)i'$ an$ r)n sa%p'e app'ications > Dia'og Mo$a'it+ en.ance%ents an$ !" > 8e1t printing > J8ab'e sorting an$ /i'tering 33 S2ing#or.er Makes it eas+ to o//'oa$ 2ork to separate t.rea$s Makes )se o/ conc)rrenc+ package Makes it %ore generic S)pports partia' res)'ts S)pports !ropert+C.ange?istener More in/or%ationA > 6ava.s)n.co%E$ocsEbooksEt)toria'E)is2ingEconc)rrenc+E Easing multi-threaded applications ith !ing 34 java*.swing.@ro!p/ayo!t "lass :e2 'a+o)t %anager to s)pport ne2 Matisse D=" b)i'$er > :etBeansI "D0 s.ips 2it. Matisse > Can a'so )se GroupLayout in J2S0 1.# so/t2are )sing stan$<a'one 'ibrar+ More capabi'ities /or re'ative positioning o/ co%ponents Works 2it. .ori4onta' an$ vertica' 'a+o)t separate'+ 35 #sing @ro!p/ayo!t "lass Horiontal !ertical "oth Horiontal an# !ertical 36 JTa$le Sorting an) Filtering $$ sorting to +o)r J8ab'e 2it. one %et.o$ ca''A > set>!to)reate1owSorter(tr!e) Speci/+ +o)r o2n co%parators S)pports secon$ar+ an$ tertiar+ sort co')%ns Can speci/+ a /i'ter to 'i%it 2.at is s.o2nA > 3eg)'ar e1pression, n)%ber, an$ $ate i%p'e%entations provi$e$ 37 Deo! 3et,eans 40' ,uil)er B)i'$ an$ r)n Contact0$itor D=" 7o) can tr+ t.is +o)rse'/ > 222.6avapassion.co%E.an$son'absEnbg)ib)i' $erE 5. Monitoring 6 5. Monitoring 6 Manageent Manageent 39 %otential %ro$les That *an ,e Detecte) Me%or+ 'eaks 8.rea$ $ea$'ocks Dirt+ re/erences "n/inite 'oops 40 Monitoring an) Manageent jpsA 'ists JJM5s jconsoleA can connect to app'ications t.at $i$ not start )p 2it. t.e JM; agent jmapA takes a $etai'e$ 5p.otograp.5 o/ 2.at5s going on in %e%or+ at an+ one point in ti%e jhatA /orensic e1pert t.at 2i'' .e'p +o) interpret t.e res)'t o/ jmap jstackA takes a 5p.otograp.5 o/ a'' t.e t.rea$s an$ 2.at t.e+ are )p to in t.eir o2n stack /ra%es 41 Deo! 7console8 7ps8 7ap8 7hat8 7stac. 3)n a sa%p'e Java app'ication =se t.e too's > =se jps to see process i$s o/ a'' Java processes > =se jconsole to connect it > =se jmap to capt)re snaps.ot o/ .eap o/ a Java process > =se jhat to interpret it > =se jstack to t.rea$<$)%p on a 'ive process 7o) can tr+ t.is > 222.6avapassion.co%E.an$son'absE6avase&to o'sE 42 Deo! Meor/ 9ea. Detection via 3et,eans @in$ o)t e1act'+ 2.ere %e%or+ 'eaking co$e in +o)r Java app'ication is 'ocate$ 7o) can tr+ t.is > 222.6avapassion.co%E.an$son'absEnbpro/i'er %e%or+E 6. *opiler &ccess 6. *opiler &ccess 44 *opiler &ccess >pens )p progra%%atic access to javac /or in<process co%pi'ation o/ $+na%ica''+ generate$ Java co$e 3ea''+ ai%e$ at peop'e 2.o create too's /or Java $eve'op%ent an$ /or /ra%e2orks > JavaServer !ages (JS!) or !C! constr)ction kit engines t.at nee$ to generate a b)nc. o/ c'asses on $e%an$ > verage $eve'opers 2i'' bene/it in$irect'+ /ro% /aster per/or%ing too' >Jasper JS! engine r)ns JS! 8C9 3.#1 /aster :. %lugga$le :. %lugga$le &nnotations &nnotations 46 %lugga$le &nnotations JS3 1(# o/ JD9 # stan$ar$i4e$ .o2 annotations are $ec'are$ in Java co$e b)t annotation processing $etai's 2ere re'egate$ as an i%p'e%entation $etai' JS3 2&, o/ JD9 &, !')ggab'e nnotation !rocessing !", stan$ar$i4es annotation processing as 2e'' > 8.e annotation processors act as p')g<ins to t.e co%pi'er, .ence Kp')ggab'e annotation processingL 47 :. %lugga$le &nnotations ''o2 $eve'opers to $e/ine ne2 annotations... 'Bor1eview p!(ic voi% myMet+o%() 0...4 ...an$ !"s to $e/ine co%ponents t.at process t.e%... import java*.annotation.processing.C; p!(ic cass Bor1eview7rocessor e*ten%s >(stract7rocessor 0..4 ...an$ integrate t.e% 2it. t.e Java Co%pi'er javac ?processor Bor1eview7rocessor My)o%e.java ;. Des.top ;. Des.top Deplo/ent Deplo/ent 49 ;. Des.top Deplo/ent We i%prove$ act)a' per/or%ance > grap.ics .ar$2are acce'eration on Win$o2s ...an$ perceive$ per/or%ance > tr)e $o)b'e b)//ering We i%prove$ t.e native 'ook M /ee's > =p$ate$ S2ing ?ookM@ee' Win$o2sE=ni1 > ?CD te1t ren$ering We reva%pe$ Java Web Start an$ J30 insta''ations > no %ore scar+ sec)rit+ $ia'og 50 #in)o2s 9oo. an) Feel 'proveents !ing!et on $ista ith 5%0 51 #in)o2s 9oo. an) Feel 'proveents !ing!et on $ista ith 6 <. Securit/ <. Securit/ 53 <. Securit/ We a$$e$ i%portant ne2 !"s > ;M? Digita' Signat)re (;M?DSig) !" (JS3 10#) > S%art Car$ "E> !" (JS3 2&*) "%prove$ a)t.entication sc.e%es > JS<base$ a)t.entication )sing ?D! > :ative !'at/or% Java DSS!" (Deneric Sec)rit+ Services pp'ication !rogra%%ing "nter/ace) integration 10. =ualit/8 Sta$ilit/8 10. =ualit/8 Sta$ilit/8 *opati$ilit/ *opati$ilit/
55 10. =ualit/8 Sta$ilit/8 *opati$ilit/ We are sti'' r)nning t.e Big pp tests We no2 .ave *0,000N JC9 tests We5ve .a$ goo$ )ptake o/ 2eek'+ b)i'$s We ran a 3egression C.a''enge 56 10. %erforance 'proveent &2!E 1%2%2 &2!E 1%3%1 &2!E 1%4%2 'iger (ustang )eta 0 50 100 150 200 250 * o r m a l i + e d
t o
& 2 ! E
1 % 2 % 2
, e r - o r m a n c e Client Benchmark: SwingMark 57 10. %erforance 'proveent Server Benchmark: SPECjbb2000 &2!E 1%3%1 &2!E 1%4%2 'iger (ustang )eta 0 50 100 150 200 250 300 350 400 * o r m a l i + e d
t o
& 2 ! E
1 % 2 % 2
, e r - o r m a n c e #h/ Java SE 6> #h/ Java SE 6> 59 ?unning &pps on Java SE 6 pp'ications r)n /aster on t.e $esktop an$ servers :e2 5D+na%ic ttac.5 $iagnostics si%p'i/+ tro)b'es.ooting 01pan$e$ So'aris D8race s)pport provi$es a$$itiona' va')e on So'aris "%prove$ 5native5 'ook an$ /ee' across So'aris, ?in)1, an$ Win$o2s @irst Java p'at/or% 2it. /)'' s)pport /or Win$o2s Jista 60 ,uil)ing &pps on Java SE 6 JavaScript integrate$ an$ inc')$e$ 2it. t.e p'at/or% Scripting 'ang)ages /ra%e2ork e1ten$s s)pport /or 3)b+, !+t.on, an$ ot.er 'ang)ages Co%p'ete 'ig.t<2eig.t p'at/or% /or 2eb services, rig.t o)t o/ t.e bo1 Si%p'i/ie$ D=" $esign an$ e1pan$e$ native p'at/or% s)pport @)'' JDBC4 i%p'e%entation provi$ing i%prove$ ;M? s)pport /or Databases Java DB inc')$e$ 2it. t.e JD9, a /ree to )se an$ $ep'o+ Java Database @)'' s)pport b+ :etBeans "D0 #.#, #.#.1 an$ &.0 61