0% found this document useful (0 votes)
116 views8 pages

Subject: Web Programming CODE: 600314 Branch: Mca Semester: Iii DURATION: 1.30 Hours Max. Marks: 50

This document contains questions and answers related to web programming. It discusses Remote Method Invocation (RMI) allowing objects on one machine to invoke methods on another. It compares CGI and servlets and explains introspection, inner classes, File objects, and benefits of Java beans. It also includes sample code for an RMI client-server application to perform basic math operations and a servlet program to query a database and display results.

Uploaded by

Karthik Keyan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
116 views8 pages

Subject: Web Programming CODE: 600314 Branch: Mca Semester: Iii DURATION: 1.30 Hours Max. Marks: 50

This document contains questions and answers related to web programming. It discusses Remote Method Invocation (RMI) allowing objects on one machine to invoke methods on another. It compares CGI and servlets and explains introspection, inner classes, File objects, and benefits of Java beans. It also includes sample code for an RMI client-server application to perform basic math operations and a servlet program to query a database and display results.

Uploaded by

Karthik Keyan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 8

UNIT TEST- III September 2011

SUBJECT: WEB PROGRAMMING CODE : 60031


BRANC! : MCA SEMESTER: III
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% 4.tr#%pe7t4#.9
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. 4..er 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 |ava.net.*;
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 =
(AddServerIntf)Namng.ookup(addServerURL);
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: " + addServerIntf.mu(d1, d2));
System.out.prntn("The sum s: " + addServerIntf.dv(d1, d2));
}
catch(Excepton e) {
System.out.prntn("Excepton: " + e);
}
}}
*OR-
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"
paradgm.
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 Yxz.mf 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#.
*16-
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
{
super.nt(confg);
try
{
Cass.forName("sun.|dbc.odbc.|dbcOdbcDrver");
dbConn=DrverManager.getConnecton("|dbc:odbc:Northwnd");
}
catch(CassNotFoundExcepton e)
{
System.out.prntn("|DBC-ODBC brdge not found");
return;
}
catch(SOLExcepton e)
{
System.out.prntn("SOL excepton thrown n nt");
return;
}
}
pubc vod doGet(HttpServetRequest
request,HttpServetResponse response)throws
ServetExcepton,IOExcepton
{
try
{
response.setContentType("text/htm");
PrntWrter out=response.getWrter();
Statement stat=dbConn.createStatement();
ResutSet customers=stat.executeOuery(
"SELECT PNRNumber, status FROM " + " Tran");
out.prntn("<HTML>");
out.prntn("<HEAD><TITLE>StatusofPNR</TITLE></HEAD>");
out.prntn("<BODY>");
out.prntn("<H2> Detas </H2>");
out.prntn("<TABLE BORDER=1>");
out.prntn("<TR><TH>PNR Number</TH>");
out.prntn("<TH>Status </TH>");
whe(customers.next())
{
out.prntn("<TR><TD>" +
customers.getStrng("PNRNumber") + "</TD><TD>"
+
customers.getStrng("status") + "</TD><TD>" +
}
out.prntn("</TABLE>");
out.prntn("</BODY></HTML>");
out.cose();
}
catch (Excepton e)
{
e.prntStackTrace();
}
}
pubc Strng getServetInfo()
{
return "Sampe |DBC Servet";
}
}
*OR-
C" *b- E+p104. t2e 80r4#$% I=O p07<0>e% 080410b1e 4. J080"
*16-
|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
FeOutputStream
ByteArrayInputStream
ByteArrayOutputStream
BufferedInputStream
BufferedOutputStream
PushbackInputStream
SequenceInputStream
PrntStream
C20r07ter Stre0m%
FeReader
FeWrter
CharArrayReader
CharArrayWrter
BufferedReader
BufferedWrter
PushbackReader
PrntWrter
D" *0- *4- D4%7$%% 0b#$t Ser4014@0t4#. /4t2 e+0mp1e
*D-
Serazaton s the process of wrtng the state of an ob|ect to a byte
stream.
At a ater tme, you may restore these ob|ects by usng the process of
deserazaton.
nterfaces and casses that support serazaton
Ser4014@0b1e
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.
Ob?e7tO$tp$t
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#.%"
Ob?e7tO$tp$tStre0m
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
Ob?e7tI.p$t
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#.%"
Ob?e7tI.p$tStre0m
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
%tre0m"
C#.%tr$7t#r:
Ob|ectInputStream(InputStream inStream) throws IOExcepton,
StreamCorruptedExcepton
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"
*OR-
D" *b- E+p104. JDBC /4t2 0. e+0mp1e pr#>r0m"
*D-
The prmary purpose of |DBC s to provde connectvty wth a
database.
|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
|ava.sq.DrverManager
|ava.sq.Connecton
|ava.sq.Statement
|ava.sq.Resutset
?080"%31"Dr48erM0.0>er:
|dbc DrverManager mantan a st of Drver casses that have regstered
themseves.
It s a cass that regster |DBC drvers and suppes connectons.
The most commony used method s
Dr48erM0.0>er">etC#..e7t4#.*-
?080"%31"C#..e7t4#.:
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
Dr48erM0.0>er">etC#..e7t4#.*-
?080"%31"St0teme.t:
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
7#..e7t4#."7re0teSt0teme.t*-
?080"%31"Re%$1t%et:
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:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy