Documente Academic
Documente Profesional
Documente Cultură
V
Advanced Java
Time : 2½ Hrs.] Prelim Question Paper [Marks : 75
r
Here Checkbox Group is a class which is used sed to convert a checkbox into a
radio button.
ka
Checkbox Group has following two methods
1) get Selected Checkbox ( );
thods
ds :
an
cted
d Checkbo
It is used to retrieve a selected Checkbox.
Checkbox
eckbox c);
2) Set Selected Checkbox (Checkbox
n appropriate
It is used to select an propriate C
Chec
Checkbox.
al
Methods of Checkbox ox :
dy
i) getLabel( );
It is used to retrieve name of the Checkbox.
el(string s);
ii) setLael(string
Vi
ed
d to se
It is used set a ne
new name on a Checkbox.
iii) getState( );
It is used to retrieve state of the Checkbox.
1014/BSc/IT/TY/Pre_Pap/2014/Adv. Java 1
Vidyalankar : T.Y. B.Sc. (IT) – Adv. Java
ST NS
Current Selection :
Java : True
Linux : False
ASP : False
ST : False
NS : False
import java.applet.*;
import java.awt.event.*;
import.java.awt.*;
/* <applet code = test width = 200 height = 30>>
r
< /applet>/
ka
public class test extends Applet implements
ItemListener
{
nts
ts
an
Checkbox c1, c2, c3, c4, c5,
public void init( )
{
al
c5 = new Ch
Check
Checkbox (”NS”);
c1.addItem
addIte Listener (this);
d
c2.addItem Listener (this);
c3.addItem Listener (this);
c4.addItem Listener (this);
c5.addItem Listener (this);
add(c1);
add(c2);
add(c3);
add(c4);
add(c5);
}
2
Prelim Paper Solution
{
string a = “Current Selection”;
string b = “Java” + c1.getState( );
string c = “Linux” + c2.getState( );
string d = “ASP” + c3.getState( );
string e = “ST” + c4.getState( );
string f = “NS” + c5.getState( );
r
public void itemStateChanged (Itemevent
event
nt ie);
{
}
ka
repaint( );
an
}
ent is de3fined
i) Event de3fin as the object which describe the state change of
ticul source.
the particular s
ii) Event canan be
b occur on multiple conditions like clicking on a button.
Selecting a Checkbox, Scrolling the scrollbars, etc.
2) Source
i) Definition : Source are the objects which generates a particular
event.
ii) If we want a particular source should generate a particular event, in
that case that source should get registered with a specific event
using following method :
addTypeListener (TypeListener tl);
3
Vidyalankar : T.Y. B.Sc. (IT) – Adv. Java
3) EventListeners
i) EventListeners are those interfaces which contains different
methods which are used or get override to receive the event and
take the corrective action on that event.
ii) ActionListener, ItemListener, MouseListener, etc. are different
interfaces which can be used to override their methods.
r
vent only when it iis registered for
A component can generated a particular event
ka
that particular event.
ss.
Q.1(c) Write a short note on Inner class. [5]
an
(A) Inner Class [4 mark]
Example :
import java.awt.*;
al
import java.awt.event.*;
*;
dy
testevent(
ent(
nt( )
{
setLayoutt ((new FlowLayout( ));
Label l = new Label (“select a color :”);
add (l);
4
Prelim Paper Solution
add (b1);
add (b2);
add (b3);
r
Color c3 = new Color (0,0,255);
ka
if (s.equals (“Red”))
{
an
setBackground (c1);
}
Green”))
en ))
else if (s.equals (“Green”))
al
{
ground
round (c2);
setBackground
else
dy
{
setBackgro
setBackground (c3);
}
Vi
}
emo e
class demo extends WindowAdapter
{
public void WindowCloasing (WindowEvent we);
{
System.exit (0);
}
}
5
Vidyalankar : T.Y. B.Sc. (IT) – Adv. Java
r
{
ka
Frame f;
testevent( )
{
an
f = new Frame( );
f.setLayout(new FlowLayout(
wLayout( ))
));
Label l = new Label
el (“select a color:”);
co
al
on b2 = new Button
Button Butto (“Green”);
But
Button
utton Button (“Blue”);
tton b3 = new Bu
Vi
b1.addActionListener (this);
b1.addActionL
b1.addA
b2.addActionListener
2.addAct (this);
dA
b3.addActionListener (this);
f.addWindowListener (this);
f.add(l);
f.add(b1);
f.add(b2);
f.add(b3);
6
Prelim Paper Solution
if (s.equals (“Red”))
{
f.setBackground (c1);
}
else if (s equals (“Green”))
{
f.setBackground (c2);
r
}
else
{ ka c3);
f.setBackground (c3);
an
}
}
al
System.exit (0);
tem.exit (0)
}
Vi
Pubic
c Static void main (String a[ ])
bic
{
test ev
event t = new testevent( );
}
}
7
Vidyalankar : T.Y. B.Sc. (IT) – Adv. Java
r
components
ka
AWT Components
1) AWT components are non java a
Swing Com
Swing components
componen
compone
comp
components
Components
are pure java
an
2) They are platform dependent
endent They arear platform independent
components com
compon
components
3) They are non decorative components
mponents The
They
T are decorative. We can even
al
shape components
5) Those are e considered as heavy Those are considered as light weight
omponents
weight components components
Vi
6) They arere not used to perform They are used to perform complex
erations
tion
complex operations operations
7) Those classes are present in java.awt Those classes are present in
package javax.swing package
8
Prelim Paper Solution
Message
OK
Message
Yes No Cancel
r
ka e);
(c) ShowInputDialog(String message);
Message
sage
an
OK
K Cancel
al
It is used to display a po
pop-up which is used to accept an input from
pop-u
dy
the userss
c
Q.2(c) Write a program to create a combobox, and add different items in [5]
Vi
that combobox
obox accepting them from user.
box by accep
(A) import java.awt.*;
wt.*;
eve
import java.awt.event.*;
import javax.swing.*;
class combo extends JFrame implements ActionListener
{
JComboBox jc;
JButton jb;
JTextField jt;
combo()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
9
Vidyalankar : T.Y. B.Sc. (IT) – Adv. Java
jc=new JComboBox();
jb=new JButton("Add");
jt=new JTextField(10);
jb.addActionListener(this);
c.add(jc);
c.add(jt);
c.add(jb);
setSize(500,500);
setVisible(true);
LOSE);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);E);
}
r
e)
public void actionPerformed(ActionEvent ae)
{
ka
String s=jt.getText();
jc.addItem(s);
an
}
public static void main(String
ng args[])
gs[])
{
al
Q.2(d) Write a program to cr create a table and perform addition and removal [5]
Vi
of rows by accepting
acceptin row no, using 2 buttons "Add" and "Remove".
(A) import java.awt.*;
wt.*;
ng
import javax.swing.*;
import java.awt.event.*;
import javax.swing.table.*;
table()
10
Prelim Paper Solution
{
Container c=getContentPane();
c.setLayout(new BorderLayout());
String data[][]={{"1","sss","dadar"},{"2","akn","sion"},{"3","sdw","thane"}};
String colheads[]={"Id","Name","Address"};
dt=new DefaultTableModel(data,colheads);
j=new JTable(dt);
jsp=new JScrollPane(j);
jb1.addActionListener(this);
r
jb2.addActionListener(this);
ka
c.add(jsp,BorderLayout.CENTER);
c.add(jb1,BorderLayout.NORTH);
an
c.add(jb2,BorderLayout.SOUTH); H);
setSize(1000,500);
setVisible(true);
al
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ation(JFrame.EXIT
JFrame.E
}
dy
if(s.equals("Add
dd Row"))
Row")
{
String a=JOptionPane.showInputDialog("Enter row number");
int m=Integer.parseInt(a);
String b=JOptionPane.showInputDialog("Enter Id");
String c=JOptionPane.showInputDialog("Enter Name");
String d=JOptionPane.showInputDialog("Enter Address");
String e[]={b,c,d};
dt.insertRow(m,e);
}
else
{
String f=JOptionPane.showInputDialog("Enter row number to be deleted");
11
Vidyalankar : T.Y. B.Sc. (IT) – Adv. Java
int n=Integer.parseInt(f);
dt.removeRow(n);
}
}
public static void main(String args[])
{
table t=new table();
}
}
username :
r
password :
ka Login
an
<html>
<head>
<title> Servlet Applicationn </title>
title> </head>
</he
al
<body>
<form method = "post" t" action = "test">
ost" "t
"test
dy
//test.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class test extends HttpServlet
{
public void doPost(HttpServletRequest Request,
HttpServletResponse Response) throws IOException
ServletException
12
Prelim Paper Solution
{
response.setContentType("text/html?);
PrintWriter out = response.getWriter( );
String n = request.getParameter("u");
String p = request.getParameter("p");
out.print ln("H \ }} ");
if((n.equals("admin")) && (p.equals("admin")))
{
RequestDispatcher rd1 = request.getrequestDispatchers
("Welcome");
rd1.include(request, response);
}
else
{
RequestDispatchers rd2 = request.getRequestDispatchers
uest.getReques
t.getRequ
r
("Errors");
} ka
out.close( );
forward(request,
ward(reques rresponse);
rd2.forward(request,
an
}
}
al
ethod
following method
equestDispatcher(
questDispatcher( );
getRequestDispatcher(
stDispatchers is a class which is there inside the package
stDispatcher
2) RequestDispatchers
Vi
ervlet
javax.servlet
spatche can be created for following 2 reasons.
3) RequestDispatcher
(a) To includede the contains of RequestDispatcher into the current
Servlet application for that purpose we are using include( ); of
RequestDispatcher.
(b) To forward the control from current servlet application to any
requestDispatcher servlet. For that purpose we are using forward(
); of RequestDistpacher.
13
Vidyalankar : T.Y. B.Sc. (IT) – Adv. Java
2) When a new client sends a request for a Servlet, Servlet will create a
session Memory to store a transaction information about a that
particular client.
3) Apart from that Servlet also generate a Session ID to keep a trap for
that session Memory.
4) Servlet Sends the SessionID to the client side. Application which will
get stored inside the client machine.
5) Next time if the Same client wants to do the transaction with the same
Servlet, then client will send request packet with session ID.
6) By retrieving the session ID, Servlet updates Session Memory for new
transaction generater new SessionID & send it to the client.
7) To perform this mechanism following three techniques can be used.
(a) Hidden formField :
x It is used by the client to send a Session sion ID to the Servlet.
x It is in Hidden form & only Servlet et can
an read it & Hence called as
r
Hidden form field.
ka
(b) Url rewriting :
x It is used to send SessionID
x Servlet can put the SessionID
nID to the client.
sionID inside
insi
clie
rresponse packet or it will
an
generate a special token
oken to send a Se
SessionID
(c) Cookies :
x By using cookie, okie, a Servl
Servlet ana send SessionID to the client
al
machine.
x For thatt purpose Servlet
Serv will create a new cookie for Session ID &
dy
Roll No. and Name from user. It should also have a button named "display"
licked should send those value to the servlet. Servlet
which when clicked
application should accept them display them on web browser.
Roll No. :
Name :
Display
14
Prelim Paper Solution
r
{
{
ka
public void doGet(HttpServletRequestt req, HttpServletResponse
throws IOException, Servlet
HttpServlet
HttpSer
et Exception
res)
an
xt/html");
res.setContentType("text/html");html");
PrintWriter pw = res.getWriter(
getWriter(
etWriter( );
arseInt(req.getPa
eInt(req.ge
int roll = Integer.parseInt(req.getParameter("r"));
al
eq.getParameter("
getParamet
String name = req.getParameter("n");
pw.println ("The
The roll no. =" + roll);
ro
n("<br>");
br>");
pw.println("<br>");
dy
{
printl
pw.println("Session is new");
}
else
{
pw.println("session is old");
pw.println("session id =" + hs.getId( ));
pw.println("Creationtime =" + hs.getId( ));
pw.println("Lastaccessed time =" + hs.getLastAccessedTime");
}
pw.cloase( );
}
}
15
Vidyalankar : T.Y. B.Sc. (IT) – Adv. Java
r
<br>
</form>
</body>
ka mit">
t">
<input type="submit" value="Submit">
an
</html>
//test.java
al
import java.io.*;
t.*;
import javax.servlet.*;*;
dy
vlet.http.*;
import javax.servlet.http.*;
16
Prelim Paper Solution
{
out.println("Correct Answer");
}
}
finally
{
out.close();
}
}
}
r
<head>
ka
<meta http-equiv="Content-Type" content="text/htm
<title>JSP Page</title>
</head>
tent="text/
content="text/html; charset=UTF-8">
an
<body>
<form method="post" action="calculate">
n="calculat
or</h1>
h1>
<h1>Simple Calculator</h1>
al
<hr>
<b>Enter First Number</b>
dy
e="number"
="number" name="
<input type="number" name
name="n1" value="" size="2">
<p>
ter Second N
<b>Enter Numb
Number</b>
Vi
<input type="number
type="n
type="number" name="n2" value="" size="2">
<p>
per
<b>Enter Operation</b>
<input type="text" name="op" value="" size="2">
<p>
<input type="submit" value="Calculate">
</form>
</body>
</html>
//calculate.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
17
Vidyalankar : T.Y. B.Sc. (IT) – Adv. Java
r
c=a+b;
}
ka
else if(op.equals("-"))
{
an
c=a-b;
}
"*")))
else if(op.equals("*"))
al
{
c=a*b;
dy
}
else
{
Vi
c=a/b;
a/b;
/b;
}
n(
out.println("The Result is "+c);
} finally {
out.close();
}
}
}
18
Prelim Paper Solution
r
ps.setInt(1,10);
ka
ps.setString(2,"SSS");
ps.execute();
ps.close();
an
c.close();
}
catch(Exception e)
al
{
System.out.println("Exception
println("Exception
rintln("Excep occur");
dy
}
}
}
Vi
cter quo
Q.4(b) Explain character quoting convention in JSP [5]
(A) Character Quotingng Conventions
Because certain character sequences are used to represent start and stop
tags, the developer sometimes need to escape a character so the JSP engine
does not interpret it as part of a special character sequence.
19
Vidyalankar : T.Y. B.Sc. (IT) – Adv. Java
Escape Description
Characters
\' A single quote in attribute that uses single quotes.
\ '' A double quote in an attribute that uses double quotes.
\\ A backslash in an attribute that uses backslash.
%\> Escaping the scripting end tag with a backslash.
<\% Escaping the scripting start tag with a backslash.
\$ Escaping the dollar sign [dollar sign is used to start an EL
expression] with a backslash
Example
<% String message = ‘Escaping \’ single
e quote’;
uote’; %>
r
ouble quote’; %
<% String message = ‘Escaping \’ double %>
ka
<% String message = ‘Escaping \ \ backslash’; %>
<% String message = ‘Escaping
ng % \ > scripting
aping
script
ng < \ % scriptin
<% String message = ‘Escaping scr
%
end tag’’; %>
e
scripting start tag’’; %>
an
<% String message = ‘Escaping
scaping \$ dollar
Escaping dol sign”
s ; %>
caping
As an alternative to escapinging quote cha
characters, the character entities
al
delete from em
s.execut("delete employ }} )
ate("updat
("up
s.executUpdate("update employ }} )
c.commit( );
ResultSet rs = s.executeQuery("select * from employee");
i) In case of JDBC the default value of commit protocol is true.
ii) Which means all the transaction will get perform in the same order as
they are written in the JDBC application.
iii) We can make the value of commit protocol as false with the help of
following method
c.setAutoCommit (false);
iv) It means all the transaction written after this will be kept hold and only
will get performed when we called the commit protocol.
v) All the transaction because of this will execute simultaneously at a same
time.
20
Prelim Paper Solution
vi) The major problem of using this transaction mechanism is that when 2
operations will get perform on the same record, sometime it will
generate deadlock condition.
vii) To overcome this deadlock transaction mechanism uses rollback concept.
viii)Because of rollback all the transaction will get undone and the operation
will get nullified.
r
code.
ka
x After this stage there is no JSP
x The resultant is a java class
(b) Compilation :
SP everything is a servlet.
ss instead
nstead of aan ht
html page (JSP page)
an
x The generated servletet iss compiled tto vvalidate the syntax.
enerate
nerate class file to run on JVM.
x The compilation generate
(c) Loading :
al
If not
Request
ues
Client initi
initialized Translation Compilation Loading
Vi
Already
Initializ Initialization Instantiation
Response
Request Processing
Destruction
(d) Instantiation:
x In this step, instance of the servlet class is created, so that it
can handle request.
21
Vidyalankar : T.Y. B.Sc. (IT) – Adv. Java
(e) Initialization :
x It can be done using jspInit( ). This is one time actively and after
initialization, the servlet is ready to process requests.
3) Destroy : Whenever the server needs memory, the server removes the
instance of the servlet.
The jspDestory( ) can be called by the server after initialization and before
or after request processing.
r
ka Response
e
plete
complete
Response
complete
an
Faces
Restore Apply Process
cess Process Process
response request
view event Validation event
values
al
e
Reader response
Response
Resp
Response co
complete
complete Response complete
dy
Faces
Render Process
rocess Invotie Process Update
response model
Vi
response
e Event application Event
values
Conversion
Convers error/render
22
Prelim Paper Solution
ii) If any error occur then the error message will get store inside
“Facescontext” object.
3. Process validation
i) In this the local values of the component will get checked with the
validation rule registered for a components.
ii) If the rules does not match then the error message will get render
to a client.
4. Update model values
i) In this face the components from component tree will update the
component present inside the webserver.
ii) It is also called as baching a bear.
5. Invest application
i) In this face the application will get invest st or
o execute to create
responses.
ii) Also if they are multiple pages then lintsing
tsing of thos
tthose page will also
r
get done in this phase.
6.
ka
Render response
In this phase the generated responses
client as a response.
ponses
ses will get re
render i.e. provided to a
an
Q.5(b) Explain advantages of EJB.. [5]
(A) Advantages of EJB
al
endent, EJB
Apart from platform independent, E has following advantages.
x More focus on n business log
logic : In industry because of use EJB the
dy
be usedd in another
anot we server.
web
x Reusable compone
component : We can create on EJB only once and by storing it
inside the webb server we can use it multiple time.
x Reduces execution time: As EJB component are readymade component
the user need not to create this component every time, which reduces
overall execution time.
x Distributed deployment: EJB’s can be sue in distributed architecture
where the EJB’s can get store in multiple system in distributed manner.
x Interoperability : EJB’s can be use by multiple types of request, because
the EJB has concept of CORBA (common object request brother
architecture) which converts different type of request into common
format.
23
Vidyalankar : T.Y. B.Sc. (IT) – Adv. Java
r
(1) Statefull session bean
ka
Those are the bean which iss use to stor
information between the client
ore
e the informatio
state in which they can store inform
store the conversational
ent & server for that they maintain a
information. Because of that state,
an
the processing of this bean are slower.
slowe
n bean
(2) Stateless session an
al
ngleton Session
(3) Singleton Sessi bean
be
Vi
ve bean
(ii) Message driven
Message driven bean can be use by generating the appropriate event or a
message by java messaging system.
Characteristics
(1) They are short live beans
(2) They are transaction oriented.
(3) They cannot be created by using a data from database, but they
have the ability to make changes in database.
(4) They are stateless.
(5) They are asynchronous.
(6) They does not use any home interface.
24
Prelim Paper Solution
Q.5(d) Write a program to create a login application using JSF with builtin [5]
validation.
(A) //index.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Login</title>
</h:head>
<h:body>
<h:form>
<h1>The Login Form</h1>
<h:outputLabel for="txtName">
r
<h:outputText value="Name" />
ka
</h:outputLabel>
<h:outputLabell for="txtPassword
for="txtPassword">
="txtPassw
<h:outputText
ext value="Password" />
xt value="Passwor
value="Pass
dy
utLabel>
</h:outputLabel>
<h:inputSecret
:inputSecret id="txtPassword"
id="t value ="#{user.password}">
Vi
<f:validateRegex
validateRegex
alidateR pattern="(.{6,20})" />
</h:inputSecret>
putSecre
</h:form>
</h:body>
</html>
//userbean.java
import javax.faces.bean.*;
@ManagedBean(name="user")
25
Vidyalankar : T.Y. B.Sc. (IT) – Adv. Java
{
String name;
String password;
r
public void setpassword(String p)
}
{
ka
password = p;
an
public String getpassword()
ord())
{
al
return password;
rd;
}
dy
public String
ring verifyUser()
{
Vi
if(name.equals("admin")
me.equals("adm
e.equals && password.equals("sssssss"))
{
ess
return "success";
}
else
{
return "failure";
}
}
}
26
Prelim Paper Solution
Event
Controller
View
Model
r
1.
ka
MVC architecture is normally use to create mult
application.
2. The basic intention of MVS S is to separate
sep
multiple views of the same
e.g. database
x View: It is the he component
componen wh which is responsible for creating multiple
dy
applicat
applic
views of the some application.
sp
e.g. jspp
ntroller: This com
x Controller: component is sue to control model as well as view.
Vi
e.g.. Servlet
4. Working
i) Wheneverr on event will occur for the use of MVC architecture, the
event or the request has been accepted by controller.
ii) Controller forward that request to model component, where model
component retrives the appropriate date use for handling the data
and send that data to controller.
Controller forwards that data to view which will create multiple views
from that data.
Sometimes the data accepted by view is not sufficient to create the
multiple views in that case view can directly interact with model for
getting that additional data.
27
Vidyalankar : T.Y. B.Sc. (IT) – Adv. Java
http
Invoke
request Filter
Interception return Action
dispatcher
Reads dispatchers
configurator
Struts
Result
Client Xml
r
i) Filter dispatcher will behave like controller
ontroller
ka
ii) Action will work as Model
iii) Result and Result type will work
ork as a view
owing
Struts framework contain following ng core component
compon
co
an
contro
co
i) Filter dispatcher: It behave like controller which is use to accept
ent.
request from the client.
Once it accept the request it w will search an appropriate action
al
spatcher.
Filterdispatcher.
Once itt identifies appr
apprompriate action, Filterdispatcher invoke the
tion by sendi
action th request.
sending the
Vi
tion:
on: Action
ii) Action: Ac will behave like model and hence it has the
priate dt
appropriate dta use to crete multiple views.
<hibernateconfiguration>
<sessionfactory>
<property name=”hibernate.dialect”>
org.hibernate.dialect.MySQLDialect</property>
28
Prelim Paper Solution
property name=”hibernate.connection.driver_class”>
com.mysql.jdbc.Driver</property>
<property name=”hibernate.connection.url”>
jdbc:mysql://localhost/DBname</property>
<property name=”hibernate.connection.username”>
root</property>
<property name=”hibernate.connection.password”>
root</property>
<mapping resource=”guestbook.hbm.xml”/>
</sessionfactory>
r
</hibernateconfiguration>
Elements: ka
hibernate.dialect It represents the
e name of the
th SQL dialect for the
an
database
r_class
ass
It rrepre
hibernate.connection.driver_class represents the JDBC driver class for
al
ion.url It represents
ion.url
hibernate.connection.url repr
represe the JDBC connection to the database
onnection.use
onnection.usernam
hibernate.connection.username It represents the user name which is used to
Vi
he
e database
connect to the datab
on
hibernate.connection.password It represents the password which is used to
connect to the database
29
Vidyalankar : T.Y. B.Sc. (IT) – Adv. Java
r
Fig. 1
ka
(1) The working of hibernate will state
te when persistent
cation.
n.
been created by the java application.
persist object i.e. POJO has
an
(2) Hibernate layer is divided into
nto following different
diff object which are use
eration.
tion.
to perform different operation.
(i) Configuration :
al
ernate. properties
(a) hibernate. propertie it is use to give some additional
propert
information
ormation about
ab the hibernate layer.
(b)) hibernate (f.g.
( xml It is use to establish a connection with a
Vi
rticul database.)
particular da
ration object is also use to create session factory.
(iii) Configuration
(iii) Session :
x It is generally use to receive a persistent object inside the
hibernate layer.
x Session object is responsible to create transaction object & perform
appropriate operation on persistent object.
30
Prelim Paper Solution
(iv) Transaction :
x It is the optional object which is use to represent unit of work.
x It represent the starting & ending of the transaction on database.
(v) Query :
(i) If we want to perform operations on database using SQL or hQl
queries, then in that case session object create query object.
(vi) Criteria :
If we want to perform operations on database using java methods then
in that case session create criteria object.
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
31
Vidyalankar : T.Y. B.Sc. (IT) – Adv. Java
add(l1);
add(t1);
add(l2);
add(t2);
add(b1);
add(b2);
add(b3);
add(b4);
add(t3);
}
r
int n2=Integer.parseInt(t2.getText());
int n;
ka
if(s.equals("Add"))
{
an
n=n1+n2;
}
else if(s.equals("Sub"))
al
{
n=n1-n2;
dy
}
else if(s.equals("Mul"))
als("Mul"))
s("Mul"))
{
Vi
n=n1*n2;
}
else
{
n=n1/n2;
}
Integer I=new Integer(n);
String p=I.toString();
t3.setText(p);
}
}
32
Prelim Paper Solution
Q.7(b) Write a program to meate a split pane in which left side of split [5]
Rane contains a list of plants and when user clicks on any planet
name, its image should get displayed an right side.
(A) import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
r
Container c=getContentPane();
ka
c.setLayout(new FlowLayout());
turn"};
n"};
String s[]={"earth","mercury","saturn"};
an
jl=new JList(s);
jl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
ectionModel.SING
onModel.S
al
i1=new ImageIcon("earth.jpg");
rth.jpg");
pg");
i2=new ImageIcon("mercury.png");
("mercury.png");
mercury.png")
dy
i3=new ImageIcon("saturn.jpg");
on("saturn.jpg")
on("saturn.jpg");
bel(i1);
j=new JLabel(i1);
Vi
jsp=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
tPane(JS
jsp.setLeftComponent(jl);
jsp.setRightComponent(j);
jl.addListSelectionListener(this);
c.add(jsp);
setSize(500,500);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
33
Vidyalankar : T.Y. B.Sc. (IT) – Adv. Java
r
}
{ ka
public static void main(String args[])
http reg.
web
Client
ent
nt CGI
Server
http
ht res
re
Vi
DB
Server
34
Prelim Paper Solution
x Once this can be done web server destroy the process to free its
memory.
(d) Three-tier architecture
http reg
web
Client
Server
http res
DB
Server
(i) In this there exist three entity i.e. client, webserver & Database
server.
(ii) Basically here server get distributed in web server se & database
server.
r
(iii) Web server is responsible to interact ract with client
clien as well as database
ka
server.
(iv) Although this architecture e minimize perf
performance delay it has
an
following disadvantage.
(v) Disadvantage
lure
(i) Single point failure e can occure if the webserver get failed.
ecture
(ii) This architecture re does not use to provide dynamic response.
al
(vi) Disadvantage e
rocess
x CGI process cess are platform
platfo
p dependent process because they are
dy
plemented in C, C+
implemented C++ pearl.
x It increase the ov overhead of webserver because every time a new
process get loaded
loa & unloaded from web server.
Vi
x It is very
ver difficult
di to implement CGI programming.
x Lack k of scalablity
s if the number of client will get increase.
x Lack of security.
x It uses lots of webserver resources.
x Only one resource can be use at a time i.e. lack of resource
sharing.
35
Vidyalankar : T.Y. B.Sc. (IT) – Adv. Java
{
JMenuBar jm;
JMenu jm1,jm2;
JMenuItem m1,m2,m3,m4,m5,m6;;
JTextArea jta;
JScrollPane jsp;
notepad2()
{
Container c=getContentPane();
c.setLayout(new BorderLayout());
jm=new JMenuBar();
jm1=new JMenu("File");
jm2=new JMenu("Edit");
r
m1=new JMenuItem("New");
ka
m2=new JMenuItem("Open");
m3=new JMenuItem("Save");
m4=new JMenuItem("Exit");
an
m5=new JMenuItem("Foreground");
nd");
m6=new JMenuItem("Background");
round");
d");
jm1.add(m1);
al
jm1.add(m2);
jm1.add(m3);
dy
jm1.add(m4);
jm2.add(m5);
m6);
jm2.add(m6);
Vi
jm.add(jm1);
jm.add(jm2);
jta=new JTextArea();
jsp=new JScrollPane(jta);
m1.addActionListener(this);
m2.addActionListener(this);
m3.addActionListener(this);
m4.addActionListener(this);
m5.addActionListener(this);
m6.addActionListener(this);
36
Prelim Paper Solution
c.add(jm,BorderLayout.NORTH);
c.add(jsp,BorderLayout.CENTER);
setSize(500,500);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
r
else if(s.equals("Open"))
{
ka
JFileChooser jf1=new JFileChooser();;
jf1.showOpenDialog(null);
an
}
else if(s.equals("Save"))
{
al
}
else if(s.equals("Exit"))
als("Exit"))
s("Exit"))
{
Vi
dispose();
}
Fo
else if(s.equals("Foreground"))
{
JColorChooser jc1=new JColorChooser();
Color c1=jc1.showDialog(null,"Select Foreground",null);
jta.setForeground(c1);
}
else
{
JColorChooser jc2=new JColorChooser();
Color c2=jc2.showDialog(null,"Select Foreground",null);
jta.setBackground(c2);
}
37
Vidyalankar : T.Y. B.Sc. (IT) – Adv. Java
}
public static void main(String args[])
{
notepad2 n=new notepad2();
}
}
r
It is use to perform those operation which can be o
opera
operated through out
e.g.: ka
the JSP page.
ve
(b) Include directivee tag :
dy
clude
lude file = “abc.jsp”
<%@ include “ab %>
ve tag :
(c) taglib directive
Inside the JSP application, if we want to use some other tag apart from
html & JSP then the tag server or the tag library can be be included
using taglib directive tag.
e.g.:
<%@taglib uri = “www.w3.org”%>
38
Prelim Paper Solution
r
ka
(d) Comment tag
It is use to write comment insidee jsp
ovide
statement which is use to provide
p page. A comment
e some additio
add
comm
c
additional
is non executable
information about the
an
some instruction.
e.g.
<% comment %>
al
f hibernate mapping
Q.7(f) Explain structure of m
map file. [5]
dy
ame=”guestboo
me=”gue
<class name=”guestbook” table=”guestbooktable”>
am
<property name=”name” type=”string”>
<column name=”username” length=”50” />
</property>
</class>
</hibernatemapping>
39
Vidyalankar : T.Y. B.Sc. (IT) – Adv. Java
Elements:
<hibernatemapping>….......</hibernatemapping>
It is the base tag which is used to write hibernate mapping file, which is
used to map POJO class with database table.
<class>….......</class>
It represents name of the class and database table which we want to map
with each other. It has 2 parameters:
name It represents name of the class
table It represents name of the database table
<property>….......</property>
It is used to write the property which we want to map with database column.
It has 2 parameters:
name It represents name of the property
r
type It represents type of the property
ka
<column>….......</column>
It is used to write the database column
mn which wwe wa
want to map with java class
an
property. It has 2 parameters:
name It represents name of the e column
length It represents maximum
aximum
um length of a column value
al
dy
Vi
40