Professional Documents
Culture Documents
Advanced Java
Time : 2 Hrs.]
[10]
[5]
[2 mark]
Vi
dy
al
an
ka
r
Q.1
Attempt the following (any TWO)
Q.1(a) Explain Checkbox with example.
(A)
Checkbox
1) Checkbox is a class which is used to create Checkbox in awt.
2) Its constructors are :
Checkbox( );
Checkbox (string s);
Checkbox (string s, Boolean state);
up (b
((b));
Checkbox (string s, Boolean state, Checkbox Group
[Marks : 75
iii) getState( );
It is used to retrieve state of the Checkbox.
iv) setState(Boolean State);
It is used to set a new state to a Checkbox.
1014/BSc/IT/TY/Pre_Pap/2014/Adv. Java
Java
Linux
ST
NS
ASP
Current Selection :
Java : True
Linux : False
ASP : False
ST : False
NS : False
Vi
dy
al
an
ka
r
import java.applet.*;
import java.awt.event.*;
import.java.awt.*;
/* <applet code = test width = 200 height = 30>>
< /applet>/
public class test extends Applet implements
nts
ts
ItemListener
{
Checkbox c1, c2, c3, c4, c5,
public void init( )
{
setLayout (new
new FlowLayout(
FlowLayou ));
))
c1 = new Checkbox (Ja
(Java);
(Java
c2 = new Checkbox (Lin
(Linux);
c3 = new Checkbox ((ASP);
c4 = new Checkbo
Chec
Checkbox
(ST);
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);
}
public void paint (Graphics g)
{
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( );
g.drawString
g.drawString
g.drawString
g.drawString
g.drawString
g.drawString
Vi
dy
al
an
ka
r
}
public void itemStateChanged (Itemevent
event
nt ie);
{
repaint( );
}
del.
Q.1(b) Explain delegation event model.
[5]
el
(A)
Delegation event model
del consist of follo
f
Delegation event model
following three concepts which are used for
handling the eventt :
[4 mark]
1) Event
ion : Event is also
a
Definition
object.
ent is de3fined
de3fin
i) Event
as the object which describe the state change of
ticul source.
s
the particular
an be
b occur on multiple conditions like clicking on a button.
ii) Event can
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) 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.
Vi
dy
al
an
ka
r
Event Handling
[1 mark]
Even the operations which are occurred when the components will get clicked
or selected to handle each type of event java develops different event
classes.
Each event class has its specific condition and when that condition will occur
the appropriate event will get generated. When the
event will get generated
e ev
eive that
th
the event object will get throw and to receive
object different
receiving method can be used.
vent only when it iis registered for
A component can generated a particular event
that particular event.
ss.
Q.1(c) Write a short note on Inner class.
(A)
Inner Class
Example :
import java.awt.*;
import java.awt.event.*;
*;
[5]
[4 mark]
add (b1);
add (b2);
add (b3);
setSize (200, 300);
setTitle (SSS);
setVisible (true);
}
public void actionPerformed (ActionEvent ae);
{
String s = ae.getActionCommand( );
Vi
dy
al
an
ka
r
if (s.equals (Red))
{
setBackground (c1);
}
Green))
en ))
else if (s.equals (Green))
{
ground
round (c2);
setBackground
else
{
setBackgro
setBackground (c3);
}
}
emo e
class demo
extends WindowAdapter
{
public void WindowCloasing (WindowEvent we);
{
System.exit (0);
}
}
public static void main (string a[ ])
{
testevent t = new testevent( );
}
}
5
Inner Class
[1 mark]
1) Inner class is used when we want our main class to get derived from
Frame class.
2) In that case we create a new class called as inner class, place it inside
the main class and derived it from the appropriate adapter class, so that
we can override a specific method from that adapter class.
Q.1(d) Explain Adapter Class with example.
(A)
Adapter Class
Example :
import java.awt.*;
import java.awt.event.*;
[5]
[3 mark]
Vi
dy
al
an
ka
r
b1.addActionListener (this);
b1.addActionL
b1.addA
b2.addActionListener
(this);
2.addAct
dA
b3.addActionListener
(this);
f.addWindowListener (this);
f.add(l);
f.add(b1);
f.add(b2);
f.add(b3);
f.setSize (200, 300);
f.setTitle (SSS);
f.setVisible (true);
}
6
Vi
dy
al
an
ka
r
if (s.equals (Red))
{
f.setBackground (c1);
}
else if (s equals (Green))
{
f.setBackground (c2);
}
else
{
c3);
f.setBackground (c3);
}
}
Adapter Class
[2 mark]
1) Adapter class is used to overcome the problem of writing different
methods of empty implementation.
2) Normally if we use event listener, then we need to override all its
methods.
3) If we want to override only certain specific method, then in that case
EventListener can be replaced with EventAdapter Class.
EventClass
ActionEvent
ItemEvent
MouseEvent
KeyEvent
ComponentEvent
ContainerEvent
AdjustmentEvent
TextEvent
WindowEvent
MouseWheelEvent
EventListener
ActionListener
ItemListener
MouseListener
KeyListener
ComponentListener
ContainerListener
AdjustmentListener
TextListener
WindowListener
MouseWheelListener
EventAdapter Class
ActionAdapter
ItemAdapter
MouseAdapter
KeyAdapter
ComponentAdapter
ContainerAdapter
AdjustmentAdapter
TextAdapter
WindowAdapter
MouseWheelAdapter
[10]
[5]
Vi
dy
al
an
ka
r
Q.2
Attempt the following (any TWO)
ng Component.
Compo
Com
Q.2(a) Differentiate between AWT component and Swing
(A)
AWT Components
1) AWT components are non java
a
components
2) They
are
platform
dependent
endent
components
3) They are non decorative components
mponents
4) They are normally
ally
ly rectangular in
i
shape
5) Those are
e considered as heavy
omponents
weight components
6) They are
re not used to perform
erations
tion
complex operations
7) Those classes are present in java.awt
package
Swing Com
Components
Swing components
compone
comp
are pure java
componen
components
They are
ar
platform independent
com
compon
components
The
They
T
are decorative. We can even
place an image on a component
We can create different shape
components
Those are considered as light weight
components
They are used to perform complex
operations
Those classes are present in
javax.swing package
Message
OK
Cancel
Vi
dy
al
an
ka
r
Yes
e);
(c) ShowInputDialog(String message);
Message
sage
OK
K
Cancel
It is used to display a po
pop-up which is used to accept an input from
pop-u
the userss
c
Q.2(c) Write a program to create
a combobox, and add different items in
that combobox
accepting them from user.
obox
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;
[5]
combo()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
9
jc=new JComboBox();
jb=new JButton("Add");
jt=new JTextField(10);
jb.addActionListener(this);
c.add(jc);
c.add(jt);
c.add(jb);
Vi
dy
al
an
ka
r
setSize(500,500);
setVisible(true);
LOSE);
E);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
e)
public void actionPerformed(ActionEvent ae)
{
String s=jt.getText();
jc.addItem(s);
}
public static void main(String
ng args[])
gs[])
{
combo cb=new combo();
);
}
}
[5]
{
Container c=getContentPane();
c.setLayout(new BorderLayout());
jb1=new JButton("Add Row");
jb2=new JButton("Remove Row");
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);
Vi
dy
al
an
ka
r
jb1.addActionListener(this);
jb2.addActionListener(this);
c.add(jsp,BorderLayout.CENTER);
c.add(jb1,BorderLayout.NORTH);
c.add(jb2,BorderLayout.SOUTH);
H);
setSize(1000,500);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ation(JFrame.EXIT
JFrame.E
}
public void actionPerformed(ActionEvent
ae)
onPerformed(Actio
nPerformed(Ac
{
ae.getActionC
ae.getActionComma
String s=ae.getActionCommand();
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
int n=Integer.parseInt(f);
dt.removeRow(n);
}
}
public static void main(String args[])
{
table t=new table();
}
}
Q.3
Attempt the following (any TWO)
Q.3(a) Explain RequestDispatcher with example.
(A)
RequestDispatcher
[10]
[5]
[ 2 mark]
Vi
dy
al
an
ka
r
username :
password :
Login
<html>
<head>
n </title>
title> </head>
</he
<title> Servlet Application
<body>
<form method = "post"
ost"
t" action = "test">
"t
"test
<b> Username </b>
b
b>
<input type = "text"
text" name = "u" value = " " size = "10">
e = "password"
"password nam
<input type
name = "p" value = " " size = "10">
<input type = "submit"
value = "login">
"subm va
</form>
</body>
</html>
//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
}
}
Vi
dy
al
an
ka
r
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
("Errors");
forward(request,
ward(reques rresponse);
rd2.forward(request,
}
out.close( );
Request Dispatchers
[2 mark]
1) Any Servlet application
created as a request dispatcher by using
pplication
ication can b
be c
ethod
following method
equestDispatcher(
questDispatcher( );
getRequestDispatcher(
stDispatchers is a class which is there inside the package
stDispatcher
2) RequestDispatchers
ervlet
javax.servlet
spatche can be created for following 2 reasons.
3) RequestDispatcher
de the contains of RequestDispatcher into the current
(a) To include
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.
Q.3(b) Explain session management with its techniques.
[5]
(A)
Session management techniques
1) Session Management is used by Servlet to store information about a
particular client.
13
Vi
dy
al
an
ka
r
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 :
sion ID to the Servlet.
x It is used by the client to send a Session
et can
an read it & Hence called as
x It is in Hidden form & only Servlet
Hidden form field.
(b) Url rewriting :
nID to the client.
clie
x It is used to send SessionID
sionID inside
insi
rresponse packet or it will
x Servlet can put the SessionID
oken to send a Se
generate a special token
SessionID
(c) Cookies :
okie, a Servl
Servlet an
a send SessionID to the client
x By using cookie,
machine.
Serv
x For thatt purpose Servlet
will create a new cookie for Session ID &
dss it to the client
w
sends
client, with
the help of response packet Header.
For example,
e,
rogram to create
cr
Write a program
a client side application which is used to accept
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
client side application
<html>
<head>
<title> Servlet Application </title> </head>
<body>
14
Vi
dy
al
an
ka
r
15
[5]
Vi
dy
al
an
ka
r
{
out.println("Correct Answer");
}
}
finally
{
out.close();
}
}
}
Vi
dy
al
an
ka
r
Vi
dy
al
an
ka
r
18
Q.4
Attempt the following (any TWO)
[10]
Q.4(a) Write a program using Prepared Statement to add record in student [5]
table containing roll number and name.
(A)
import java.sql.*;
public class Main
{
Vi
dy
al
an
ka
r
19
Description
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
Vi
dy
al
an
ka
r
Example
<% String message = Escaping \ single
e quote;
uote; %>
ouble quote; %
%>
<% String message = Escaping \ double
<% String message = Escaping \ \ backslash; %>
%
<% String message = Escaping
end tag; %>
ng % \ > scripting
script
e
aping
ng < \ % scriptin
scr
<% String message = Escaping
scripting start tag; %>
<% String message = Escaping
sign
; %>
Escaping
scaping \$ dollar
dol
s
caping
ing quote cha
As an alternative to escaping
characters, the character entities
' and " can also be used.
ion in JDBC.
Q.4(c) Explain transaction
[5]
(A)
c.setAutoCommit
(false);
mit (false
s.execut("insert
value }} )
nsert into employ
emp
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
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.
Vi
dy
al
an
ka
r
Client
Request
ues
If not
initi
initialized
Translation
Already
Initializ
Response
Compilation
Initialization
Loading
Instantiation
Request Processing
Destruction
(d) Instantiation:
x In this step, instance of the servlet class is created, so that it
can handle request.
21
(e) Initialization :
x It can be done using jspInit( ). This is one time actively and after
initialization, the servlet is ready to process requests.
2) Request Processing : Entire initialization process is done to make the
servlet available in order to process the incoming request.
jspService( ) is the method that actually process the request.
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.
[10]
[5]
Vi
dy
al
an
ka
r
Q.5
Attempt the following (any TWO)
Q.5(a) Explain JSF life cycle.
(A)
JSF life cycle
Response
e
plete
complete
Faces
response
Restore
view
Apply
request
values
Process
cess
event
Process
Validation
Response
complete
Process
event
e
Reader response
Response
Resp
Res
ponse co
complete
com
plete
Faces
response
Render
response
e
Process
rocess
Event
Invotie
application
Conversion
C
onvers
error/render
Response complete
Process
Event
Update
model
values
22
4.
5.
6.
Vi
dy
al
an
ka
r
3.
ii) If any error occur then the error message will get store inside
Facescontext object.
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.
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.
Invest application
i) In this face the application will get invest
st or
o execute to create
responses.
tsing of thos
tthose page will also
ii) Also if they are multiple pages then lintsing
get done in this phase.
Render response
ponses
ses will get re
In this phase the generated responses
render i.e. provided to a
client as a response.
23
Vi
dy
al
an
ka
r
Q.5(d) Write a program to create a login application using JSF with builtin
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>
[5]
Vi
dy
al
an
ka
r
<h:outputLabel for="txtName">
<h:outputText value="Name" />
</h:outputLabel>
<h:inputSecret
value ="#{user.password}">
:inputSecret id="txtPassword"
id="t
<f:validateRegex
pattern="(.{6,20})" />
validateRegex
alidateR
</h:inputSecret>
putSecre
<h:commandButton value="Login" action="#{user.verifyUser}"/>
</h:form>
</h:body>
</html>
//userbean.java
import javax.faces.bean.*;
@ManagedBean(name="user")
public class userbean
25
{
String name;
String password;
Vi
dy
al
an
ka
r
}
public void setpassword(String p)
{
password = p;
}
public String getpassword()
ord())
{
return password;
rd;
public String
ring verifyUser()
{
if(name.equals("admin")
&& password.equals("sssssss"))
me.equals("adm
e.equals
{
ess
return "success";
}
else
{
return "failure";
}
}
}
26
Q.6
Attempt the following (any TWO)
Q.6(a) Explain MVC architecture.
(A)
MVC architecture
[10]
[5]
Event
Controller
View
Vi
dy
al
an
ka
r
Model
1.
27
Interception
Filter
dispatcher
Reads
configurator
Client
Invoke
return
Action
dispatchers
Result
Vi
dy
al
an
ka
r
1.
Struts
Xml
[5]
[5]
<hibernateconfiguration>
<sessionfactory>
<property name=hibernate.dialect>
org.hibernate.dialect.MySQLDialect</property>
28
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/>
Vi
dy
al
an
ka
r
</sessionfactory>
</hibernateconfiguration>
Elements:
e name of the
th SQL dialect for the
hibernate.dialect It represents the
database
r_class
ass
It rrepre
hibernate.connection.driver_class
represents the JDBC driver class for
the specific database
ion.url It represents
ion.url
repr
represe
hibernate.connection.url
the JDBC connection to the database
onnection.use
onnection.usernam
hibernate.connection.username
It represents the user name which is used to
he
e database
datab
connect to the
on
hibernate.connection.password
It represents the password which is used to
connect to the database
guestbook.hbm.xml It represents the name of mapping file
29
[5]
Vi
dy
al
an
ka
r
Fig. 1
(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.
Q.7
Attempt the following (any THREE)
[15]
Q.7(a) Write a program to implement single arithmetic calculator
using awt [5]
calc
c
components.
(A)
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
t=300>
00>
/*<applet code=e5 width=200 height=300>
</applet>*/
Actio
A
public class e5 extends Applett implements ActionListener
{
Label l1,l2;
Button b1,b2,b3,b4;
TextField t1,t2,t3;;
public void init())
{
(new FlowLay
FlowLayout(
setLayout(new
FlowLayout());
el("Number
"Numb 1");
1"
l1=new Label("Number
Numbe 2");
l2=new Label("Number
Ad
b1=new Button("Add");
b2=new Button("Sub");
b3=new Button("Mul");
b4=new Button("Div");
t1=new TextField(10);
t2=new TextField(10);
t3=new TextField(10);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
31
add(l1);
add(t1);
add(l2);
add(t2);
add(b1);
add(b2);
add(b3);
add(b4);
add(t3);
}
Vi
dy
al
an
ka
r
32
Q.7(b) Write a program to meate a split pane in which left side of split
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.*;
[5]
Vi
dy
al
an
ka
r
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
Vi
dy
al
an
ka
r
g. Also wirte
w
Q.7(c) Explain CGI and its woring.
disadvantages of CGI.
(A)
http reg.
Client
ent
nt
http
ht res
re
web
Server
[5]
CGI
DB
Server
Once this can be done web server destroy the process to free its
memory.
http res
web
Server
DB
Server
Vi
dy
al
an
ka
r
(i) In this there exist three entity i.e. client, webserver & Database
server.
se
(ii) Basically here server get distributed in web server
& database
server.
ract with client
clien as well as database
(iii) Web server is responsible to interact
server.
e minimize perf
(iv) Although this architecture
performance delay it has
following disadvantage.
(v) Disadvantage
lure
e can occure if the webserver get failed.
(i) Single point failure
ecture
re does not use to provide dynamic response.
(ii) This architecture
e
(vi) Disadvantage
rocess
cess are platform
platfo
p
x CGI process
dependent process because they are
plemented in C, C+
C++ pearl.
implemented
x It increase the ov
overhead of webserver because every time a new
process get loaded
loa
& unloaded from web server.
ver difficult
di
x It is very
to implement CGI programming.
k of scalablity
s
x Lack
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.
Q.7(d) Write a program to demonstrate use of JMenuBar, JMenu and
JMenuItem class in swing.
(A)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
[5]
{
JMenuBar jm;
JMenu jm1,jm2;
JMenuItem m1,m2,m3,m4,m5,m6;;
JTextArea jta;
JScrollPane jsp;
notepad2()
{
Container c=getContentPane();
c.setLayout(new BorderLayout());
Vi
dy
al
an
ka
r
jm=new JMenuBar();
jm1=new JMenu("File");
jm2=new JMenu("Edit");
m1=new JMenuItem("New");
m2=new JMenuItem("Open");
m3=new JMenuItem("Save");
m4=new JMenuItem("Exit");
m5=new JMenuItem("Foreground");
nd");
m6=new JMenuItem("Background");
round");
d");
jm1.add(m1);
jm1.add(m2);
jm1.add(m3);
jm1.add(m4);
jm2.add(m5);
m6);
jm2.add(m6);
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
c.add(jm,BorderLayout.NORTH);
c.add(jsp,BorderLayout.CENTER);
setSize(500,500);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
Vi
dy
al
an
ka
r
37
}
public static void main(String args[])
{
notepad2 n=new notepad2();
}
}
Q.7(e) Explain different types of JSP tags.
(A)
JSP tags / JSP elements
JSP tags are normally use to embed java code inside the JSP page.
Following are various type of JSP tags
(A) Directive tag
It has three types
[5]
Vi
dy
al
an
ka
r
38
Vi
dy
al
an
ka
r
(A)
[5]
<?xml version=1.0
1.0 encoding=U
encoding=UT
encoding=UTF8?>
<hibernatemapping>
mapping>
apping>
ame=guestboo
me=gue
<class name=guestbook
table=guestbooktable>
am
<property name=name
type=string>
<column name=username length=50 />
</property>
39
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
Vi
dy
al
an
ka
r
<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
type It represents type of the property
<column>.......</column>
mn which w
we wa
It is used to write the database column
want to map with java class
property. It has 2 parameters:
e column
name It represents name of the
aximum
um length of a column value
length It represents maximum
40