You are on page 1of 39

14/6/2007 Java Technology 1. Java Standard Edition (Java SE) 2. Java Enterprise Edition (Java EE) . Java !

o"ile Edition ( Java !E) http#//$ava.s%n.co& 'ersions 1. (rod%ct 'ersion a. 1.0 ". 1.1 c. 1.2 d. 1. e. 1.4 ). *.0 g. 6.0 2. +eveloper 'ersion (J+, - J.E) a. 1.0 ". 1.1 c. 1.2 d. 1. e. 1.4 ). 1.* g. 1.6 Tools 1. Java +evelop&ent ,it (1.* - 1.6) 2. Java .%nti&e Environ&ent (1.* - 1.6) Editor or IDE 1. /otepad 2. Kawa . /et0eans 4. Eclipse *. 1ntelliJ 6. 10! 'is%al 2ge 7. 3racle J+eveloper Etc. J+, Javac.e4e5 J2'2(.E6E5 J2..E6E etc. J.E Java 'irt%al !achine 7 8ar"age 9ollector J'! 9ode 'eri)ier 7 J1T (J%st:1n:Ti&e) co&piler History of Java

+eveloped in 1;;1 at S%n !icrosyste&s "y Ja&es 8osling <ith initial na&e =3a>? rena&ed to Java in 1;;*. Feat res of Java 1. Si&ple 2. Sec%re . 3"$ect 3riented 4. (orta"le *. (lat)or& 1ndependent a. .$ava J2'29.E6E .class (0yte 9ode) J1T 0inary ". J'! is a &achine dependent progra& that &a>es Java (lat)or& 1ndependent 6. .o"%st a. 1n:"%ilt i. "ig set o) li"raries ii. 8ar"age 9ollection ". E4ception handling )acility 7. !%ltitheaded 16/6/2007 9o&&ents 1. !%ltiline co&&ents a. /@ A @/ 2. Single Bine a. // co&&ents . +oc%&entation 9o&&ents a. /@@ and @/ Types of Java !rogra"s 1. Java 2pplication 2. Java 2pplets #riti$g Java %pplicatio$ !rogra"s 1. Each application progra& &%st have an entry point p &lic static void "ai$'(tri$g args)*+ 2. Java provides a set o) li"raries called pac>ages containing a related set o) classes a. $ava.lang (de)a%lt) C (rovides all co&&only %sed classes li>e String5 !ath etc. ". $ava.io C 1/3 related classes. Dile5 DileEriter5 Dile.eader5 1np%tStrea&5 1np%tStrea&.eader5 0%))ered.eader etc. c. $ava.sFl )or J+09

d. $ava.a<t 8G1 (rogra&&ing e. $ava4.s<ing 2dvanced 8raphics ). Gse i"port co&&and to i&port the classes i. i&port pac>agena&e.classna&eH ii. i&port pac>agena&e.@H Java !rogra""i$g co$ve$tio$ 1. 2ll classes and inter)aces starts <ith 9aps a. String5 0%))ered.eader5 1np%tStrea&.eader 2. 2ll )ields and &ethods starts <ith lo<er case a. length5 readBine()5 print()5 print)()5 println() . 2ll >ey<ords and pac>age na&es al<ays in lo<er case ,e$eral I-. operatio$s Java provides Syste& class <ith i$ and o t o"$ects. in re)ers to >ey"oard and o%t )or the &onitor. i$ is an o"$ect o) I$p t(trea" class and o t is an o"$ect o) !ri$t(trea" class (rintStrea& class provides &ethods 1. print() 2. println() . print)() #riti$g first /ava progra" // )irst progra& C )irst.$ava class Test I p%"lic static void &ain(String argsJK) I Syste&.o%t.println(LMello to allL)H N N /ote# Set the path o) 01/ )older "e)ore co&pilation SET (2TMOP(2TMPH+#QJ+,1.*Q01/ 0o"pili$g Java progra"s J2'29 Rprogra&na&eS e.g. J2'29 )irst.$ava Test.class File 1a"i$g co$ve$tio$ 1. 2 )ile can have any n%&"er o) classes and choice o) its na&e e4cept i) class is p%"lic then "oth &%st "e sa&e

2. 2 progra& can have only one p%"lic class 2 $$i$g a class J2'2 Rclassna&eS Java Test Data Types 1. 1ntegral types (2ll are signed) a. "yte : 1 "yte ". short : 2 "ytes c. int : 4 "ytes d. long : T "ytes 2. Dloatings a. )loat : 4 "ytes (6 dec. place) ". do%"le : T "ytes (14 dec. place) . 9haracters a. char : 2 "ytes (Gnicode) 4. 0ooleans a. "oolean C 1 "it ( can have only tr%e or )alse) 3aria&les 2 &e&ory location to store and retrieve the val%es that can "e changed any<here. int nH nO*H nO7H 0o$sta$ts 2 &e&ory location to store and retrieve the val%es that can never "e changed a)ter initialiUation. fi$al >ey<ord is %sed. )inal do%"le piO .14H 4iterals The val%es that are assigned to so&e varia"le or the constants. 1ntegral literals ("y de)a%lt int) 1. +eci&al (de)a%lt) 2. 3ctal C Starts <ith :0 . Me4adeci&al C starts <ith 04 or 06 int nO0427H int >O074H long >O67BH // %se l or B s%))i4 )or long val%es

Dloating literals (de)a%lt is do%"le) do%"le >O*6.6H )loat pO4.*H // never get co&piled )loat pO4.*DH // Gse ) or D s%))i4 )or )loating 9haracter literals : Enclosed in single F%otes char chO?2?H : Escape seF%ence characters o Qn o Qt o QQ o QV Eg. Me said5 WQnV is )or ne< line String Biterals : Enclosed in do%"le F%otes : Mandled "y (tri$g class o) $ava.lang pac>age String na&eOV'i>asVH 2eadi$g Data fro" 5ey&oard !ethod 1 1. Gse (ca$$er class o) /ava. til pac>age a. !ethods o) Scanner class i. int ne4t1nt() ii. do%"le ne4t+o%"le() iii. String ne4t() 17/6/2007 !ethod 2 C Gsing 0%))ered.eader : .ead data )ro& >ey"oard (Syste&.in) and pass it to 1np%tStrea&.eader : 1np%tStrea&.eader converts the "yte into character : (ass the characters to 0%))ered.eader to place the& into a "%))er till enter >ey is pressed : (ass the "%))ered data to any place %sing readBine() &ethod o) 0%))ered.eader class 0%))ered.eader "rOne< 0%))ered.eader(ne< 1np%tStrea&.eader(Syste&.in))H /ote# readBine() ret%rns the data in String )or&at. 1t need to "e converted to other types. Java provides special >ind o) classes )or conversion called #rapper classes

Erapper class is a special class corresponding to data types "yte 0yte class short Short class int 1nteger class long Bong char 9haracter 0o$versio$ r le datatype varia"leO<rapperclass.parse+atatype(stringdata)H int ageO1nteger.parse1nt("r.readBine())H do%"le "asicO+o%"le.parse+o%"le("r.readBine())H !ethod C Gsing 9o&&and Bine 2rg%&ent : (roviding data to a progra& <hile r%nning progra&s )ro& +3S (ro&pt : +ata is passed to argsJK varia"le o) &ain() &ethod 0o$ditio$s 1. i) 2. s<itch . Ternary operator (X#) a. conditionXtr%e part # )alse part e.g. int gOaS"X(aScXa#c) # ("ScX"#c)H 4oops 1. 2. . 4. <hile do:<hile )or )or each C to <or> <ith arrays and collections

)or(datatype varia"le # array or collection) state&entsH 2rrays : Di4ed SiUe int nJKOne< intJ*KH //nJ0K :S nJ4K int aJKJKOne< intJ KJ4KH : .perators Each array provides le$gt6 property

1. 2rith&etic 7 2. Bogical -. .elational OO 4. 0it<ise operators Y

: YY ZO [

@ Z S RR

/ SO SS R RO instanceo)

SSS (\ero )ill right shi)t)

+i))erence "et<een - and -: 1n -- i) )irst condition is )alse then second is not chec>ed : 1n - "oth conditions are al<ays chec>ed +i))erence "et<een Y and YY : 1n YY i) )irst condition is tr%e then second is not chec>ed : 1n Y "oth conditions are al<ays chec>ed +i))erence "et<een SS and SSS : SS operator do not shi)t the sign "it : SSS shi)ts the sign "it i) n%&"er is negative 17-6-2008 0lass 9 .&/ect 2 class is set o) speci)ication having a set o) )ields and &ethods a"o%t an entity. class >ey<ord is %sed. Dields hold the val%es and &ethods provide the action. Types of 0lass "e"&ers 1. /on Static or 1nstance &e&"ers C (de)a%lt) C /eeds an o"$ect to %se the& 2. Static or 9lass &e&"ers C co&&on to all o"$ects. 9an "e accessed thro%gh the o"$ect or the class na&e. static >ey<ord is reF%ired class Test I p%"lic void hello() //instance &e&"er I Syste&.o%t.println(WMello to 2llV)H N p%"lic static void <elco&e() //static or class &e&"er I Syste&.o%t.println(WEelco&e to JavaV)H N N class Testing I p%"lic static void &ain(String argsJK) I Test tOne< Test()H t.hello()H

Test.<elco&e()H N N /ote# 1. To create an o"$ect o) a class5 special &ethod is reF%ired called 9onstr%ctor. 9onstr%ctor is a special &ethod 1. Maving the sa&e na&e as class na&e 2. /o ret%rn type . Gsed to initialiUe the )ields o) a class 4. 9an "e overloaded *. 1) no constr%ctor is created then de)a%lt constr%ctor is created a%to&atically 6. 1) a para&eteriUed constr%ctor is created then de)a%lt constr%ctor is not created 2. Gse J2'2( tool o) J+, to vie< the contents inside a class J2'2( classna&e . 1) the arg%&ent and )ield na&e are sa&e then %se t6is o"$ect to re)er the )ields o) c%rrent class 4. To do so&e tas> <hile re:cla&ing the &e&ory space o) an o"$ect5 $ava provides special &ethod in 3"$ect class as )inaliUe() protected void )inaliUe() *. Ehile overriding &ethods o) a class into child class5 the scope can never "e red%ced a. )inaliUe() in child class &%st "e p &lic or protected. p%"lic void )inaliUe() I Syste&.o%t.println(L+oneL)H N Types of Fields i$ a class 1. 'aria"les a. int nH 2. 9onstants C )inal >ey<ord is %sed. 'al%e &%st "e assigned <hile declaration a. )inal do%"le piO .14H Types of "et6ods 1. 8eneral &ethods 2. Dinal &ethods C fi$al >ey<ord reF%ired. 9an never "e overridden . 2"stract &ethod C a&stract >ey<ord reF%ired. +o not have any "ody contents. 0ody is provided "y overriding in child class. 1) a class contains any a"stract &ethod then it &%st "e declared as a"stract. Types of 0lasses

1. 8eneral class 2. Dinal class C fi$al >ey<ord is %sed. 9an never "e inherited . 2"stract class C a&stract >ey<ord is %sed. 2l<ays inherited. 9an never "e instantiated. 2"stract class can or cannot have any a"stract &ethod. %ssig$"e$t 1. 9reate a class to hold t<o n%&"ers. /%&"ers can "e ta>en %sing constr%ctor or >ey"oard. 9reate the &ethods to operator on those n%&"ers as prod%ct()5 &od%l%s()5 greatest() 2. 9reate a class c%sto&er having acco%nt no5 na&e and "alance. 8et the data %sing constr%ctor. (rovide the &ethods to +eposit5 Eithdra< and 9hec> "alance. assign&ents]i&pecca"letrainers.co.in 2:-6-2008 !illars of ..!s 1. Encaps%lation a. 2ll &e&"ers &%st "e <ithin the sa&e "ody 2. 2"straction or +ata Miding a. (roviding controlling o) accessi"ility o) &e&"ers ". Java provides )o%r accessi"ility levels (scopes )or &e&"ers) i. (rivate C <ithin the class ii. (rotected C <ithin the class or in child class iii. (%"lic : any<here iv. +e)a%lt or 1nternal or Driend C <ithin the pac>age or )older . (oly&orphis& a. !%ltiple )or&s o) an ite&s ". Java provides only !ethod 3verloading to achieve the poly&orphis& c. !ethod 3verloading i. !%ltiple &ethods <ith the sa&e na&e "%t di))erent n%&"er o) arg%&ents or the type o) arg%&ents 4. 1nheritance a. (rovides re:%sa"ility o) code ". 3ne class can access &e&"ers o) other class "y inheriting it <ith e;te$ds >ey<ord class 2 I N class 0 e4tends 2 I N

class 9 e4tends 0 // 0 s%per class5 250 parent class I N : : : : Java provides only single inheritance Each $ava class in a child class o) 3"$ect class Gse t6is >ey<ord to re)er the o"$ect o) c%rrent class Gse s per >ey<ord to re)er o"$ect o) s%per class

.verridi$g 1. 9hanging contents o) a &ethod )ro& a class or inter)ace inside the child class 2. Scope o) the &ethod in child cane "e increased "%t cannot "e decreased 0reati$g 0 sto" !ac5age : Each pac>age is a )older contains classes and inter)aces )or speci)ic p%rpose : +i))erent pac>age can have classes <ith sa&e na&e : 9reate a )older to hold yo%r pac>ages o +#Q"1 p>g : 9reate a )older to p%t yo%r classes called as pac>age o +#Q"1 p>gQ&atc61: : 9reate the classes and save the& into "atch1 )older <ith pac5age co&&and on top pac>age "atch1 H class Test I N <si$g 0 sto" pac5ages : Set the classpat6 to access the classes in the pac>age SET 9B2SS(2TMOP9B2SS(2TMPHd#Q"1 p>g : 1&port the pac>age and %se its classes Distri& tio$ of !ac5ages 1. (ac>ages can "e distri"%ted in t<o )or&s a. 2s J2. (Java 2rchive) )ile ". 2s \1( )ile 2. Dor \1(5 Select all the pac>age and create a Uip )ile. /o< add this )ile into the classpath . Dor J2. )iles5 Gse J2..E6E %tility o) J+, a. Jar provides vario%s options i. c : 9reate ii. v : 'er"ose iii. t : Ta"%late iv. 4 : E4tract the J2. v. ) : to speci)y the )ile

E.g. 9reating a J2. )ile J2. cv) test.$ar @.gi) @.$ava @.class 8oto the +3S pro&pt and then goto the )older containing the pac>age (d#Q"1 p>g) 1ss%e the co&&and to create a $ar J2. cv) "1 .$ar . 24/6/2007 I$trod ctio$ to I$terfaces : 2 collection o) a"stract &ethods and )inal )ields : 2ll &ethods are p%"lic and a"stract "y de)a%lt and each )ield is p%"lic and )inal "y de)a%lt : (rovides a &ethod to i&ple&ent the &%ltiple inheritance in Java : 2 class can inherit any n%&"er o) inter)ace %sing i"ple"e$ts >ey<ord : Gse i$terface >ey<ord to declare the inter)aces : 2ll s%ch &ethods are overridden in so&e child class : (rovides controlling on the &ethods in a class : 1nter)aces can never "e instantiated "%t can give re)erence to their child classes : 3ne inter)ace can inherit other inter)aces %sing e;te$ds >ey<ord inter)ace 11 I N inter)ace 12 I N inter)ace 1 e4tends 11512 I N E;ceptio$ Ha$dli$g : 2 &ethod to pass error &essage )ro& the error occ%rred to the place <here &ethod get called : Each e4ception is a class inherited )ro& /ava.la$g.E;ceptio$ class : Every e4ception class has E4ception associated <ith the& o 13E4ception o Dor&atE4ception etc : Each e4ception class provides &ethods o String get!essage() o String toString() (de)a%lt )or all classes) o void printStac>Trace() C de)a%lt

: try I

Java provides )ive >ey<ords )or e4ception handling o try o catch o )inally o thro< o thro<s try:catch is "loc> to r%n the co&&ands and trap the e4ceptions

//state&ents Ncatch(e4ceptionclassna&e e4) I //reporting N : one try can have &any catch state&ents : )inally is a "loc> to al<ays e4ec%te so&e state&ents irrespective o) e4ception try I Ncatch() I N )inally I N 0reati$g c sto" e;ceptio$s 1. 9reate a class and inherit )ro& E4ception class 2. 3verride the &ethods toString() and get!essage() to provide the &essaging 26-6-2008 (tri$g Ha$dli$g : To do so&e processing on Strings : 2ll strings are &anaged "y (tri$g class : (tri$g class is immutable (non:e4panda"le or )i4ed siUe) : Java provides another class (tri$g= ffer as mutable to e4pand data in c%rrent location : Java *.0 introd%ced one &ore class (tri$g= ilder )or sa&e p%rpose o) (tri$g= ffer : String can "e creates "y t<o <ays o String Biteral String s1OV.a>eshVH String s2OV.a>eshVH

: :

Syste&.o%t.println(s1OOs2)H//val%e co&parison : Tr%e o String 3"$ects String s1One< String(W.a>eshV)H String s2One< String(W.a>eshV)H Syste&.o%t.println(s1OOs2)H//.e)erence co&parison C Dalse !ethods o) String class o toGpper9ase() o toBo<er9ase() o length() o s%"string(start5end) // n%&"er o) characters <ill "e end:start o s%"string(start) // till end o inde43)(String s) // to search a string in another string. .et%rns :1 i) not )o%nd o inde43)(int o))set5 String s) // to search a string in another string. .et%rns :1 i) not )o%nd o last1nde43)(String s) // to search a string in another string. .et%rns :1 i) not )o%nd o last1nde43)(int o))set5 String s) // to search a string in another string. .et%rns :1 i) not )o%nd o char2t(int inde4) String0%))er class provides a &ethod called append() to add data dyna&ically 1t also provides reverse() &ethod and toString() to ret%rn the string data

+i))erence "et<een a"stract class and inter)aceX

%pplicatio$s of Java
,<I Develop"e$ts si$g %#T '%&stract #i$dow Tool5it+ : Java provides /ava.awt pac>age )or all 8G1 related classes and inter)aces : 1t provides t<o &ain >ind o) classes o Maving 8G1 2ppearance 9o&ponents 0%tton5 9hoice5 9hec>0o45 Scroll"ar5 Te4tDield etc. 9ontainers Dra&e5 +ialog5 2pplet5 (anel etc. o /on 8G1 2ppearance Dont5 9olor5 +i&ension etc. : 2ll co&ponents and containers are inherited )ro& an a"stract class called 0o"po$e$t : 0o"po$e$t class provides all co&&on &ethods applica"le to all the co&ponent and containers o void setSiUe(int <idth5 int height)

o void set'isi"le("oolean ") o void set0ac>gro%nd(9olor c) 0o$tai$er class provides co&&on &ethods )or all the containers o void setBayo%t(Bayo%t!anager l&) o void add(9o&ponent c) o void re&ove(9o&ponent c)

: Types of ,<I Develop"e$t 1. Java 2pplications 2. Java 2pplets 2 progra& to "e called 8G1 application &%st inherit )ro& Fra"e class )or $ava.a<t paca>ge 2 progra& to "e called an 2pplet &%st inherit )ro& %pplet class o) $ava.applet pac>age Dra&e class : (rovides top level container )or applications : !ethods o void setTitle(String s) ,e$eral ,<I 0o"po$e$ts Ba"el class : To p%t so&e static te4t or )or &essaging : 9onstr%ctors o Ba"el() o Ba"el(String te4t) : !ethods o void setTe4t(String te4t) o String getTe4t() Te4tDield class : Gsed )or single line or pass<ord )ield : 9onstr%ctors o Te4tDield(int siUe) : !ethods o void setTe4t(String te4t) o String getTe4t() o void setEcho9har(char ch) Te4t2rea class : Gsed )or &%ltiline te4t"o4 : 9onstr%ctors o Te4t2rea(int ro<s5 int col%&ns)

!ethods o void setTe4t(String te4t) o String getTe4t() 0%tton class : To create a p%sh "%tton : 9onstr%ctor o 0%tton(String la"el) : !ethod o void setBa"el(String la"el) o String getBa"el() o void add2ctionBistener(o"$ect) 2T/6/2007 Bayo%t!anagers : Special classes that control the place&ent o) co&ponents in a container : 2ll are inherited )ro& Bayo%t!anager class : They are o 0orderBayo%t +e)a%lt )or Dra&e +ivides the screen into * sections East Eest /orth So%th 9enter +e)a%lt is center +e)ine the section <hile adding the ite&s add(9o&ponent c5 String section) e.g. o add(t4t/%&5V/orthV)H o Dlo<Bayo%t +e)a%lt )or 2pplet (lace co&ponents le)t to right then top to "otto& Gse setBayo%t() &ethod setBayo%t(ne< Dlo<Bayo%t())H o 8ridBayo%t o 9ardBayo%t o 8rid0agBayo%t /ote# To place the controls as per yo%r choice5 re&ove the layo%t &anagers %sing &ethods setBayo%t(n%ll)H

Gse set0o%nds() &ethod o) setBocation() and setSiUe() &ethods set0o%nds(int 45 int y5 int <5 int h) setBocation(int 45 int y) setSiUe(int <5 int h)

Eve$t Ha$dli$g i$ Java : Event handling in Java called as Event +elegation !odel : Each event in $ava is an a"stract &ethod de)ined in so&e inter)aces called Listeners. o ,eyBistener o !o%seBistener o !o%se!otionBistener o Eindo<Bistener o 2d$%st&entBistener o 1te&Bistener o 2ctionBistener : 2ll s%ch inter)aces are provides in /ava.awt.eve$t pac>age : To %se the events on a co&ponent5 yo% need to register the event handler : Gse add666Bistener() &ethod o add,eyBistener(o"$ect o) class having its &ethod) o add2ctionBistener(o"$ect o) class having its &ethod) : +i))erent &ethod in listeners o 2ctionBistener p%"lic void action(er)or&ed(2ctionEvent e) Mere 2ctionEvent is the delegate Gse its &ethods o 3"$ect getSo%rce() o String get2ction9o&&and() o !o%se!otionBistener p%"lic void &o%se!oved(!o%seEvent e) p%"lic void &o%se+ragged(!o%seEvent e) Gse &ethods o) !o%seEvent o 3"$ect getSo%rce() o int get6() o int get^() o ,eyBistener p%"lic void >eyTyped(,eyEvent e) p%"lic void >ey(ressed(,eyEvent e) p%"lic void >ey.eleased(,eyEvent e) Gse &ethods o) ,eyEvent o 3"$ect getSo%rce() o char get,ey9har()

o void cons%&e() I$trod ctio$ to %dapters : Special classes corresponding to listeners <ith pre:overridden &ethods o) listeners : Bisteners having only one &ethod5 do not have corresponding adapters o ,eyBistener ,ey2dapter o Eindo<Bistener Eindo<2dapter I$$er class : 2 class <ithin a class <hich can access all the &e&"ers o) containing class 2nony&o%s class : 2 class <itho%t any na&e is called as anony&o%s class : 3verride the &ethods <hile registering the event %ssig$"e$ts 9reate a )or& and get /a&e5 0asic and E&ail o) a person. 'alidate the data inp%t )or all three. (rint the )ollo<ing /a&e # E&ail # 0asic # Erite the sa&e progra& %sing three &ethods o) event handling 1. 3verriding in Sa&e 9lass 2. 3verriding in 1nner 9lass . 3verriding in 2nony&o%s 9lass :0-6-2008 Eor>ing <ith 2pplets : Java applets are the $ava progra&s that r%n inside the "ro<ser "y e&"edding into MT!B lang%age tags MT!B : : : : 2 )or&atting lang%age )ro& E 9 (Eorld Eide Ee" 9onsorti%&) <ith latest version 4.01 (< .org) (< schools.co&) 1t contains a )i4ed set o) co&&ands called Tags <ith additional properties called attri& tes Dile e4tension can "e .ht& or .ht&l 9ase in:sensitive

MT!B )ile Str%ct%re RMT!BS RME2+S

R/ME2+S R03+^S R/03+^S R/MT!BS TagX Tag is special code enclosed in R and S de)ined "y E 9. e.g RMT!BSR/MT!BS5 RM1SR/M1S5 R1!8S etc. Types o) TagsX 1. (aired Tags a. Maving opening and closing "oth i. Rh1SR/h1S5 R"SR/"S5 RiSR/iS etc. 2. Sing%lar Tags a. Maving only opening section i. R0.S 5 R1!8S 5 R!ET2S5 R08S3G/+S etc. %ttri& tes : (roperties <ritten in opening section o) tag separated "y space : E.g. R03+^S tag attri"%tes o 0gcolorOVcolorna&e or code )or "ac>gro%ndV o Te4tOVcolorna&e or code )or )oregro%ndV o 0ac>gro%ndOVi&age )ilena&eV R03+^ te4tOVredV "gcolorOV"l%eVS R/03+^S HT>4 Editors : Special so)t<are )or <e"page develop&ent !S Dront(age !acro&edia +rea&<eaver Dirst (age Mot +og I"porta$t 1otes? 1. To &erge the applets into MT!B code5 R2((BETSR/2((BETS tag is reF%ired <ith its s%" tag R(2.2!S tag 2ttri"%tes o) R2ppletS 9odeOVclass )ile na&eV EidthOV4V MeightOVyV 9ode"aseOV)older containing class )ilesV 2rchiveOV$ar )ile na&eV R(2.2!S tag sends data to the class )ile 2ttri"%tes

/a&eOVpara&eter na&eV 'al%eOVpara&eter val%eV . 2pplets do not contain any &ain() &ethod or the constr%ctor 4. 2ll applets &%st "e p%"lic *. Each $ava progra& to "e called as an applet &%st inherit )ro& %pplet class o) /ava.applet pac>age a. 2pplet class provides vario%s &ethods >et6ods of %pplet class : p%"lic void init() C si&ilar to constr%ctor5 e4ec%tes only )or once : p%"lic void paint(8raphics g) : p%"lic void repaint() >et6ods of ,rap6ics class : 8raphics is a class )ro& $ava.a<t pac>age to dra< strings5 i&ages5 shapes etc. o p%"lic void dra<String(String s5 int 45 int y) o p%"lic void dra<1&age(1&age i&g5 int 45 int y5 1&age3"server o"$) o p%"lic void dra<1&age(1&age i&g5 int 45 int y5 int <5 int h5 1&age3"server o"$)

2 $$i$g t6e %pplets 1. Gsing 0ro<ser 2. Gsing 2pplet'ie<er Tool o) J+, !laci$g HT>4 a$d 04%(( file i$ differe$t folders : Gse code"ase attri"%te o) R2ppletS tag E4a&ple R2pplet codeOL8G12pplet1L <idthOL200L heightOL200L code"aseOLclassesLS R/appletS !assi$g data to %pplets fro" @%!!4ETA tag si$g @!%2%>A s & tag : Ehen data is passed to the applets5 it is received %sing get!ara"eter'+ &ethod o) 2pplet class String get(ara&eter(Wpara&na&eV) <si$g I"ages i$to %pplets : 0e)ore %sing the i&ages5 its location o) place&ent is i&portant : S%n provides t<o &ethods to >no< a"o%t the path o) <e"site )or MT!B or class )ile o G.B get+oc%&ent0ase() C ret%rn path )or MT!B )ile o G.B get9ode0ase() C ret%rn path )or class )ile : Gse getI"age'+ &ethod to get an i&age into "%))er and pass it to 8raphics class to dra< on screen

1&age i&gOget1&age(G.B path5 String )ilena&e) :-8-2008 <si$g % dio i$to %pplets '.wavB ."idB .a + : Gse get2%dio9lip() &ethod o) 2pplet class and get re)erence into 2%dio9lip class o) $av.applet 2%dio9lip acOget2%dio9lip(get+oc%&ent0ase()5Vtest.&idV)H : Gse &ethods o) 2%dio9lip clas o void play() o void stop()

<si$g J%2 files i$ %pplets : (lace all the )iles into a J2. and %se 2.9M1'E o) R2((BETS tag to de)ine the J2. 0reati$g >e$ s 1. +rop +o<n !en% a. 9reate a >e$ =ar class o"$ect i. 9reate >e$ class o"$ects 1. 9reate >e$ Ite" class o"$ects ". Set the !en%0ar on )ra&e %sing set!en%0ar() &ethod o) Dra&e class c. (lace the 2ctionBistener on !en%1te& 2. (op%p!en%s :9reate an o"$ect o) !op p>e$ class and add !en% or !en%1te& or "oth : To sho< the pop%p&en% %se !o%seBistener?s &o%se.ealeased() &ethod : 9hec> the right clic> %sing is!op pTrigger'+ &ethod o) !o%seEvent class : Gse sho<() &ethod o) (op%p!en% class to sho< the &en% : 2dd the pop%p&en% to the )ra&e (op%p!en% p&H p&.sho<(e.get9o&ponent()5 e.get6()5 e.get^())H 0reati$g 0o"&o=o; : : : : 2llo<s to select only one ite& Gse 06oice class Gse add() &ethod to add the ite&s Gse getSelected1te&() to pic> the c%rrently selected ite&

9reating Bist0o4 : 2llo<s to select single or &%ltiple ite&s : Gse 4ist class o Bist(int ite&s) o Bist(int ite&s5 "oolean &%ltiple) : Gse add() &ethod to add ite&s : Gse getSelected1te&() or getSelected1te&s() 0reati$g 06ec5&o; co$trol : : To select all or none Gse 9hec>"o4 class o 9hec>"o4() o 9hec>"o4(String caption) o 9hec>0o4(String caption5 "oolean chec>ed) Gse &oolea$ get(tate'+ &ethod to chec> the state

9reating radio "%ttons : Gse the sa&e 06ec5&o; class <ith 06ec5&o;,ro p : Dirst create a 9hec>"o48ro%p and then the 9hec>"o4 o 9hec>"o4(String caption5 9hec>"o48ro%p cg5 "oolean state) : Gse getState() to chec> the state C-8-2008 J+09 (Java +ata"ase 9onnectivity) : Java is a )ront end that can "e connected <ith any >ind o) data"ase : 2ll classes and inter)aces are provides in t<o pac>ages o $ava.sFl o $ava4.sFl (teps to se t6e JD=0 1. 9hec> )or the data"ase a. !S 2ccess ". !y SFl c. 3racle 2. 9hec> )or the driver class )ile a. S%n provides a de)a%lt driver called J+09:3+09 0ridge <ith class )ile s $./d&c.od&c.Jd&c.&dcDriver ". This class is located in rt.$ar o) J.E c. 1t needs a +ata So%rce /a&e (+S/) . Boad the +river a. 9lass.)or/a&e(Wdriver classV)H 3r +river!anager.register+river(ne< driverclass())H 3r Syste&.set(roperty(W$d"c.driversV5VdriverclassV)

4. Esta"lish the connection <ith the data"ase and get re)erence into a 9onnection inter)ace 9onnection cnO+river!anager.get9onnection(W%rlV5VloginV5Vpass<ordV)H *. +epending on type o) state&ent5 create any o) three o"$ect State&ent stOcn.createState&ent()H 3r (reparedState&ent psOcn.prepareState&ent(sFl)H 3r 9alla"leState&ent csOcn.prepare9all(WIcall proced%rena&eNV)H 6. 9hec> the S_B state&ent type to "e SEBE9T or /on:Select. Gse e4ec%teGpdate()5 e4ec%te_%ery()5 e4ec%te() &ethods Dor State&ent int e4ec%teGpdate(String sFl) .es%ltSet e4ec%te_%ery(String sFl) Dor (reparedState&ent int e4ec%teGpdate() .es%ltSet e4ec%te_%ery() Dor 9alla"leState&ent void e4ec%te() 7. 9lose the connection cn.close()H E4a&ple %sing !S 2ccess as data"ase 1. +ata"ase !S 2ccess 2. +river s%n.$d"c.od"c.Jd"c3d"c+river . Boad the +river 4. 9hec> )or the G.B a. /d&c?od&c?@dsnna&eS &. /d&c?od&c?&1: *. Esta"lish the connection Gsing !ySFl as +ata"ase 1. +river co&.&ysFl.$d"c.+river 2. G.B $d"c#&ysFl#//localhost# 06/"atch1 Xa%to.econnectOtr%e <si$g !lace6olders : Ehile &a>ing S_B state&ents5 do not provide the act%al data "%t X : Gse set666(val%e) &ethods to pass the val%es

o void set1nt(int inde4no5 int val%e) o void setString(int inde4no5 String val%e) 2llo<ed <ith (reparedState&ent and 9alla"leState&ent

Fetc6i$g t6e 2ecords : 9reate SEBE9T state&ent and pass the res%lt to so&e .es%ltSet : !ethods o) .es%ltSet o Gse get666(int col%&nno or String )ieldna&e) C col%&ns no. starts <ith 1 o "oolean ne4t() :: !ove to ne4t record o "oolean previo%s() C !ove to previo%s record o "oolean )irst() o "oolean last() 0reati$g (crolla&le 2es lt(ets : 2llo<s to &ove records to and )ro : (rovide the constants )ro& .es%ltSet <hile creating State&ent or (reparedState&ent
(reparedState&ent psOcn.prepareState&ent(sFl5.es%ltSet.T^(E`S9.3BB`1/SE/S1T1'E5.es%ltSet.93/9G.`.E2+`3/ B^)H %ssig$"e$t : 9reate a 8G1 application to sho< the records <ith )o%r "%ttons Dirst5 Bast5 (rev5 /e4t <si$g >etaData : +ata over the data is called !eta+ata : Dor a ta"le5 )ield na&es5 datatypes and their siUes are the &eta in)or&ation : 2ll ta"les in data"ase )or connections is again &eta in)or&ation : Java provides t<o classes o .es%ltSet!eta+ata o +ata"ase!eta+ata : Gse getMetaData() &ethod )ro& .es%ltSet )or .es%ltSet!eta+ata and )ro& 9onnection )or +ata"ase!eta+ata >a$agi$g Tra$sactio$s : 9onnection inter)ace provides three &ethods o set2%to9o&&it("oolean state) :: de)a%lt is tr%e o co&&it() C Ehen all codes e4ec%ted o roll"ac>() C Ehen so&e e4ception occ%rs 8-8-2008

4oadi$g Drivers si$g (yste" !roperties Syste&.set(roperty(W$d"c.driversV5VdriverclassV)H (tori$g i$for"atio$ a&o t driverB rlB logi$ a$d password o tside t6e progra" : Store the in)or&ation in a )ile <ith >eyOval%e relationship

//data"ase.properties driverOs%n.$d"c.od"c.Jd"c3d"c+river %rlO$d"c#od"c#"1 loginO passO : .ead the )ile )ro& dis> to &e&ory %sing FileI$p t(trea" class o) $ava.io pac>age

Dile1np%tStrea& )One< Dile1np%tStrea&(Wdata"ase.propertiesV)H : To separate the data )or di))erent properties5 %se !roperties class o) $ava.%til pac>age <ith load'+ &ethod o Gse get(roperty() &ethod to get data )or di))erent properties

(roperties pOne< (roperties()H p.load())H String drvOp.get(roperty(WdriverV)H String %rlOp.get(roperty(W%rlV)H <si$g (tored !roced res : 2 proced%re created on data"ase side %sing a lang%age : (B/S_B )or 3racle : T:S_B )or !S SFl !4-(D4 code 9reate or replace proced%re Save+ata ( n 1/ e&p1.na&ePT^(E5 e 1/ e&p1.e&ailPT^(E ) 1S 0E81/ 1/SE.T 1/T3 e&p1 '2BGES (n5e)H E/+H / T:S_B 9ode 9.E2TE (.39E+G.E Save+ata ]na&e varchar( *0)5 ]e&ail varchar(*0)

2S 1nsert into e&p val%es(]na&e5 ]e&ail) 83 <si$g (D4 (erver : Start !anage&ent 9onsole o) !icroso)t S_B Server 200* : 9reate a +ata"ase : 9reate Ta"les : 9lic> on /e< _%ery and Erite yo%r proced%re : Select the (roced%re and press D* to e4ec%te : (roced%re has "een created 0alli$g a stored proced re : 9reate a 9alla"leState&ent and %se e4ec%te() &ethod 9alla"leState&ent csOcn.prepare9all(LIcall Save+ata(X5X)NL)H cs.setString(15na&e)H cs.setString(25e&ail)H cs.e4ec%te()H 10-8-2008 S<ings : : : : : 2dvance graphics5 independent o) 3S (ac>age %sed $ava4.s<ing and $ava4.s<ing.event !%ltiple loo> and )eels 2ll co&ponents provides tooltip o void setToolTipTe4t(String tip) 2ll s<ing co&ponents provides a <ay to p%t i&ages on the& thro%gh Ico$ inter)ace. Gse an o"$ect o) I"ageIco$ class to provide an i&age

J9olor9hooser class : To display the set o) colors and allo<s to create c%sto& color : (rovides a static &ethod o static 9olor sho<+ialog(Dra&e )5 String caption5 9olor de)a%lcolor) J3ption(ane class : (rovides vario%s dialogs )or o !essage o +ata 1np%t and Selection o _%erying : 1t provides static &ethods o static void sho<!essage+ialog() sho<!essage+ialog(9o&ponent parent5 3"$ect &essage5 String title5 int i&ageType5 1con icon)

o static String sho<1np%t+ialog() o string int sho<9on)ir&+ialog() Gse i&age constants o E..3.`!ESS28E o 1/D3.!2T13/`!ESS28E o E2./1/8`!ESS28E o _GEST13/`!ESS28E o (B21/`!ESS28E Gse "%tton constants o +ED2GBT`3(T13/ o ^ES`/3`3(T13/ o ^ES`/3`92/9EB`3(T13/ o 3,`92/9EB`3(T13/ .es%lts to co&pare )ro& con)ir&ation dialogs o ^ES`3(T13/ o /3`3(T13/ o 92/9EB`3(T13/ o 3,`3(T13/ o 9B3SE+`3(T13/

Setting Boo> and Deel : Java provide three loo> and )eel "y de)a%lt o !etal (de)a%lt) o !oti) C )or lin%4 and %ni4 o Eindo< : Boo>s are set %sing a class called <I>a$ager and applied %sing class (wi$g<tilities : Gse setBoo>2ndDeel() &ethod G1!anager o G1!anager.setBoo>2ndDeel(L$ava4.s<ing.pla).&etal.!etalBoo>2ndD eelL)H o G1!anager.setBoo>2ndDeel(Lco&.s%n.$ava.s<ing.pla).&oti).!oti)Bo o>2ndDeelL)H o G1!anager.setBoo>2ndDeel(Lco&.s%n.$ava.s<ing.pla).<indo<s.Eind o<sBoo>2ndDeelL)H : +e)ine the co&ponent to apply the loo> and )eel to S<ingGtilities o S<ingGtilities.%pdate9o&ponentTreeG1(get9ontent(ane())H JTa""ed(ane class : To create a ta""ed pane )or &ore co&ponents in less space : Each ta" can have only one co&ponent5 so %se the J(anel to hold ite&s and place the& on Ta" : (rovides &ethod o void addTa"(String caption5 9o&ponent c) JSlider class

: : :

To create a slide to a select a val%e )ro& &ini&%& to &a4i&%& 9onstr%ctor o JSlider(int direction5 int start5 int end5 int de)a%ltval%e) Bistener %sed o 9hangeBistener p%"lic void state9hanged(9hangeEvent e) !ethdod o void set!ini&%&(int val%e) o int get!ini&%&() o void set!a4i&%&(int val%e) o int get!a4i&%&() o void set'al%e(int n) o int get'al%e() o void setE4tent(int val%e) o void set!a$orTic>Spacing(int n) o void set!inorTic>Spacing(int n) o void set(aintTic>s("oolean displaytic>s) o void set(aintBa"els("oolean displayte4tla"els)

12-8-2008 JTe4t2rea class : Dor &%lti:line te4t : JTe4t2rea(int ro<s5 int col%&ns) : Gse a J(croll!a$e to provide the scroll "ars JScroll(ane class : (rovides scroll"ar )or any thing 9reating !en%s )ro& J!en%5 J!en%0ar and J!en%1te& : J!en% and J!en%1te& provides so&e &ethods o set!ne&onic(char ch or virt%al >ey) To &a>e a hot >ey : 'irt%al >ey a constant given to so&e >ey inside the ,eyEvent class o ,eyEvent.',`2 o ,eyEvent.',`029,S(29E : To apply the shortc%t co&&and apply the Key(tro5e class o"$ect to the J!en%1te& o"$ects %sing o set2ccelarator(,eyStro>e >s) &ethod : ,eyStro>e class provides static &ethod get,eyStro>e() o Select the >ey and the !as> ,ey !as> ,eys can "e 2lt5 Shi)t or 9trl provided in Event class Event.9T.B`!2S, Event.2BT`!2S, Event.SM1DT`!2S,

,eyStro>e >sO,eyStro>e.get,eyStro>e(,eyEvent.',`/5Event.9T.B`!2S,)H &n%/e<.set2ccelerator(>s)H JTool0ar class : To create a tool"ar : 9ontains a collection o) JTool0ar0%tton class o"$ects : J1nternalDra&e class : (rovide a )ra&e <ithin a )ra&e : 9onstr%ctor J1nternalDra&e(String title5 "oolean resiUa"le5 "oolean closa"le5 "oolean &a4i&iUa"le5 "oolean iconi)ia"le) : !ethods o setDra&e1con(1con i&age) : 2dd all internal )ra&es into a JDes5top!a$e container : 2dd JDes5top!a$e into Dra&e JDile9hooser class : (rovides selection o) a )ile o set9%rrent+irectory(Dile )) o setDileDilter(DileDilter )) o sho<3pen+ialog(parent) o String getSelectedDile() 18-8-2008 File Ha$dli$g i$ Java : (ac>age %sed $ava.io : Dile class o To <or> <ith e4isting )iles and )older o 2llo<s to create5 delete and rena&e )or )iles and )olders o Selection o) )iles and s%")olders <ithin a )older : Eor>ing <ith )iles o Te4t !ode +irectly <or>s <ith strings Dile.eader DileEriter o 0inary !ode Eor>s <ith "ytes Dile1np%tStrea& Dile3%tp%tStrea& File class

9onstr%ctor o Dile(String )ilena&e or )older <ith path) o Dile(String )older5 String )ile) !ethods o "oolean e4ists() o "oolean isDile() o "oolean is+irectory() o String JKlist() o String JKlist(Dilena&eDilter )) Dor selected set o) )iles Dilena&eDilter is an inter)ace having accept() &ethod <hich &%st "e overridden o long length() o long last!odi)ied() .et%rns a n%&"er that represents n%&"er o) &illiseconds elapsed )ro& 1/1/1;70 at 12 2! to the )ile get created Gse +ate() )ro& $ava.%til pac>age to convert in act%al date o "oolean &>dir() 9reate a directory o "oolean &>dirs() 9reates a directory str%ct%re o "oolean delete() o "oolean rena&eTo(Dile ))

#or5i$g wit6 File2eader a$d File#riter : To create )iles %se DileEriter o DileEriter(String )ilena&e) o DileEriter(Dile )) o !ethods <rite(String s) close() To read the )ile %se Dile.eader class o Dile.eader(String s) o Dile.eader(Dile )) o (ass re)erence to the 0%))ered.eader and read the contents

#or5i$g wit6 FileI$p t(trea" a$d File. tp t(trea" : To create )ile %se Dile3%tp%tStrea& o Dile3%tp%tStrea&(String )ilena&e( o Dile3%tp%tStrea&(Dile )) o <rite("yte ") o <rite("yte JK") 9onvert a string into "yte array "e)ore saving to dis>

String class provides get0ytes() &ethod "yte JK"Os.get0ytes()H Ehile reading read the data "yte "y "yte

/e4t topic !%ltithreading 17-8-2008 Thread is s%":process <ithin a process called light process. 2 thread sched%ler is %sed sched%le the <or>ing o) threads. Java provides /ava.la$g.T6read class to create the thread and 2 $$a&le inter)ace providing r $'+ &ethod to give <or>ing )or threads T6read class : 9onstr%ctors Thread(.%nna"le r) Thread(.%nna"le r5 String tna&e) : !ethods static Thread c%rrentThread() String get/a&e() void set/a&e(String tna&e) int get(riority() void set(riority(int n) // &inO1 &a4O10 de)a%lt is * void start() // to send the thread in Thread _%e%e void r%n() // inherited )ro& .%nna"le <ith "lan> "ody static void sleep(int &s) // to s%spend a thread )or given ti&e give control to ne4t thread in F%e%e static void sleep(int &s5 int ns) thro<s 1nterr%ptedE4ception static void s%spend() static void res%&e() static void <ait() static void noti)y() static void stop() 0y de)a%lt all Java progra&s are single threaded. 3ne thread is al<ays present called "ai$ thread. Threads can "e gro%ped and de)a%lt gro%p is &ain 4ife 0ycle of T6reads 1. 0orn state a. Ehen thread is created

2. .eady State a. Ehen start() &ethod is called . .%nning State a. E4ec%tion o) r%n() 4. 0loc> State a. Ehen thread goes to Sleep5 Eait or S%spend sit%ation *. +ead state a. Ehen <or> is )inished to stop is called (y$c6ro$iEatio$ : Ehen t<o or &ore threads try to %pdate a co&&on reso%rce (varia"le) then the reso%rce &%st "e protected : Java provide sy$c6ro$iEed >ey<ord to handle the deadloc>s : 1t can "e %sed <ith the &ethods or as "loc> i) the &ethods are overridden )ro& other classes synchroniUed Rret%rntypeS R&ethodna&eS() I N Rret%rntypeS R&ethodna&eS() I State&entsH synchroniUed(this) I //state&ents N //state&ents N : SynchroniUation provide a loc> to the thread called &%te4 (!%t%al E4cl%sive Boc>)

I$ter T6read 0o"" $icatio$ : Ehen one thread needs data )ro& other thread and data is not availa"le then the thread has to <ait de)ined "y wait'+ &ethod : Ehen data is availa"le a noti)ication is done <ith $otify'+ &ethod 2ssign&ent 1. 9reate a 8G1 (rogra& <ith one la"el and sho< the ti&e a)ter every second 21-8-200F

Gsing $oin() &ethod : To hold the thread in &e&ory %ntil depending threads get ter&inated T1.$oin()H// )inished end T2.$oin()H//)inished second last T .$oin()H //)inished )irst <si$g yield'+ "et6od : To provide control <hile r%nning a progra& to other processes or thread even a)ter loop is in)inite Thread.yield()H (etti$g a t6read as dae"o$ t6read : : 2 thread that r%n in "ac>gro%nd void set+ae&on("oolean ")

Thread tOne< Thread(this)H t.set+ae&on(tr%e)H t.start()H i)(t.is+ae&on()) I t.set+ae&on()alse)H N 0reati$g E;ec ta&le Jar i$ Java : : : 9reate a &ani)est )ile providing in)or&ation a"o%t the )irst class to "e started !ani)est )ile (.&)t) is a &eta )ile containing start%p class in)or&ation 9reate the )ollo<ing entry !ain:9lass# classna&e : /o< create a $ar <ith cv&) or cv)& option

J2. cv&) !en%Test.&)t !en%Test.$ar !enTest@.@ J2. cv)& !en%Test.$ar !en%Test.&)t !enTest@.@ Java 1etwor5i$g : 2 &ethod to provide co&&%nication "et<een t<o &achines

: :

: :

2ll classes are provided in /ava.$et pac>age /et<or>ing can "e o) t<o types o T9(/1( "ased connectivity 9onnection 3riented .elia"le o G+( "ased connectivity 9onnection Bess Gn:relia"le To set%p the co&&%nication <e need t<o >ind o) classes o T9(/1( Server Side ServerSoc>et 9lient Side Soc>et o G+( Server Side +atagra&Soc>et 9lient Side +atagra&Soc>et Every server &%st >no< its port n%&"er and every client &%st >no< the 1( 2ddress or +/S along <ith the port n%&"er o) the server (ort n%&"er is a logical n%&"er to identi)y di))erent client/server applications on &achine. 2 &achine can have &a4i&%& o) 6** * ports. o MTT( T0 o DT( 21 o S!T( 2* o 3racle 1*21 o !ySFl 06 o To&cat T0T0 o .!1 10;; Etc.

06ec5i$g t6e availa&ility of port : Every c%rrent &achine has its na&e as localhost and 1( 2ddress 127.0.0.1 : Gse (oc5et class to set%p the connection o Soc>et(String dns or ipaddress5 int port) o 1t so&e server is availa"le on given port the connection is easta"lished other<ise thro<s 13E4ception <si$g (erver(oc5et class : Gsed to set%p a server that can serve the clients ServerSoc>et(int port)

(rovides a &ethod accept() Soc>et accept()H

E4a&ple ServerSoc>et sOne< ServerSoc>et( 0)H Soc>et cOs.accept()H 0lie$t (ide wit6 (oc5et Soc>et sOne< Soc>et(WipaddressV5 0)H Soc>et class provides &ethods 1np%tStrea& get1np%tStrea&()H 3%p%tStrea& get3%tp%tStrea&() To send data in string )or&at5 create an o"$ect o) (rintEriter class (rintEriter o%tOne< (rintEriter(c.get3%p%tStrea&()5 tr%e)H Gsing print()5 print)()5 println() &ethod to send data. To read data %se get1np%tStrea&() &ethod at the place o) Syste&.in 0%))ered.eader "rOne< 0%))ered.eader(ne< 1np%tStrea&.eader(s.get1np%tStrea&())H 24-8-2008 Eor>ing <ith G+( 9lasses %sed +atagra&Soc>et +atagra&(ac>et 1net2ddress 1net2ddress hold in)or&ation a"o%t a &achine and provides special static &ethods that ret%rn o"$ect o) its o<n class. S%ch &ethod are called as )actory &ethods. p%"lic static 1net2ddress getBocalMost() p%"lic static 1net2ddress get0y/a&e(String dns) p%"lic static 1net2ddressJK get2ll0y/a&e(String dns) +atagra&(ac>et creates a pac>et

+atagra&(ac>et("yte JK"5 int siUe) +atagra&(ac>et("yte JK"5 int siUe5 1net2ddress ia5 int port) "yte JKget+ata() int getBength() +atagra&Soc>et class : %sed to send o) receive the data +atagra&Soc>et(int port) !ethod send(+atagra&(ac>et p) receive(+atagra&(ac>et p) #e& 1etwor5i$g : (rovides co&&%nication )ro& a &achine to <e"page or applet to &achine : 9lasses %sed o G.B G.B(string %rl) G.B9onnection open9onnection() o G.B9onnection (sa&e as Soc>et )or local &achine) 1np%tStrea& get1np%tStrea&() 3%tp%tStrea& get3%tp%tStrea&() 0ollectio$s : +yna&ic set o) o"$ects : Java provides t<o >inds o) collections o Begacy 9ollections o 9ollection Dra&e<or> : Begacy collections o 'ector C single set o) val%es 'ector() void add1te&(3"$ect 4) int siUe() 3"$ect ele&ent2t(int inde4) o Mashta"le C >ey/val%e pairs Mashta"le() void p%t(String >ey5 3"$ect val%e) 3"$ect get(String >ey) En%&erator >eys() o En%&eration inter)ace "oolean has!oreEle&ents() 3"$ect ne4tEle&ent()

/ote# %se instanceof operator to >no< the type o) an ele&ent in collection 26-8-2008 #or5i$g wit6 0ollectio$ Fra"ewor5 : : 2 set o) inter)aces and classes that <or> %nder so&e r%les called 9ollection Dra&e<or> They designed )o%r &ain inter)aces o 9ollection inter)ace Top level inter)aces )or all collections o Bist : an inter)ace to <or> <ith single set o) o"$ects 2llo<s d%plicates o Set C an inter)aces to <or> <ith single set o) %niF%e o"$ect o !ap C an inter)aces to <or> <ith ,ey/(air o"$ects 9lasses in 9ollections o 2rrayBist o Bin>edBist Dro& 1terator inter)ace in place o) En%&eration o "oolean has/e4t() o 3"$ect ne4t()

% to=o;i$g a$d % toG<$&o;i$g : 9onversion )ro& val%e type to re)erence type is called as 2%to0o4ing 1nteger 4O*6H : 9onversion )ro& re)erence to val%e type is called as 2%to:Gn"o4ing int pO4H ,e$erics : Si&ilar to te&plates in 977 : (rovides datatype o) &e&"ers <hile creating the o"$ects 9lassna&e RdatatypeS re)na&eOne< 9onstr%ctorRdatatypeS()H /ote# 2ll collections s%pport the generics <si$g E$ "erator : Gse e$ " >ey<ord to de)ine the en%&erators en%& en%&eratorna&eIna&e15 na&e25A..N I"porti$g static fields of a class

Gse static >ey<ord <ith i&port

i&port static pac>age.class.@H E4a&ple i&port static $ava.lang.!ath.(1H i&port static $ava.a<t.9olor.@H <si$g varia&le $ "&er of arg "e$ts i$ "et6ods : %se A to de)ine a varia"le to hold &%ltiple val%es 0reati$g a !rocess fro" a /ava progra" Gse (rocess0%ilder class )ro& $ava.io pac>age : Gse start() &ethod to start the process 2;/7/2007 <tilities : (rovides general classes )or di))erent operations

Date class : To <or> <ith syste& date or c%sto& date : 9onstr%ctor o +ate() C syste& date o +ate(int y5 int &5 int d) C c%sto& date : !ethod o get+ate() o get!onth() C starts <ith 0 o get^ear() C ret%rns year a)ter 1;00 o getMo%rs() o get!in%tes() o getSeconds() StringTo>eniUer class : To "rea> a string into di))erent parts "ased on a given to>ens : 9onstr%ctor o StringTo>eniUer(String s5 String to>ens) : !ethods o "oolean has!oreTo>ens() o String ne4tTo>en()

Ti"er &ased %pplicatio$s wit6 Ti"er a$d Ti"erTas5 class : : Ti&erTas> provides a r%n() to provide the <or>ing Ti&er class provides a sched%le() &ethod o sched%le(Ti&erTas> t5 int delayti&ein&s5 int repeatti&ein&s) o cancel() o restart()

2e"ote >et6od I$vocatio$ '2>I+ : : : 2 &ethod to place all the logic and data on centraliUed server and call the& )ro& any <here in the <orld <itho%t )ear o) port n%&"ers 1t is a sec%red co&&%nication <ith serialiUation 2ll classes are provided %nder o $ava.r&i pac>age o $ava.r&i.server pac>age

(oftware 2eH ire"e$ts 0lie$t J.E 9lient 2ccess (rogra&s to connect <ith server <ith .!1 protocol (r&i#) (erver 2ll "%siness logic +ata"ase .!1.E81ST.^ tool )ro& J+, +evelop&ent .!19 C .!1 9o&piler Steps )or any .!1 2pplication 1. +esign an inter)ace "y providing all possi"le &ethods accessi"le to client a. This inter)ace &%st inherit )ro& 2e"ote inter)ace o) $ava.r&i pac>age ". 2ll &ethods &%st thro<s 2e"oteE;ceptio$ 2. /o< i&ple&ent this inter)ace to so&e class called i&ple&entation progra&. a. This class &%st inherit )ro& <$icast2e"ote.&/ect class o) $ava.r&i.server pac>age . 9reate a server progra& to reside on a &achine and server the clients a. Gse /a&ing.re"ind() to provide so&e server na&e and ret%rn the o"$ect o) "%siness logic class to the client &. 1a"i$g.re&i$d'Iserver$a"eJB$ew & sclass$a"e'++K 4. 9reate a client progra& to contact the server and get re)erence o) "%siness logic )ile into an inter)ace a. Gse /a&ing.loo>%p() &ethod connect <ith server %sing .!1 protocol I$terfacerefere$ce L'i$terface$a"e+1a"i$g.loo5 p'Ir"i?--ip or d$s-server$a"eJ+

*. 9reate STG0 and S,EBT3/ )or the "%siness &ethod to &arshalling and %n: &arshaling the &ethods a. Gse .!19 tool )ro& J+, to create the& i. .!19 i&ple&entclass ". /o< in J+, 1.* S,EBT3/ is optional c. STG0 is )or client and S>elton is )or Server Files placed o$ clie$t 1nter)ace St%" 9lient (rogra& (erverside 1nter)ace Server (rogra& 1&ple&entation progra& E;ec ti$g t6e applicatio$ Server Side <or> Start the .!1.E81ST.^ ST2.T .!1.E81ST.^ Start the Server progra& 9lient Start the client progra& /ote# The c%rrent )older &%st "e in classspath