Web Programming Unit5 2 & 16 Marks

Published on December 2016 | Categories: Documents | Downloads: 44 | Comments: 0 | Views: 133
of 20
Download PDF   Embed   Report

Web Programming Unit5 2 & 16 Marks

Comments

Content


1
Mailam Engineering College
(Approved AICTE, New Delhi Affiliated to Anna University Chennai
& Accredited by National of Accreditation (NBA New Delhi
Mailam Villupuram (Dt), Pin – 604 304
DEPARTMENT ! CMP"TER APP#$CAT$N%
%u&'e(t Name ) *e& Programming
%u&'e(t Co+e ) MC,-3.
/ear ) -00- – -003
%eme1ter ) $$$
Prepare+ 23 ) M14A4%u&at5ra De6i
%u&'e(t $n(5arge 7D Prin(ipal
Prepared by
Ms.A.Subathra Devi
2
*e& Programming
UNIT V ADVANCED JAVA PROGRAMMING
Utility Packages – Input Output Packages – Inner Classes – Java Database Connectivity -
Servlets - RMI – Java Beans
- – Mar81 9ue1tion1 :it5 An1:er1
04 *53 +o t5rea+1 &lo(8 on $;<
Threads bloc! on I"# that other threads $ay e%ec&te while the I"# #peration is
perfor$ed
-4 *5at i1 t5e Ve(tor (la11<
The 'ector class provides the capability to i$ple$ent a (rowable array of ob)ects
34 *5at mo+i=ier1 ma3 &e u1e+ :it5 an inner (la11 t5at i1 a mem&er o= an outer
(la11<
A (non*local inner class $ay be declared as p&blic, protected, private, static, final, or
abstract+
44 Doe1 gar&age (olle(tion guarantee t5at a program :ill not run out o= memor3<
,arba(e collection does not (&arantee that a pro(ra$ will not r&n o&t of $e$ory+ It is
possible for pro(ra$s to &se &p $e$ory reso&rces faster than they are (arba(e collected+
It is also possible for pro(ra$s to create ob)ects that are not s&b)ect to (arba(e collection+
.4 Name t5ree Component 1u&(la11e1 t5at 1upport painting4
The Canvas, -ra$e, .anel, and Applet classes s&pport paintin(+
64 *5at an $; =ilter<
An I"# filter is an ob)ect that reads fro$ one strea$ and writes to another, &s&ally
alterin( the data in so$e way as it is passed fro$ one strea$ to another+
>4 *5at i1 ?a6a %er6let<
A servlet is a /ava technolo(y*based 0eb co$ponent, $ana(ed by a container called
servlet container or servlet en(ine, that (enerates dyna$ic content and interacts with web
clients via a re1&est"response paradi($+
@4 *5atA1 t5e +i==eren(e &et:een 1er6let1 an+ applet1<
2ervlets are to servers, applets are to browsers+ Unli!e applets, however, servlets
have no (raphical &ser interface+
,4 *5atA1 t5e a+6antage1 u1ing 1er6let1 t5an u1ing CB$<
2ervlets provide a way to (enerate dyna$ic doc&$ents that is both easier to write
and faster to r&n+ It is efficient, convenient, powerf&l, portable, sec&re and ine%pensive+
2ervlets also address the proble$ of doin( server*side pro(ra$$in( with platfor$*specific
A.Is3 they are developed with /ava 2ervlet A.I, a standard /ava e%tension+

004 *5at are t5e purpo1e o= %er6let1< "9 CNo6;De( -000D
A servlet can handle $&ltiple re1&ests conc&rrently, and can synchroni4e re1&ests+
This allows servlets to s&pport syste$s s&ch as on*line conferencin(+ 2ervlets can forward
re1&ests to other servers and servlets+ Th&s servlets can be &sed to balance load a$on(
several servers that $irror the sa$e content, and to partition a sin(le lo(ical service over
several servers, accordin( to tas! type or or(ani4ational bo&ndaries+

Prepared by
Ms.A.Subathra Devi
3
004 *5atA1 t5e %er6let $nter=a(e<
The central abstraction in the 2ervlet A.I is the 2ervlet interface+ All servlets
i$ple$ent this interface, either directly or, $ore co$$only, by e%tendin( a class that
i$ple$ents it s&ch as 5ttp2ervlet+ 2ervlets67,eneric 2ervlet675ttp2ervlet678y2ervlet+
The 2ervlet interface declares, b&t does not i$ple$ent, $ethods that $ana(e the servlet
and its co$$&nications with clients+ 2ervlet writers provide so$e or all of these $ethods
when developin( a servlet+
0-4 *5en a 1er6let a((ept1 a (all =rom a (lient, it re(ei6e1 t:o o&'e(t14 *5at are
t5e3<
2ervelt9e1&est3 which encaps&lates the co$$&nication fro$ the client to the server+
2ervlet9esponse3 which encaps&lates the co$$&nication fro$ the servlet bac! to the client+
2ervlet9e1&est and 2ervlet9esponse are interfaces defined by the )ava%+servlet pac!a(e+
034 De=ine 1er6let #i=e C3(le4 C"9 No6;De(
-00,D
A servlet life cycle can be defined as the entire process fro$ its creation till the
destr&ction+ The followin( are the paths followed by a servlet
• The servlet is initiali4ed by callin( the init () $ethod+
• The servlet calls 1er6i(e() $ethod to process a client:s re1&est+
• The servlet is ter$inated by callin( the +e1tro3() $ethod+
• -inally, servlet is (arba(e collected by the (arba(e collector of the /'8+
044 *5en a (lient reEue1t i1 1ent to t5e 1er6let (ontainer, 5o: +oe1 t5e (ontainer
(5oo1e :5i(5 1er6let to in6o8e<
The servlet container deter$ines which servlet to invo!e based on the confi(&ration
of its servlets, and calls it with ob)ects representin( the re1&est and response+
0.4 De=ine %er6let $= a 1er6let i1 not properl3 initialiFe+, :5at eG(eption ma3 &e
t5ro:n<
D&rin( initiali4ation or service of a re1&est, the servlet instance can throw an
UnavailableE%ception or a 2ervletE%ception+
064 *5at i1 =ilter< Can =ilter &e u1e+ a1 reEue1t or re1pon1e<
A filter is a re&sable piece of code that can transfor$ the content of 5TT.
re1&ests,responses, and header infor$ation+ -ilters do not (enerally create a response or
respond to a re1&est as servlets do, rather they $odify or adapt the re1&ests for a
reso&rce, and $odify or adapt responses fro$ a reso&rce+
0>4 *5at i1 ne: in %er6letReEue1t inter=a(e<
The followin( $ethods have been added to 2ervlet9e1&est ;+< version3
p&blic int (et9e$ote.ort(
p&blic )ava+lan(+2trin( (et=ocalNa$e(
p&blic )ava+lan(+2trin( (et=ocalAddr(
p&blic int (et=ocal.ort(
0@4 7o: (an $ 1en+ u1er aut5enti(ation in=ormation :5ile ma8ing"R#Conne(tion<
>o&:ll want to &se 5ttpU9=Connection+set9e1&est.roperty and set all the appropriate
headers to 5TT. a&thori4ation+
Prepared by
Ms.A.Subathra Devi
4
0,4 Can :e u1e t5e (on1tru(tor, in1tea+ o= init(), to initialiFe 1er6let<
>es , of co&rse yo& can &se the constr&ctor instead of init(+ There:s nothin( to stop
yo&+ B&t yo& sho&ldn:t+ The ori(inal reason for init( was that ancient versions of /ava
co&ldn:t dyna$ically invo!e constr&ctors with ar(&$ents, so there was no way to (ive the
constr&ct&r a 2ervletConfi(+
-04 T5e (o+e in a =inall3 (lau1e :ill ne6er =ail to eGe(ute, rig5t<
Usin( 2yste$+e%it(?@ in try bloc! will not allow finally code to e%ec&te+
-04 Di==eren(e &et:een BET an+ P%T in ?a6a %er6let1<
In ,ET yo&r entire for$ s&b$ission can be encaps&lated in one U9=, li!e a hyperlin!+
1&ery len(th is li$ited to ;AB characters, not sec&re, faster, 1&ic! and easy+
In .#2T >o&r na$e"val&e pairs inside the body of the 5TT. re1&est, which $a!es for
a cleaner U9= and i$poses no si4e li$itations on the for$:s o&tp&t+ It is &sed to send a
ch&n! of data to the server to be processed, $ore versatile, $ost sec&re+

--4 *5at i1 ?a6a %er6let 1e11ion<
The session is an ob)ect &sed by a servlet to trac! a &ser:s interaction with a 0eb
application across $&ltiple 5TT. re1&ests+
-34 *5at i1 1er6let mapping<
The servlet $appin( defines an association between a U9= pattern and a servlet+ The
$appin( is &sed to $ap re1&ests to servlets+
-44 *5at i1 1er6let (onteGt <
The servlet conte%t is an ob)ect that contains a servlet:s view of the 0eb application
within which the servlet is r&nnin(+
Usin( the conte%t, a servlet can lo( events, obtain U9= references to reso&rces, and
set and store attrib&tes that other servlets in the conte%t can &se+
-.4 EGplain Bar&age (olle(tion me(5ani1m in ?a6a
It is done by two ways by reference co&nt & trace a (raph of ob)ect reference+
-64 *5at i1 ?a6a RM$<
9e$ote 8ethod Invocation (98I is the process of activatin( a $ethod on a re$otely
r&nnin( ob)ect+ 98I offers location transparency in the sense that it (ives the feel that a
$ethod is e%ec&ted on a locally r&nnin( ob)ect+
->4 *5at are t5e la3er1 o= RM$ Ar(5ite(ture<
The 98I is b&ilt on three layers+
a. Stub and Skeleton layer
This layer lies )&st beneath the view of the developer+ This layer intercepts $ethod
calls $ade by the client to the interface reference variable and redirects these calls to a
re$ote 98I service+
b. Remote Reference Layer
This layer &nderstands how to interpret and $ana(e references $ade fro$ clients to
the re$ote service ob)ects+ The connection is a one*to*one (&nicast lin!+
c. Transport layer
Prepared by
Ms.A.Subathra Devi
5
This layer is based on TC."I. connections between $achines in a networ!+ It
provides basic connectivity, as well as so$e firewall penetration strate(ies+
-@4 7o: man3 t3pe1 o= proto(ol implementation1 +oe1 RM$ 5a6e<
98I has at least three protocol i$ple$entations3
/ava 9e$ote 8ethod .rotocol(/98., Internet Inter #9B .rotocol(II#., and /ini
E%tensible 9e$ote Invocation(/E9I+ These are alternatives, not part of the sa$e thin(, All
three are indeed layer A protocols for those who are still spea!in( #2I reference $odel+
-,4 *5at i1 t5e role o= Remote $nter=a(e in RM$<
The 9e$ote interface serves to identify interfaces whose $ethods $ay be invo!ed
fro$ a non*local virt&al $achine+ Any ob)ect that is a re$ote ob)ect $&st directly or
indirectly i$ple$ent this interface+ 8ethods that are to be invo!ed re$otely $&st be
identified in 9e$ote Interface+ All 9e$ote $ethods sho&ld throw 9e$oteE%ception+
304 *5at i1 t5e role 'a6a4rmi4Naming Cla11<
The Na$in( class provides $ethods for storin( and obtainin( references to re$ote
ob)ects in the re$ote ob)ect re(istry+
304 *5at i1 t5e +e=ault port u1e+ &3 RM$ Regi1tr3<
?BCC
3-4 *5at i1 meant &3 &in+ing in RM$<
Bindin( is a process of associatin( or re(isterin( a na$e for a re$ote ob)ect that can
be &sed at a later ti$e to loo! &p that re$ote ob)ect+ A re$ote ob)ect can be associated
with a na$e &sin( the Na$in( class:s bind or rebind $ethods+
334 *5at i1 t5e +i==eren(e &et:een u1ing &in+() an+ re&in+() met5o+1 o= Naming
Cla11<
bind $ethod(2trin( na$e binds the specified na$e to a re$ote ob)ect while
rebind(2trin( na$e $ethod rebinds the specified na$e to a new re$ote ob)ect,any
e%istin( bindin( for the na$e is replaced+
344 *5en i1 Alrea+32oun+EG(eption t5ro:n an+ &3 :5i(5 met5o+<
AlreadyBo&ndE%ception is thrown by bind(2trin( na$e $ethod when a re$ote
ob)ect is already re(istered with the re(istry with the sa$e na$e+
3.4 7o: to get all t5e regi1tere+ o&'e(t1 in a rmiregi1tr3<
Usin( list $ethod of Na$in( Class+
364 Can a (la11 implementing a Remote inter=a(e 5a6e non remote met5o+1<
>es+ Those $ethods behave as nor$al )ava $ethods operatin( within the /'8+
3>4 *5at i1 t5e proto(ol u1e+ &3 RM$<
/98. ()ava re$ote $ethod protocol
3@4 *5at i1 t5e u1e o= "ni(a1tRemote&'e(t in RM$<
The Unicast9e$ote#b)ect class provides s&pport for point*to*point active ob)ect
references &sin( TC. strea$s+ #b)ects that re1&ire re$ote behavior sho&ld e%tend
Unicast9e$ote#b)ect+
3,4 *5at i1 Porta&leRemote&'e(t4narro:() met5o+ an+ :5at i1 u1e+ =or<
Prepared by
Ms.A.Subathra Devi
6
/ava 98I*II#. provides a $echanis$ to narrow the the #b)ect yo& have received
fro$ fro$ yo&r loo!&p, to the appropriate type+ This is done thro&(h the
)ava%+r$i+.ortable9e$ote#b)ect class and, $ore specifically, &sin( the narrow( $ethod+
404 $n a RM$ Client Program, :5at are t5e eG(petion1 :5i(5 mig5t 5a6e to
5an+le+<
a+ 8al-or$edU9=E%ception
b+ NotBo&ndE%ception
c+ 9e$oteE%ception
404 *5at are t5e 1er6i(e1 in RM$<
An 98I DserviceD co&ld well be any /ava $ethod that can be invo!ed re$otely+ The
other service is the /98. 98I na$in( service which is a loo!&p service+
4-4 *5at i1 t5e ?D2C 340 AP$<
The /DBC E+B A.I is the latest &pdate of the /DBC A.I+ It contains $any feat&res,
incl&din( scrollable res&lt sets and the 2F=3?CCC data types+
Edit
434 Are t5ere an3 D2C +ri6er1 t5at +o not :or8 :it5 t5e ?D2CHD2C 2ri+ge<
8ost #DBC ;+B drivers sho&ld wor! with the Brid(e+ 2ince there is so$e variation in
f&nctionality between #DBC drivers, the f&nctionality of the brid(e $ay be affected+ The
brid(e wor!s with pop&lar .C databases, s&ch as 8icrosoft Access and -o%.ro+
444 7o: +o $ retrie6e a :5ole ro: o= +ata at on(e, in1tea+ o= (alling an in+i6i+ual
Re1ult%et4getIII met5o+ =or ea(5 (olumn<
The 9es&lt2et+(etGGG $ethods are the only way to retrieve data fro$ a 9es&lt2et
ob)ect, which $eans that yo& have to $a!e a $ethod call for each col&$n of a row+ It is
&nli!ely that this is the ca&se of a perfor$ance proble$, however, beca&se it is diffic&lt to
see how a col&$n co&ld be fetched witho&t at least the cost of a f&nction call in any
scenario+ 0e welco$e inp&t fro$ developers on this iss&e+

4.4 Are all t5e reEuire+ ?D2C +ri6er1 to e1ta&li15 (onne(ti6it3 to m3 +ata&a1e part
o= t5e ?DJ<
No+ There arenH:t any /DBC technolo(y*enabled drivers b&ndled with the /DI ?+?+% or
/ava ; .latfor$ releases other than the /DBC*#DBC Brid(e+ 2o, developers need to (et a
driver and install it before they can connect to a database+ 0e are considerin( b&ndlin(
/DBC technolo(y* enabled drivers in the f&t&re+

464 Doe1 t5e ?D2CHD2C 2ri+ge 1upport multiple (on(urrent open 1tatement1 per
(onne(tion<
No+ >o& can open only one 2tate$ent ob)ect per connection when yo& are &sin( the /DBC*
#DBC Brid(e+
4>4 *53 (anKt $ in6o8e t5e Re1ult%et met5o+1 a=ter#a1t an+ &e=ore!ir1t :5en t5e
met5o+ neGt :or81<
>o& are probably &sin( a driver i$ple$ented for the /DBC ?+B A.I+ >o& need to &p(rade to a
/DBC ;+B driver that i$ple$ents scrollable res&lt sets+ Also be s&re that yo&r code has
created scrollable res&lt sets and that the DB82 yo& are &sin( s&pports the$+

4,4 7o: (an $ retrie6e a %tring or ot5er o&'e(t t3pe :it5out (reating a ne: o&'e(t
ea(5 time<
Creatin( and (arba(e collectin( potentially lar(e n&$bers of ob)ects ($illions
&nnecessarily can really h&rt perfor$ance+
Prepared by
Ms.A.Subathra Devi
7
It $ay be better to provide a way to retrieve data li!e strin(s &sin( the /DBC A.I
witho&t always allocatin( a new ob)ect+ 0e are st&dyin( this iss&e to see if it is an area in
which the /DBC A.I sho&ld be i$proved+ 2tay t&ned, and please send &s any co$$ents yo&
have on this 1&estion+

.04 $ :oul+ li8e to +o:nloa+ t5e ?D2CHD2C 2ri+ge =or t5e ?a6a - %DJ, %tan+ar+
E+ition (=ormerl3 ?DJ 04-)4 $LKm a &eginner :it5 t5e ?D2C AP$, an+ $ :oul+ li8e to
1tart :it5 t5e 2ri+ge4 7o: +o $ +o it<
The /DBC*#DBC Brid(e is b&ndled with the /ava ; 2DI, 2tandard Edition, so there is
no need to download it separately+
.04 $= $ u1e t5e ?D2C AP$, +o $ 5a6e to u1e D2C un+erneat5<
No, this is )&st one of $any possible sol&tions+ 0e reco$$end &sin( a p&re /ava
/DBC technolo(y*enabled driver, type E or <, in order to (et all of the benefits of the /ava
pro(ra$$in( lan(&a(e and the /DBC A.I+

.-4 EGplain %er6letConteGt
2ervletConte%t interface is a window for a servlet to view itH:s environ$ent+ A servlet
can &se this interface to (et infor$ation s&ch as initiali4ation para$eters for the web
applicationor servlet containerH:s version+ Every web application has one and only one
2ervletConte%t and is accessible to all active reso&rce of that application

.34 *5at i1 t5e +i==eren(e &et:een 7ttp%er6let an+ Beneri(%er6let<
A ,eneric2ervlet has a service( $ethod ai$ed to handle re1&ests+ 5ttp2ervlet
e%tends ,eneric2ervlet and adds s&pport for do,et(, do.ost(, do5ead( $ethods (5TT.
?+B pl&s do.&t(, do#ptions(, doDelete(, doTrace( $ethods (5TT. ?+?+ Both these
classes are abstract+

54 4 *5at are ?a6a 2ean1<
/ava Beans are &s&al /ava classes which adhere to certain codin( conventions3
► I$ple$ents )ava+io+2eriali4able interface
► .rovides no ar(&$ent constr&ctor
► .rovides (etter and setter $ethods for accessin( it:s properties+
5.4 *53 +o $ get a NullPointerEG(eption :5en loa+ing a ?AR =ile into t5e 2ean2oG<
Us&ally this is beca&se of a $ista!e in the /A9 file bein( loaded+ In the $eanti$e,
typical errors incl&de3
► The 8ANI-E2T file &ses classes &sin( the wron( file separator (D"D sho&ld be &sed in all
platfor$s+
► The 8ANI-E2T file refers to classes in a pac!a(e b&t the act&al +class files are not really
in that pac!a(e+

.64 *5at i1 &ean per1i1tan(e propert3<
A bean has the property of persistence when its properties, fields, and state
infor$ation are saved to and retrieved fro$ stora(e+ Co$ponent $odels provide a
$echanis$ for persistence that enables the state of co$ponents to be stored in a non*
volatile place for later retrieval+
.>4 *5at are eGterniFa&le inter=a(e<
Use the E%ternali4able interface when yo& need co$plete control over yo&r bean:s
seriali4ation (for e%a$ple, when writin( and readin( a specific file for$at+
To &se the E%ternali4able interface yo& need to i$ple$ent two $ethods3 readE%ternal and
writeE%ternal+ Classes that i$ple$ent E%ternali4able $&st have a no*ar(&$ent constr&ctor+
Prepared by
Ms.A.Subathra Devi
8
.@4 *5at i1 propert3 e+itor in 'a6a &ean1<
A property editor is a tool for c&sto$i4in( a partic&lar property type+ .roperty editors
are activated in the .roperties window+ This window deter$ines a property:s type, searches
for a relevant property editor, and displays the property:s c&rrent val&e in a relevant way+
59 4 *53 are (omponent ar(5ite(ture1 u1e=ul<
Developers are t&rnin( to creatin( co$ponents rather than $onolithic applications to
free the$selves fro$ slow, e%pensive application develop$ent, and to b&ild &p a portable,
re&sable code base+ This enables developers to 1&ic!ly attac! new $ar!et opport&nities,
new )oint develop$ent opport&nities, and new ways to sell s$aller pac!a(es of software+
604 $1 ?a6a2ean1 a (omplete (omponent ar(5ite(ture<
/avaBeans is a co$plete co$ponent $odel+ It s&pports the standard co$ponent
architect&re feat&res of properties, events, $ethods, and persistence+ In addition,
/avaBeans provides s&pport for introspection (to allow a&to$atic analysis of a
/avaBeansco$ponent and c&sto$i4ation (to $a!e it easy to confi(&re a /avaBeans
co$ponent+
604 7o: i1 anon3mou1 inner (la11 u1e+ :it5 it1 purpo1e4 C"9 No6;De( -00,D
An anony$o&s class is a !ind of local class that has no na$e, it co$bines the synta%
for class definition with the synta% for ob)ect instantiation+ 0hile a local class definition is a
/ava state$ent, an anony$o&s class definition (and instantiation is a /ava e%pression, so it
can appear as part of a lar(er e%pression, s&ch as $ethod invocation+ Interfaces cannot be
defined anony$o&sly+
6-4 *5at are t5e 1e(urit3 impli(ation1 =or +o:nloa+ing 2ean1 o6er t5e $nternet<
/avaBeans does not add any sec&rity feat&res to the /ava platfor$+ 9ather,
/avaBeans co$ponents have f&ll access to the broad ran(e of sec&rity feat&res that are part
of the /ava platfor$+ /avaBeans co$ponents can be &sed to b&ild a ran(e of different !inds
of sol&tions fro$ f&ll*fled(ed /ava des!top applications to web*based Applets+
634 *5en :ill ?a6a2ean1 &e 1upporte+ on t5e C=ill in t5e &lan8D
plat=orm;operating 131tem<
The co$plete set of /avaBeans A.Is are core to /ava ;, hence any platfor$ that is f&lly
co$patible with /ava ; i$plicitly s&pports /avaBeans+ Th&s, /avaBeans s&pport will be
available as soon as this platfor$"operatin( syste$ vendor s&pports /ava ;+
644 7o: +o 3ou pa(8 a &ean into a ?AR =ile <
Before yo& can brin( a /avaBean into a Bean*enabled vis&al b&ilder tool, it $&st be p&t into
the standard Bean container, which is a /A9 file that incl&des all the Bean classes as well as
a D$anifestD file that says DThis is a Bean+D A $anifest file is si$ply a te%t file that follows a
partic&lar for$+
6.4 *5at i1 an inner (la11< EGplain :it5 an eGample< "9 CNo6;De( -000D
A class within the class is called as an inner class+
class A
J int a, b,c@
class B
J "" codin( for inner class KK
Prepared by
Ms.A.Subathra Devi
9
Part H 2
06 – Mar81 9ue1tion1 :it5 An1:er1
04 "tilit3 Pa(8age1)
 The final /ava pac!a(e, )ava+&til, contains a collection of &tility classes+
 The Utility .ac!a(e of /ava consist of the followin( co$ponents3
⇒ Collections fra$ewor!
⇒ =e(acy collection classes
⇒ Event $odel
⇒ Date and ti$e facilities
⇒ Internationali4ation
⇒ 8iscellaneo&s &tility classes s&ch as strin( to!eni4er, rando$*n&$ber
(enerator and bit array
 Description of the &tility classes of this pac!a(e is as follows
⇒ Data 2tr&ct&re Classes3 Data 2tr&ct&re Classes are very &sef&l classes for
i$ple$entin( standard co$p&ter science data str&ct&res3 incl&din( Bit2et,
Dictionary, 5ashtable, 2tac! and 'ector+ The En&$eration interface of )ava+&til
pac!a(e is &sed to co&nt thro&(h a set of val&es+
⇒ Date3 The Date class is &sed to $anip&late calendar dates in a syste$*
independent fashion+
⇒ 2trin(To!eni4er3 This 2trin(To!eni4er class is &sed to convert a 2trin( of te%t
into its to!ens+
⇒ .roperties3 The properties table contains !ey"val&e pairs where both the !ey
and the val&e are 2trin(s and the class is &sed by the 2yste$ class to
i$ple$ent 2yste$ properties+
⇒ #bserver and #bservable3 Classes that i$ple$ent the #bserver interface can
DwatchD #bservable ob)ects for state chan(es+ 0hen an #bservable ob)ect
chan(es it notifies all of its #bservers of the chan(e+
⇒ 9ando$*N&$ber ,enerator3 The 9ando$ N&$ber ,enerator class is &sed to
(enerate the rando$*n&$bers+
⇒ En&$eration3 The En&$eration interface defines a (eneric pro(ra$$in(
interface for iteratin( thro&(h a set of val&es+
-4 $nput;utput Pa(8age1)
The )ava+io pac!a(e defines I"# in ter$s of strea$s+ 2trea$s are ordered se1&ences
of data that have a so&rce (inp&t strea$s or destination (o&tp&t strea$s+
8ost strea$ types s&pport the $ethods of so$e basic interfaces and abstract classes,
with few additions+
The )ava+nio pac!a(e and its s&bpac!a(es define I"# in ter$s of b&ffers and channels+
B&ffers are data stores (si$ilar to arrays that can be read fro$ or written to+
Prepared by
Ms.A.Subathra Devi
10
Channels represent connections to entities capable of perfor$in( I"# operations,
incl&din( b&ffers, files, and soc!ets+
The )ava+net pac!a(e provides specific s&pport for networ! I"#, based aro&nd the &se
of soc!ets, with an &nderlyin( strea$ or channel*based $odel+
The pac!a(e )ava+io has two $a)or parts3 character strea$s and byte strea$s+
Characters are ?A*bit UT-*?A characters, whereas bytes are (as always L bits+
The character strea$s are &sed for te%t*based I"#, while byte strea$s are &sed for
data*based I"#+
The byte strea$s are called inp&t strea$s and o&tp&t strea$s, and the character
strea$s are called readers and writers
The I#E%ception class is &sed by $any $ethods in )ava+io to si(nal e%ceptional
conditions+ 2o$e e%tended classes of I#E%ception si(nal specific proble$s+
34 23te %tream1)
 The )ava+io pac!a(e defines abstract classes for basic byte inp&t and o&tp&t strea$s+
 All strea$s s&pport the notion of bein( open or closed+ >o& open a strea$ when yo&
create it, and can read or write while it is open+ >o& close a strea$ with its close
$ethod, defined in the Closeable interface+
 A strea$ class co&ld define a finali4e $ethod to release these reso&rces d&rin(
(arba(e collection
 Inp&t2trea$3 The abstract class Inp&t2trea$ declares $ethods to read bytes fro$ a
partic&lar so&rce+ Inp&t2trea$ is the s&perclass of $ost byte inp&t strea$s in
)ava+io+
⇒ p&blic abstract int read( throws I#E%ception
⇒ p&blic int read(byteMN b&f, int offset, int co&nt throws I#E%ception
⇒ p&blic int read(byteMN b&f throws I#E%ception
⇒ p&blic lon( s!ip(lon( co&nt throws I#E%ception
⇒ p&blic int available( throws I#E%ception
⇒ p&blic void close( throws I#E%ception
 #&tp&t2trea$3 The abstract class #&tp&t2trea$ is analo(o&s to Inp&t2trea$@ it
provides an abstraction for writin( bytes to a destination+ Its $ethods are3
⇒ p&blic abstract void write(int b throws I#E%ception
⇒ p&blic void write(byteMN b&f, int offset, int co&nt throws I#E%ception
⇒ p&blic void write(byteMN b&f throws I#E%ception
⇒ p&blic void fl&sh( throws I#E%ception
⇒ p&blic void close( throws I#E%ception
 The i$ple$entation of #&tp&t2trea$ re1&ires only that a s&bclass provide the
sin(le*byte variant of write beca&se the other write $ethods are defined in ter$s of
this one+
 he defa&lt i$ple$entations of fl&sh and close will &s&ally need to be overridden as
appropriate for a partic&lar strea$Oin partic&lar, b&ffered strea$s $ay need to fl&sh
when closed+
 Character 2trea$s3 The abstract classes for readin( and writin( strea$s of
characters are 9eader and 0riter+
 Each s&pports $ethods si$ilar to those of its byte strea$ co&nterpartOInp&t2trea$
and #&tp&t2trea$, respectively+
 9eader has a read $ethod that ret&rns a char as the lowest ?A bits of an int+ And,
0riter has $ethods that write char arrays+
 The character strea$s were desi(ned after the byte strea$s to provide f&ll s&pport
for wor!in( with Unicode characters, and in the process the contracts of the classes
were i$proved to $a!e the$ easier to wor! with+
Prepared by
Ms.A.Subathra Devi
11
 9eader3 The abstract class 9eader provides a character strea$ analo(o&s to the byte
strea$ Inp&t2trea$ and the $ethods of 9eader essentially $irror those of
Inp&t2trea$3
⇒ p&blic int read( throws I#E%ception
⇒ p&blic abstract int read(charMN b&f, int offset, int co&nt throws I#E%ception
⇒ p&blic int read(charMN b&f throws I#E%ception
⇒ p&blic int read()ava+nio+CharB&ffer b&f throws I#E%ception
⇒ p&blic lon( s!ip(lon( co&nt throws I#E%ception
⇒ p&blic boolean ready( throws I#E%ception
⇒ p&blic abstract void close( throws I#E%ception
 The i$ple$entation of 9eader re1&ires that a s&bclass provide an i$ple$entation of
both the read $ethod that reads into a char array, and the close $ethod+
 There are a n&$ber of differences between 9eader and Inp&t2trea$+
 0ith 9eader the f&nda$ental readin( $ethod reads into a char array and the other
read $ethods are defined in ter$s of this $ethod+
 In contrast the Inp&t2trea$ class &ses the sin(le*byte read $ethod as its
f&nda$ental readin( $ethod+
 0riter3 The abstract class 0riter provides a strea$ analo(o&s to #&tp&t2trea$ b&t
desi(ned for &se with characters instead of bytes+
 The $ethods of 0riter essentially $irror those of #&tp&t2trea$, b&t add so$e other
&sef&l for$s of write3
⇒ p&blic void write(int ch throws I#E%ception
⇒ p&blic abstract void write(charMN b&f, int offset, int co&nt throws I#E%ception
⇒ p&blic void write(charMN b&f throws I#E%ception
⇒ p&blic void write(2trin( str, int offset, int co&nt throws I#E%ception
⇒ p&blic void write(2trin( str throws I#E%ception
⇒ p&blic abstract void fl&sh( throws I#E%ception
⇒ p&blic abstract void close( throws I#E%ception
 2&bclasses of 0riter $&st i$ple$ent the array writin( variant of write, the close
$ethod, and the fl&sh $ethod+
 0riter also i$ple$ents the )ava+lan(+Appendable interface+ The append(charc
$ethod is e1&ivalent to write(c@ the append $ethods that ta!e a Char2e1&ence are
e1&ivalent to passin( the 2trin( representations of the Char2e1&ence ob)ects to the
write(2trin(str $ethod+
 Inp&t2trea$9eader and #&tp&t2trea$0riter3 The conversion strea$s
Inp&t2trea$9eader and #&tp&t2trea$0riter translate between character and byte
strea$s &sin( either a specified character set encodin( or the defa&lt encodin( for
the local syste$+
 An Inp&t2trea$9eader ob)ect is (iven a byte inp&t strea$ as its so&rce and
prod&ces the correspondin( UT-*?A characters+ An #&tp&t2trea$0riter ob)ect is
(iven a byte o&tp&t strea$ as its destination and prod&ces encoded byte for$s of
the UT-*?A characters written on it+
⇒ p&blic Inp&t2trea$9eader(Inp&t2trea$ in
⇒ p&blic Inp&t2trea$9eader(Inp&t2trea$ in, Charset c
⇒ p&blic Inp&t2trea$9eader(Inp&t2trea$ in, CharsetDecoder c
⇒ p&blic Inp&t2trea$9eader(Inp&t2trea$ in, 2trin( enc throws
Uns&pportedEncodin(E%ception
⇒ p&blic #&tp&t2trea$0riter(#&tp&t2trea$ o&t
⇒ p&blic #&tp&t2trea$0riter(#&tp&t2trea$ o&t, Charset c
⇒ p&blic #&tp&t2trea$0riter(#&tp&t2trea$ o&t, CharsetEncoder c
Prepared by
Ms.A.Subathra Devi
12
⇒ p&blic #&tp&t2trea$0riter(#&tp&t2trea$ o&t, 2trin( enc throws
Uns&pportedEncodin(E%ception
 The read $ethods of Inp&t2trea$9eader si$ply read bytes fro$ their associated
Inp&t2trea$ and convert the$ to characters &sin( the appropriate encodin( for that
strea$+
 The write $ethods of #&tp&t2trea$0riter ta!e the s&pplied characters, convert
the$ to bytes with the appropriate encodin(, and write the$ to the associated
#&tp&t2trea$+
 The -ile9eader and -ile0riter classes are s&bclasses of these conversion strea$s+
This helps yo& read and write local files correctly in a consistent, Unicode*savvy
fashion &sin( the local encodin(+
44 $llu1trate :it5 a ?a6a Program a +e=ine an+ u1e an inner (la114
C"9 No6;De( -000D
 There are fo&r other types of classes, loosely !nown as inner classes, that can be
defined in a /ava pro(ra$+ Used correctly, inner classes are an ele(ant and powerf&l
feat&re of the /ava lan(&a(e+ These fo&r types of classes are s&$$ari4ed here3
⇒ 2tatic $e$ber classes
 A static $e$ber class is a class (or interface defined as a static
$e$ber of another class+
 A static $ethod is called a class $ethod, so, by analo(y, we co&ld call
this type of inner class a Dclass class,D b&t this ter$inolo(y wo&ld
obvio&sly be conf&sin(+
 A static $e$ber class behaves $&ch li!e an ordinary top*level class,
e%cept that it can access the static $e$bers of the class that contains
it+ Interfaces can be defined as static $e$bers of classes+
⇒ 8e$ber classes
 A $e$ber class is also defined as a $e$ber of an enclosin( class, b&t
is not declared with the static $odifier+ This type of inner class is
analo(o&s to an instance $ethod or field+
 An instance of a $e$ber class is always associated with an instance of
the enclosin( class, and the code of a $e$ber class has access to all
the fields and $ethods (both static and non*static of its enclosin(
class+
 There are several feat&res of /ava synta% that e%ist specifically to wor!
with the enclosin( instance of a $e$ber class+ Interfaces can only be
defined as static $e$bers of a class, not as non*static $e$bers+
⇒ =ocal classes
 A local class is a class defined within a bloc! of /ava code+ =i!e a local
variable, a local class is visible only within that bloc!+
 Altho&(h local classes are not $e$ber classes, they are still defined
within an enclosin( class, so they share $any of the feat&res of
$e$ber classes+
 Additionally, however, a local class can access any final local variables
or para$eters that are accessible in the scope of the bloc! that defines
the class+ Interfaces cannot be defined locally+
⇒ Anony$o&s classes
 An anony$o&s class is a !ind of local class that has no na$e@ it
co$bines the synta% for class definition with the synta% for ob)ect
instantiation+
Prepared by
Ms.A.Subathra Devi
13
 0hile a local class definition is a /ava state$ent, an anony$o&s class
definition (and instantiation is a /ava e%pression, so it can appear as
part of a lar(er e%pression, s&ch as $ethod invocation+
 Interfaces cannot be defined anony$o&sly+
 The $ost i$portant feat&re of the inner class is that it allows &s to t&rn thin(s into
ob)ects that we nor$ally wo&ldn:t t&rn into ob)ects+ That allows o&r code to be even
$ore ob)ect*oriented than it wo&ld be witho&t inner classes
 An inner class allows &s to re$ove that lo(ic and place it into its own class+ 2o fro$
an ob)ect*oriented point of view, we:ve ta!en f&nctionality o&t of where it doesn:t
belon( and have p&t it into its own class+
 #b)ect*oriented desi(n isn:t everyone:s thin(, b&t l&c!ily, inner classes provide $ore+
-ro$ an or(ani4ational point of view, inner classes allow &s to f&rther or(ani4e o&r
pac!a(e str&ct&re thro&(h the &se of na$espaces+ Instead of d&$pin( everythin( in
a flat pac!a(e, classes can be f&rther nested within classes+
 Inner classes have their disadvanta(es+ -ro$ a $aintenance point of view,
ine%perienced /ava developers $ay find the inner class diffic&lt to &nderstand+ The
&se of inner classes will also increase the total n&$ber of classes in yo&r code+
.4 ?a6a Data&a1e Conne(ti6it3)
 /ava Database Connectivity or in short /DBC is a technolo(y that enables the )ava
pro(ra$ to $anip&late data stored into the database+
 /DBC is /ava application pro(ra$$in( interface that allows the /ava pro(ra$$ers to
access database $ana(e$ent syste$ fro$ /ava code+ It was developed by /ava2oft,
a s&bsidiary of 2&n 8icrosyste$s+
 /DBC is consists of fo&r Co$ponents3 The /DBC A.I, /DBC Driver 8ana(er, The /DBC
Test 2&ite and /DBC*#DBC Brid(e+
 /DBC is an A.I specification developed by 2&n 8icrosyste$s that defines a &nifor$
interface for accessin( vario&s relational databases+ /DBC is a core part of the /ava
platfor$ and is incl&ded in the standard /DI distrib&tion+
/DBC Driver 8ana(er3
 The /DBC Driver8ana(er class defines ob)ects which can connect /ava applications to
a /DBC driver+ Driver8ana(er has traditionally been the bac!bone of the /DBC
architect&re+
 Its $ain p&rpose is to provide a $eans of $ana(in( the different types of /DBC
database driver+
 0hen openin( a connection to a database it is the Driver8ana(er: s role to choose
the $ost appropriate driver fro$ the previo&sly loaded drivers+
 A /ava pro(ra$ that &ses the /DBC A.I loads the specified driver for a partic&lar
DB82 before it act&ally connects to a database+ The /DBC Driver8ana(er class then
sends all /DBC A.I calls to the loaded driver+
 Types of /DBC drivers3 There are fo&r types of /DBC drivers !nown as3
⇒ /DBC*#DBC brid(e pl&s #DBC driver, also called Type ?+
⇒ Native*A.I, partly /ava driver, also called Type ;+
⇒ /DBC*Net, p&re /ava driver, also called Type E+
⇒ Native*protocol, p&re /ava driver, also called Type <+
 The $ethod Class+forNa$e(2trin( is &sed to load the /DBC driver class+ In /DBC
<+B, it:s no lon(er necessary to e%plicitly load /DBC drivers &sin( Class+forNa$e(+
 0hen a connection is needed, one of the Driver8ana(er+(etConnection( $ethods is
&sed to create a /DBC connection+
Prepared by
Ms.A.Subathra Devi
14
 The U9= &sed is dependent &pon the partic&lar /DBC driver+ It will always be(in with
the D)dbc3D protocol, b&t the rest is &p to the partic&lar vendor+ #nce a connection is
established, a state$ent $&st be created+
64 *5at i1 t5e li=e(3(le o= a 1er6let< *rite 15ort note1 on t5e =ollo:ing (la11e1)
Beneri1%er6let, %er6let$nput%tream, %er6letutput%tream M
%er6letEG(eption4 C"9 No6;De( -000D
 2ervlets are /ava technolo(y:s answer to C,I pro(ra$$in(+ They are pro(ra$s that
r&n on a 0eb server and b&ild 0eb pa(es+
Lifecycle of a Servlet
 The 2ervlet lifecycle consists of the followin( steps3
⇒ The 2ervlet class is loaded by the container d&rin( start*&p+
⇒ The container calls the init( $ethod+ This $ethod initiali4es the servlet and
$&st be called before the servlet can service any re1&ests+ In the entire life of
a servlet, the init( $ethod is called only once+
⇒ After initiali4ation, the servlet can service client*re1&ests+ Each re1&est is
serviced in its own separate thread+ The container calls the service( $ethod
of the servlet for every re1&est+ The service( $ethod deter$ines the !ind of
re1&est bein( $ade and dispatches it to an appropriate $ethod to handle the
re1&est+ The developer of the servlet $&st provide an i$ple$entation for
these $ethods+ If a re1&est for a $ethod that is not i$ple$ented by the
servlet is $ade, the $ethod of the parent class is called, typically res&ltin( in
an error bein( ret&rned to the re1&ester+
⇒ -inally, the container calls the destroy( $ethod which ta!es the servlet o&t of
service+ The destroy( $ethod li!e init( is called only once in the lifecycle of a
2ervlet+
GenerisServlet:
This class i$ple$ents 2ervlet and 2ervletConfi( interfaces+ This class can be e%tended
by a servlet+ It is a co$$on practice that a servlet class e%tends protocol*specific, s&ch as
5ttp2ervlet class+ 0ith the help of &sin( life cycle $ethods, it $a!es si$pler and easier to
develop servlets applications+ To write a (eneric servlet, the developer need only to override
the service( $ethod+ Additionally, the lo( $ethod of 2ervletConte%t interface is also
i$ple$ented by ,eneric2ervlet+
ServletInputStream:
.rovides an inp&t strea$ for readin( binary data fro$ a client re1&est, incl&din( an
efficient read=ine $ethod for readin( data one line at a ti$e+ 0ith so$e protocols, s&ch as
5TT. .#2T and .UT, a 2ervletInp&t2trea$ ob)ect can be &sed to read data sent fro$ the
client+ A 2ervletInp&t2trea$ ob)ect is nor$ally retrieved via the
2ervlet9e1&est+(etInp&t2trea$( $ethod+ This is an abstract class that a servlet container
i$ple$ents+ 2&bclasses of this class $&st i$ple$ent the )ava+io+Inp&t2trea$+read(
$ethod+
ServletOutputStream:
2ervleto&tp&tstrea$ is &sed for sendin( data to client in binary for$at+ It is retrieved
via response+(et#&tp&t2trea$( f&nction+ 2ervlet#&tp&t2trea$ is an abstract class and
servlet container i$ple$ents it+ 0hen yo& &se character conversion and there is a lot of
te%t then it is better to &se byteMN instead of 2trin( ob)ect+ ByteArray#&tp&t2trea$
Prepared by
Ms.A.Subathra Devi
15
i$ple$ents o&tp&t strea$ and it contain data in for$ of byte array+-or retrievin( data yo&
can &se toByteArray( and to2trin(( $ethods+
ServletException:
2ervletE%ception is a s&bclass of the E%ception+ It defines a (eneral e%ception a servlet
can throw when it enco&nters diffic&lty+ 2ervletE%ception class define only one $ethod
(et9ootCa&se( that ret&rns the e%ception that ca&sed this servlet e%ception+ It inherit the
other $ethods li!e fillIn2tac!Trace, (et=ocali4ed8essa(e, (et8essa(e, print2tac!Trace,
print2tac!Trace, print2tac!Trace, to2trin( etc fro$ the Throwable class+ .ac!a(es that &se
2ervletE%ception 3 P )ava%+servlet P )ava%+servlet+http
>4 De1ign an appli(ation :5i(5 implement1 RM$ Con(ept14 C"9 No6;De( -00,D
 9e$ote 8ethod Invocation (98I facilitates ob)ect f&nction calls between /ava 'irt&al
8achines (/'8s+
 /'8s can be located on separate co$p&ters * yet one /'8 can invo!e $ethods
belon(in( to an ob)ect stored in another /'8+ 8ethods can even pass ob)ects that a
forei(n virt&al $achine has never enco&ntered before, allowin( dyna$ic loadin( of
new classes as re1&ired+
 0ritin( yo&r own 98I services can be a little diffic&lt at first+
 The first thin( we need to do is to a(ree &pon an interface, an interface is a
description of the $ethods we will allow re$ote clients to invo!e+ An interface is a
$ethod which contains abstract $ethods@ these $ethods $&st be i$ple$ented by
another class+ #&r interface e%tends )ava+r$i+9e$ote, which indicates that this is a
re$ote service+ And the ne%t step is to i$ple$ent the interface+
 I$ple$entin( the interface is a little tric!ier+ The real code we need to be concerned
abo&t is the constr&ctor and $ain $ethod+
 0e have to declare a defa&lt constr&ctor, even when we don:t have any initiali4ation
code for o&r service+ This is beca&se o&r defa&lt constr&ctor can throw a
)ava+r$i+9e$oteE%ception, fro$ its parent constr&ctor in Unicast9e$ote#b)ect+
 #&r i$ple$entation of the service also needs to have a $ain $ethod+ The $ain
$ethod will be responsible for creatin( an instance of o&r .ower2ervice2erver, and
re(isterin( (or bindin( the service with the 98I 9e(istry+
 #&r $ain $ethod will also assi(n a sec&rity $ana(er to the /'8, to prevent any
nasty s&rprises fro$ re$otely loaded classes+ In this case, a sec&rity $ana(er isn:t
really needed, b&t in $ore co$ple% syste$s where &ntr&sted clients will be &sin( the
service, it is critical+
 0ritin( clients is the easy part * all a client has to do is call the re(istry to obtain a
reference to the re$ote ob)ect, and call its $ethods+ All the &nderlyin( networ!
co$$&nication is hidden fro$ view, which $a!es 98I clients si$ple+
 #&r client $&st first assi(n a sec&rity $ana(er, and then obtain a reference to the
service+ Note that the client receives an instance of the interface we defined earlier,
and not the act&al i$ple$entation+ 2o$e behind*the*scenes wor! is (oin( on, b&t
this is co$pletely transparent to the client+
 To identify a service, we specify an 98I U9=+ The U9= contains the hostna$e on
which the service is located, and the lo(ical na$e of the service+
 /ava 98I is a &sef&l $echanis$ for invo!in( $ethods of re$ote ob)ects+ /ava 98I
allows one /ava 'irt&al 8achine to invo!e $ethods of another, and to share any /ava
ob)ect type, even if client or server has never co$e across that ob)ect type before+
@4 *5at i1 ?a6a 2ean1< Enumerate it1 a+6antage14 C"9 No6;De( -00,D

Prepared by
Ms.A.Subathra Devi
16
 A /ava Bean is a re&sable software co$ponent that wor!s with /ava+ 8ore
specifically3 a /ava Bean is a re&sable software co$ponent that can be vis&ally
$anip&lated in b&ilder tools+
 .ractically, they are classes written in the /ava pro(ra$$in( lan(&a(e confor$in( to
a partic&lar convention+ They are &sed to encaps&late $any ob)ects into a sin(le
ob)ect (the bean, so that they can be passed aro&nd as a sin(le bean ob)ect instead
of as $&ltiple individ&al ob)ects+
 In order to f&nction as a /avaBean class, an ob)ect class $&st obey certain
conventions abo&t $ethod na$in(, constr&ction, and behavior+
 The re1&ired conventions are3
⇒ The class $&st have a no*ar(&$ent p&blic constr&ctor+ This allows easy
instantiation within editin( and activation fra$ewor!s+
⇒ The class properties $&st be accessible &sin( (et, set, and other $ethods
followin( a standard na$in( convention+ This allows easy a&to$ated
inspection and &pdatin( of bean state within fra$ewor!s, $any of which
incl&de c&sto$ editors for vario&s types of properties+
⇒ The class sho&ld be seriali4able+ This allows applications and fra$ewor!s to
reliably save, store, and restore the bean:s state in fashion that is
independent of the '8 and platfor$+
 .roperties are attrib&tes of a Bean that are referenced by na$e+ These properties
are &s&ally read and written by callin( $ethods on the Bean specifically created for
that p&rpose+
 The $ethods of a Bean are )&st the /ava $ethods e%posed by the class that
i$ple$ents the Bean+ These $ethods represent the interface &sed to access and
$anip&late the co$ponent+
 Events are the $echanis$ &sed by one co$ponent to send notifications to another+
#ne co$ponent can re(ister its interest in the events (enerated by another+
0henever the event occ&rs, the interested co$ponent will be notified by havin( one
of its $ethods invo!ed+
 Introspection is the process of e%posin( the properties, $ethods, and events that a
/avaBean co$ponent s&pports+ This process is &sed at r&n*ti$e, as well as by a
vis&al develop$ent tool at desi(n*ti$e+ The defa&lt behavior of this process allows
for the a&to$atic introspection of any Bean+
 0hen yo& are &sin( a vis&al develop$ent tool to asse$ble co$ponents into
applications, yo& will be presented with so$e sort of &ser interface for c&sto$i4in(
Bean attrib&tes+ These attrib&tes $ay affect the way the Bean operates or the way it
loo!s on the screen+
 It is necessary that Beans s&pport a lar(e variety of stora(e $echanis$s+ This way,
Beans can participate in the lar(est n&$ber of applications+ The si$plest way to
s&pport persistence is to ta!e advanta(e of /ava #b)ect 2eriali4ation+ This is an
a&to$atic $echanis$ for savin( and restorin( the state of an ob)ect+
 There is no re1&ire$ent that a Bean be visible at r&n*ti$e+ It is perfectly reasonable
for a Bean to perfor$ so$e f&nction that does not re1&ire it to present an interface
to the &ser@ the Bean $ay be controllin( access to a specific device or data feed+
 The iss&e of $&ltithreadin( is no different in /avaBeans than it is in conventional
/ava pro(ra$$in(+ The /avaBeans architect&re doesn:t introd&ce any new lan(&a(e
constr&cts or classes to deal with threadin(+
 Beans are s&b)ected to the sa$e sec&rity $odel as standard /ava pro(ra$s+ >o&
sho&ld ass&$e that yo&r Bean is r&nnin( in an &ntr&sted applet+ >o& sho&ldn:t $a!e
any desi(n decisions that re1&ire yo&r Bean to be r&n in a tr&sted environ$ent+
Prepared by
Ms.A.Subathra Devi
17
9. EGplain RM$ Ar(5ite(ture<
&ses a layered architect&re, each of the layers co&ld be enhanced or replaced witho&t
affectin( the rest of the syste$+ The details of layers can be s&$$arised as follows3
?+ Application =ayer3 The client and server pro(ra$
;+ 2t&b & 2!eleton =ayer3 Intercepts $ethod calls $ade by the client"redirects these calls to
a re$ote 98I service+
E+9e$ote 9eference =ayer3 Understands how to interpret and $ana(e references $ade
fro$ clients to the re$ote service ob)ects+
<+Transport layer3 Based on TC."I. connections between $achines in a networ!+ It provides
basic connectivity, as well as so$e firewall penetration strate(ies+
004 7o: +o 3ou pa(8 an applet into a ?AR =ile <
An i$portant &se of the /A9 &tility is to opti$i4e applet loadin(+ In /ava ?+B, people
tended to try to cra$ all their code into a sin(le applet class so the client wo&ld need only a
sin(le server hit to download the applet code+ Not only did this res&lt in $essy, hard*to*read
(and $aintain pro(ra$s, b&t the +class file was still &nco$pressed so downloadin(
wasnQRSt as fast as it co&ld have been+ /A9 files solve the proble$ by co$pressin( all of
yo&r +class files into a sin(le file that is downloaded by the browser+ Now yo& can create the
ri(ht desi(n witho&t worryin( abo&t how $any +class files it will (enerate, and the &ser will
(et a $&ch faster download ti$e+
004 *rite 15ort note1 on T3pe 0) ?D2CHD2C 2ri+ge plu1 D2C Dri6er M it1 t3pe1)
Type 1: JDBC-ODBC Brd!e plus ODBC Dr"er:
The first type of /DBC driver is the /DBC*#DBC Brid(e+ It is a driver that provides
/DBC access to databases thro&(h #DBC drivers+ The #DBC driver $&st be confi(&red on
the client for the brid(e to wor!+ This driver type is co$$only &sed for prototypin( or when
there is no /DBC driver available for a partic&lar DB82+
Type #: $at"e-%&' partly-Ja"a Dr"er:
Native*A.I partly*/ava Driver3 The Native to A.I driver converts /DBC co$$ands to
DB82*specific native calls+ This is $&ch li!e the restriction of Type ? drivers+ The client $&st
have so$e binary code loaded on its $achine+ These drivers do have an advanta(e over
Type ? drivers beca&se they interface directly with the database+

Type (: JDBC-$et &ure Ja"a Dr"er:
/DBC*Net .&re /ava Driver3 The /DBC*Net drivers are a three*tier sol&tion+ This type
of driver translates /DBC calls into a database*independent networ! protocol that is sent to
a $iddleware server+ This server then translates this DB82*independent protocol into a
DB82*specific protocol, which is sent to a partic&lar database+ The res&lts are then ro&ted
bac! thro&(h the $iddleware server and sent bac! to the client+ This type of sol&tion $a!es
it possible to i$ple$ent a p&re /ava client+ It also $a!es it possible to swap databases
witho&t affectin( the client+
Type ): $at"e-&rotocol &ur Ja"a Dr"er:
Native*.rotocol .&r /ava Driver These are p&re /ava drivers that co$$&nicate
directly with the vendorH:s database+ They do this by convertin( /DBC co$$ands directly
into the database en(ineH:s native protocol+ This driver has no additional translation or
$iddleware layer, which i$proves perfor$ance tre$endo&sly+
0-4 De1ign an appli(ation =or online &oo8 1elling u1ing %er6let M ?D2C4
9CNo6;De( -00,D
Prepared by
Ms.A.Subathra Devi
18
?,o to the start*7Control .anel*7Ad$inistrative Tools*7 data so&rces+
;Clic! Add b&tton and select the driver 8icrosoft Access Driver(P+$db+
EAfter selectin( the driver, clic! finish b&tton+
<Then (ive Data 2o&rce Na$e and clic! o! b&tton+
T>o&r D2N will (et created+
A Co$pile yo&r servlet and restart the server and r&n yo&r servlet+
servlet code3
i$port )ava+io+P@
i$port )ava+lan(+P@
i$port )ava+s1l+P@
i$port )ava%+servlet+P@
i$port )ava%+servlet+http+P@
p&blic class 2ervletInsertin(DataUsin(5t$l e%tends 5ttp2ervletJ
p&blic void do.ost(5ttp2ervlet9e1&est re1&est, 5ttp2ervlet9esponse response throws
2ervletE%ception, I#E%ceptionJ
response+setContentType(Dte%t"ht$lD@
.rint0riter pw U response+(et0riter(@
2trin( connectionU9= U D)dbc3odbc3st&dentD@
Connection connection@
tryJ 2trin( &serna$e U re1&est+(et.ara$eter(D&serna$eD@
2trin( password U re1&est+(et.ara$eter(DpasswordD@
pw+println(&serna$e@
pw+println(password@
Class+forNa$e(Ds&n+)dbc+odbc+/dbc#dbcDriverD@
connection U Driver8ana(er+(etConnection(connectionU9=@
.repared2tate$ent pst U connection+prepare2tate$ent(Dinsert into
lo(in(&serna$e,password val&es(V,VD@
pst+set2trin((?,&serna$e@
pst+set2trin((;,password@
int i U pst+e%ec&teUpdate(@
if(iWUBJ
pw+println(D9ecord has been insertedD@
K
elseJ
pw+println(D-ailed to insert the dataD@
K
K
catch (E%ception eJ
pw+println(e@
K
K
K
034 Create a "R#Conne(tion u1ing t5e penConne(tion() met5o+ o= a "R# o&'e(t
an+ t5en u1e it to eGamine t5e +o(umentA1 propertie1 an+ (ontent4
C"9 No6;De( -000D
 E%a$ple3
i$port )ava+s1l+P@
p&blic class 8ys1lConnect
Prepared by
Ms.A.Subathra Devi
19
J
p&blic static void $ain(2trin(MN ar(s
J
2yste$+o&t+println(D8y2F= Connect E%a$ple+D@
Connection conn U n&ll@
2trin( &rl U D)dbc3$ys1l3""localhost3EEBA"D@
2trin( dbNa$e U D)dbct&torialD@
2trin( driver U Dco$+$ys1l+)dbc+DriverD@
2trin( &serNa$e U DrootD@
2trin( password U DrootD@
try
J
Class+forNa$e(driver+newInstance(@
conn U
Driver8ana(er+(etConnection(&rlXdbNa$e,&serNa$e,password@
2yste$+o&t+println(DConnected to the databaseD@
conn+close(@
2yste$+o&t+println(DDisconnected fro$ databaseD@
K
catch (E%ception e
J
e+print2tac!Trace(@
K
K
K
"N$VER%$T/ 9"E%T$N%
PART – A
?+ 0hat are the p&rpose of 2ervletsV M9ef+ F+No3 ?BN
;+ 5ow is anony$o&s inner class &sed with its p&rpose+ M9ef+ F+No3 A?N
E+ 0hat is an inner classV E%plain with an e%a$pleV M9ef+ F+No3 ATN
<+ Define 2ervlet =ife Cycle M9ef+ F+No3 ?EN
PART – 2
?+ Desi(n an application which i$ple$ents 98I Concepts+ M9ef+ F+No3 YN
;+ Desi(n an application for online boo! sellin( &sin( 2ervlet & /DBC+ M9ef+ F+No3 ??N
E+ Ill&strate with a /ava .ro(ra$ a define and &se an inner class+ M9ef+ F+No3 <N
<+ 0hat is the lifecycle of a servletV 0rite short notes on the followin( classes3
,eneris2ervlet, 2ervletInp&t2trea$, 2ervlet#&tp&t2trea$ & 2ervletE%ception+
M9ef+ F+No3 AN
T+ 0hat is /ava BeansV En&$erate its advanta(es+ M9ef+ F+No3 LN
A+ Create a U9=Connection &sin( the #penConnection( $ethod of a U9= ob)ect and
then &se it to e%a$ine the doc&$entZs properties and content+ M9ef+ F+No3 ?EN
Prepared by
Ms.A.Subathra Devi
20
Prepared by
Ms.A.Subathra Devi

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close