You are on page 1of 8

UNIT TEST- III September 2011


DURATION: 1"30 !#$r% MA&" MAR'S: (0
PART ) A *( + 2 , 10-
A.%/er 011 t2e 3$e%t4#.%
1" De54.e RMI"
Remote Method Invocaton (RMI) aows a |ava ob|ect that executes on
one machne to nvoke a method of a |ava ob|ect that executes on
another machne.
2" W20t 4% t2e 6455ere.7e bet/ee. CGI 0.6 %er81et%9
Performance s sgnfcanty better, servet execute wthn the address
space of a web server.
Servets are patform ndependent
The |ava securty manager on the server enforces a set of restrctons
to protect the resources on a server machne.
The fu functonaty of |ava cass brares s avaabe to a servet.
3" W20t 4%
Introspecton s the process of anayzng a Bean to determne ts
capabtes. Ths s an essenta feature of the |ava Beans API, because t
aows an appcaton buder too to present nformaton about a
component to a software desgner. Wthout ntrospecton, the |ava Beans
technoogy coud not operate.
" W20t 4% 0. 710%%9 E+p104. /4t2 0. e+0mp1e9
A cass wthn the cass s caed as an nner cass.
cass A
{ nt a, b,c;
cass B
{ // codng for nner cass }}
(" De54.e :41e 0.6 me.t4#. 0.; t/# met2#6% #5 :41e"
A Fe ob|ect s used to obtan or manpuate the nformaton assocated
wth a dsk fe, such as the permssons, tme, date, and drectory path,
and to navgate subdrectory herarches.
getName( ) returns the name of the fe
getParent( ) returns the name of the parent drectory
PART- B *0 M0r<%-
6" *0- D4%7$%% RMI 0.6 7re0te 0 %4mp1e 714e.t=%er8er 0pp1470t4#.
$%4.> RMI" *16-
I.ter507e Pr#>r0m:
mport |ava.rm.*;
pubc nterface AddServerIntf extends Remote {
doube add(doube d1, doube d2) throws RemoteExcepton;
doube sub(doube d1, doube d2) throws RemoteExcepton;
doube mu(doube d1, doube d2) throws RemoteExcepton;
doube dv(doube d1, doube d2) throws RemoteExcepton;
Imp1eme.t0t4#. Pr#>r0m:
mport |ava.rm.*;
mport |ava.rm.server.*;
pubc cass AddServerImp extends UncastRemoteOb|ect
mpements AddServerIntf {
pubc AddServerImp() throws RemoteExcepton {
pubc doube add(doube d1, doube d2) throws RemoteExcepton {
return d1 + d2;
pubc doube sub(doube d1, doube d2) throws RemoteExcepton {
return d1 - d2;
pubc doube mu(doube d1, doube d2) throws RemoteExcepton {
return d1 * d2;
pubc doube dv(doube d1, doube d2) throws RemoteExcepton {
return d1/ d2;
Ser8er Pr#>r0m:
mport |*;
mport |ava.rm.*;
pubc cass AddServer {
pubc statc vod man(Strng args||) {
try {
AddServerImp addServerImp = new AddServerImp();
Namng.rebnd("AddServer", addServerImp);
catch(Excepton e) {
System.out.prntn("Excepton: " + e);
C14e.t Pr#>r0m:
mport |ava.rm.*;
pubc cass AddCent {
pubc statc vod man(Strng args||) {
try {
Strng addServerURL = "rm://" + args|0| + "/AddServer";
AddServerIntf addServerIntf =
System.out.prntn("The frst number s: " + args|1|);
doube d1 = Doube.vaueOf(args|1|).doubeVaue();
System.out.prntn("The second number s: " + args|2|);
doube d2 = Doube.vaueOf(args|2|).doubeVaue();
System.out.prntn("The sum s: " + addServerIntf.add(d1, d2));
System.out.prntn("The sum s: " + addServerIntf.sub(d1, d2));
System.out.prntn("The sum s: " +, d2));
System.out.prntn("The sum s: " + addServerIntf.dv(d1, d2));
catch(Excepton e) {
System.out.prntn("Excepton: " + e);
6" *b- (i) Mention the benefits of Java beans and discuss JAR files (6)
A Bean obtans a the benefts of |avas "wrte-once, run-anywhere"
The propertes, events, and methods of a Bean that are exposed to
an appcaton buder too can be controed.
A Bean may be desgned to operate correcty n dfferent ocaes,
whch makes t usefu n goba markets.
Auxary software can be provded to hep a person confgure a
Bean. Ths software s ony needed when the desgn-tme
parameters for that component are beng set. It does not need to be
ncuded n the run-tme envronment.
The confguraton settngs of a Bean can be saved n persstent
storage and restored at a ater tme.
A Bean may regster to receve events from other ob|ects and can
generate events that are sent to other ob|ects.
JAR :41e%:
The |AR Utty
A utty s used to generate a |AR fe. Its syntax s shown here:
?0r #pt4#.% 541e%
Cre0t4.> 0 JAR :41e
The foowng command creates a |AR fe named Xyz.|ar that contans a
of the .cass and .gf fes n the current drectory:
?0r 75 &;@"?0r A"710%% A">45
If a manfest fe such as s avaabe, t can be used wth the
foowng command:
?0r 75m &;@"?0r B+@"m5 A"710%% A">45
T0b$10t4.> t2e C#.te.t% #5 0 JAR :41e
The foowng command sts the contents of Xyz.|ar:
?0r t5 &;@"?0r
E+tr07t4.> :41e% 5r#m 0 JAR :41e
The foowng command extracts the contents of Xyz.|ar and paces those
fes n the
current drectory:
?0r +5 &;@"?0r
Up60t4.> 0. E+4%t4.> JAR :41e
The foowng command adds the fe fe1.cass to Xyz.|ar:
?0r -$5 &;@"?0r 541e1"710%%
Re7$r%4.> D4re7t#r4e%
The foowng command adds a fes beow drectoryX to Xyz.|ar:
?0r -$5 &;@"?0r -C 64re7t#r;& A
(ii) Explain Bean Builder with an example (1)
A680.t0>e% #5 Be0. B$416er:
Powerfu & Spohstcated.
Easer to use.
T/# m#6e% #5 Oper0t4#.:
Desgn mode - construct a Bean-based appcaton, addng the
varous components, and wrng them together
Test mode or run-tme mode - appcaton s executed and a of the
components are ve.
T2ree W4.6#/%:
Current paette set
Property Inspector wndow provded by Bean Buder.
Desgn wndow
C" *0- Wr4te 0 Ser81et pr#>r0m /4t2 60t0b0%e 7#..e7t484t; 5#r 0
/eb b0%e6 PNR .$mber e.3$4r; 0pp1470t4#.
mport |avax.servet.*;
mport |avax.servet.http.*;
mport |ava.o.*;
mport |ava.sq.*;
pubc cass |dbcServet extends HttpServet
Connecton dbConn;
pubc vod nt(ServetConfg confg)throws ServetExcepton
catch(CassNotFoundExcepton e)
System.out.prntn("|DBC-ODBC brdge not found");
catch(SOLExcepton e)
System.out.prntn("SOL excepton thrown n nt");
pubc vod doGet(HttpServetRequest
request,HttpServetResponse response)throws
PrntWrter out=response.getWrter();
Statement stat=dbConn.createStatement();
ResutSet customers=stat.executeOuery(
"SELECT PNRNumber, status FROM " + " Tran");
out.prntn("<H2> Detas </H2>");
out.prntn("<TABLE BORDER=1>");
out.prntn("<TR><TH>PNR Number</TH>");
out.prntn("<TH>Status </TH>");
out.prntn("<TR><TD>" +
customers.getStrng("PNRNumber") + "</TD><TD>"
customers.getStrng("status") + "</TD><TD>" +
catch (Excepton e)
pubc Strng getServetInfo()
return "Sampe |DBC Servet";
C" *b- E+p104. t2e 80r4#$% I=O p07<0>e% 080410b1e 4. J080"
|ava programs perform I/O through streams.
A stream s an abstracton that ether produces or consumes nformaton.
J080 2 6e54.e% t/# t;pe% #5 %tre0m%"
(1) byte Stream
(2) character Stream
B;te %tre0m% provde a convenent means for handng nput and output
of bytes. Byte streams are used, when readng or wrtng bnary data.
C20r07ter %tre0m% provde a convenent means for handng nput and
output of characters
B;te Stre0m% FeInputStream
C20r07ter Stre0m%
D" *0- *4- D4%7$%% 0b#$t Ser4014@0t4#. /4t2 e+0mp1e
Serazaton s the process of wrtng the state of an ob|ect to a byte
At a ater tme, you may restore these ob|ects by usng the process of
nterfaces and casses that support serazaton
Ony an ob|ect that mpements the Ser4014@0b1e 4.ter507e 70. be
%08e6 0.6 re%t#re6 b; the serazaton factes.
The Ser4014@0b1e 4.ter507e 6e54.e% .# member%"
It 4% %4mp1; used to ndcate that a cass may be serazed.
If a cass s serazabe, a of ts subcasses are aso serazabe.
The Ob|ectOutput nterface e+te.6% the DataOutput nterface and
supports ob|ect serazaton.
A of these methods w throw an IOE+7ept4#. #. err#r 7#.64t4#.%"
The Ob|ectOutputStream cass extends the O$tp$tStre0m cass and
mpements the Ob?e7tO$tp$t 4.ter507e"
It s responsbe for /r4t4.> #b?e7t% to a stream.
Ob|ectOutputStream(OutputStream outStream) throws IOException
The argument outStream s the output stream to whch serazed ob|ects
w be wrtten. It throw an IOExcepton on error condtons
The Ob?e7tI.p$t 4.ter507e extends t2e D0t0I.p$t 4.ter507e"
re06Ob?e7t* - to deseraze an ob|ect.
A of these methods w throw an IOE+7ept4#. #. err#r 7#.64t4#.%"
The Ob|ectInputStream cass extends the I.p$tStre0m cass and
4mp1eme.t% t2e Ob?e7tI.p$t 4.ter507e.
Ob|ectInputStream s responsbe for re064.> #b?e7t% 5r#m 0
Ob|ectInputStream(InputStream inStream) throws IOExcepton,
The argument nStream s the nput stream from whch serazed
ob|ects shoud be read.
Wr4te 0 Pr#>r0m 5#r %er4014@4.> 0. #b?e7t"
D" *b- E+p104. JDBC /4t2 0. e+0mp1e pr#>r0m"
The prmary purpose of |DBC s to provde connectvty wth a
|DBC s an API specfcaton that provdes a set of nterfaces and
casses to perform database reated operatons.
|ava programs, |ava servets and |ava Beans can access the
databases through the |DBC.
A operatons of databases ke nserton, seecton, modfcatons
can be done.
J080 API
Bascay there are four fundamenta casses n the |DBC API namey
|dbc DrverManager mantan a st of Drver casses that have regstered
It s a cass that regster |DBC drvers and suppes connectons.
The most commony used method s
A connecton s an actve nk to the database through whch a |ava
program can read & wrte data.
A connecton ob|ect s created by a ca to
A statement s an ob|ect that aows SOL statement to be sent through a
connecton and retrve the resutset.
A statement s created wth
An ordered set of tabe rows produced by an SOL query.
A resutset s most often encountered wth
%t0teme.t"e+e7$teE$er;*%31%tr4.>- method ca.
It s used to retreve the resuts generated by the SOL query.
JDBC Dr48er% - :#$r t;pe% #5 JDBC 6r48er%
Type1: |DBC-ODBC Brdge
Type2:Both Natve & |ava Drvers:
Type3 Pure |ava drver for database mddeware:
Type4 Drect to database pure |ava drver: