Scheme - G Sample Question Paper Unit Test 1
Scheme - G Sample Question Paper Unit Test 1
Q5. What is an event in delegation event model used by Java programming language? 1M
a) An event is an object that describes a state change in a source.
b) An event is an object that describes a state change in processing.
c) An event is an object that describes any change by the user and system.
58
d) An event is a class used for defining object, to create events.
Q6. Which of these methods are used to register a mouse motion listener? 1M
a) addMouse()
b) addMouseListener()
c) addMouseMotionListner()
d) eventMouseMotionListener()
Q.7 Which of these methods can be used to determine the type of event? 1M
a) getID()
b) getSource()
c) getEvent()
d) getEventObject()
59
Q10. Select the missing statement in given code 2M
mouseX = 0;
mouseY = 10;
msg = "Mouse clicked.";
repaint();
}
// Handle mouse entered.
public void mouseEntered(MouseEvent me)
{
mouseX = 0;
mouseY = 10;
msg = "Mouse entered.";
repaint();
}
// Handle mouse exited.
public void mouseExited(MouseEvent me)
{
mouseX = 0;
mouseY = 10;
msg = "Mouse exited.";
repaint();
}
// Handle button pressed.
60
public void mousePressed(MouseEvent me)
{
mouseX = me.getX();
mouseY = me.getY();
msg = "Down";
repaint();
}
// Handle button released.
public void mouseReleased(MouseEvent me)
{
mouseX = me.getX();
mouseY = me.getY();
msg = "Up";
repaint();
}
// Handle mouse dragged.
public void mouseDragged(MouseEvent me)
{
mouseX = me.getX();
mouseY = me.getY();
msg = "*";
showStatus("Dragging mouse at " + mouseX + ", " + mouseY);
repaint();
}
// Handle mouse moved.
public void mouseMoved(MouseEvent me)
{
showStatus("Moving mouse at " + me.getX() + ", " + me.getY());
}
// Display msg in applet window at current X,Y location.
public void paint(Graphics g)
{
g.drawString(msg, mouseX, mouseY);
}
}
a)addMouseListener(this);
b)addMouseListener(this);
addMouseMotionListener(this);
import java.awt.event.*;
c) addMouseListener();
d) all of above
61
Q11. Which of these events will be notified if scroll bar is manipulated? 2M
a) ActionEvent
b) ComponentEvent
c) AdjustmentEvent
d) WindowEvent
importjava.awt.event.*;
import java.awt.*;
importjava.applet.*;
public class checkbackg extends Applet implements ItemListener
{
Checkbox m1,m2,m3;
public void init()
{
m1=new Checkbox("A");
m2=new Checkbox("B");
m3=new Checkbox("C");
add(m1);
add(m2);
add(m3);
m1.addItemListener(this);
m2.addItemListener(this);
}
</applet>*/
a)
62
b)
c)
d)
63
Q13. Select proper code for given output 2M
a) import java.awt.*;
import java.applet.*;
public class choice11 extends Applet
{
public void init()
{
Choice os=new Choice();
os.add("wnn18");
os.add("wnnxp");
os.add("wnnnt");
os.add("win 2000");
add(os);
}
}
/*<applet code="choice11" height=200 width=300>
</applet>*/
b)
import java.awt.*;
import java.applet.*;
public class choice11 extends Applet
64
{
public void init()
{
Choice os=new Choice();
os.add("wnn18");
os.add("wnnxp");
add(os);
}
}
/*<applet code="choice11" height=200 width=300>
</applet>*/
c) import java.awt.*;
import java.applet.*;
public class choice11 extends Applet
{
public void init()
{
Choice os=new Choice();
os.add("wnn18");
os.add("wnnxp");
os.add("wnnnt");
os.add("win 2000");
add(os);
}
}
d)
import java.awt.*;
import java.applet.*;
public class choice11 extends Applet
{
65
Q14. select the proper output for following code 2M
import java.awt.*;
import java.applet.*;
public class list2 extends Applet
{
public void init()
{
List l= new List(2,true);
l.add("java");
l.add("c++");
l.add("kkk");
add(l);
}
}
/*<applet code=list2.class height=200 width=200>
</applet>*/
a)
b)
c)
66
d)
import java.awt.*;
import javax.swing.*;
/*
<applet code="JTableDemo" width=400 height=200>
</applet>
*/
public class JTableDemo extends JApplet
{
public void init() {
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
final String[] colHeads = { "emp_Name", "emp_id", "emp_salary" };
final Object[][] data = {
{ "Ramesh", "111", "50000" },
{ "Sagar", "222", "52000" },
{ "Virag", "333", "40000" },
{ "Amit", "444", "62000" },
{ "Anil", "555", "60000" },
67
};
JTable table = new JTable(data);
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp = new JScrollPane(table, v, h);
contentPane.add(jsp, BorderLayout.CENTER);
}
}
a. Error in statement in which JTable is created
b. Error in statement in which JScrollPane is created
c. Error in statement in which applet tag is declared
d. None of the above
import java.awt.*;
import java.applet.*;
public class LayoutDemo5 extends Applet
{
public void init()
{
int i,j,k,n=4;
setLayout(new BorderLayout());
Panel p1=new Panel();
Panel p2=new Panel();
p1.setLayout(new FlowLayout());
p1.add(new TextField(20));
p1.add(new TextField(20));
p2.setLayout(new GridLayout(5,3));
p2.add(new Button("OK"));
p2.add(new Button("Submit"));
add(p1,BorderLayout.EAST);
add(p2,BorderLayout.WEST);
}
}
/*<applet code=LayoutDemo5.class width=300 height=400>
</applet>*/
A. The output is obtained in Frame with two layouts: Frame layout and Flow Layout.
B. The output is obtained in Applet with two layouts: Frame layout and Flow Layout.
C. The output is obtained in Applet with two layouts: Frame layout and Border Layout.
D. The output is obtained in Applet with two layouts: Border layout and Flow Layout.
68
Scheme – G
Sample Question Paper Unit Test 2
Q5.What is servlet? 1M
A. Servlets are small program used for developing and executing web applications.
B. Servlets are small program used for database applications
C. Servlets are used for intranet programming
D. Servlets are programs written in C and C++
69
Q6.Which of these is a return type of getAddress() method of DatagramPacket class?
2M
A. DatagramPacket
B. DatagramSocket
C. InetAddress
D. ServerSocket
Q.7 Select the proper method to retrieve the host name of local machine. 2M
Q11. Consider the following program what will be displayed in the output? 2M
import java.net.*;
class myAddress
{
public static void main (String args[])
{
70
try
{
InetAddress address = InetAddress.getLocalHost();
System.out.println(address);
}
catch (UnknownHostException e)
{
System.out.println("Could not find this computer's address.");
}
}
}
Q12. Choose the correct option to establish a connection to database named student
and display its contents. 2M
A.
import java.sql.*;
class Ddemo1
{
public static void main(String args[]) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," ");
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("select *from StudTable");
System .out.println("Name" + " \t " + "Roll_No" + " \t " + "Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t \t"+rs.getDouble(3));
}
s.close();
c.close();
}
}
B.
import java.sql.*;
class Ddemo1
{
public static void main(String args[]) throws Exception
71
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," ");
ResultSet rs=s.executeQuery("select *from StudTable");
System .out.println("Name" + " \t " + "Roll_No" + " \t " + "Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t \t"+rs.getDouble(3));
}
s.close();
c.close();
}
}
C.
import java.sql.*;
class Ddemo1
{
public static void main(String args[]) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("select *from StudTable");
System .out.println("Name" + " \t " + "Roll_No" + " \t " + "Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t \t"+rs.getDouble(3));
}
s.close();
c.close();
}
}
D.
import java.sql.*;
class Ddemo1
{
public static void main(String args[]) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," ");
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("select *from StudTable");
72
System .out.println("Name" + " \t " + "Roll_No" + " \t " + "Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+" \t "+rs.getInt(1)+" \t \t"+rs.getDouble(1));
}
s.close();
c.close();
}
}
import java.sql.*;
public class db15
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c =DriverManager.getConnection("jdbc:odbc:MyDSN","","");
PreparedStatement s=c.prepareStatement( "update db3 set Name=? where Roll_no=?");
Statement s=c.createStatement( );
s.setString(1,*);
s.setString(2,*);
s.setString(3,*);
s.executeUpdate();
73
C. public static Connection getConnection(String url, String name, String password) throws
SQLException
D. public static Connection getConnection(String url, String name) throws SQLException
<html>
<body>
<center>
<form name="Form1"
action="http://localhost:8080/servlets-examples/ColorGetServlet">
<B>Color:</B>
<select name="color" size="1">
<option value="Red">Red</option>
<option value="Green">Green</option>
<option value="Blue">Blue</option>
</select>
<br><br>
<input type=submit value="Submit">
</form>
</body>
</html>
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
74
After clicking on Submit button :
16. A JSP page called test.jsp is passed a parameter name in the URL
using http://localhost/test.jsp?name="John". The test.jsp contains the
following code.
<%! String myName=request.getParameter();%>
<% String test= "welcome" + myName; %>
<%= test%>
A. The program prints "Welcome John"
B. The program gives a syntax error because of the statement
<%! String myName=request.getParameter();%>
C. The program gives a syntax error because of the statement
<% String test= "welcome" + myName; %>
D. The program gives a syntax error because of the statement
<%= test%>
75
MSBTE Sample Question Paper
Course Name: Computer Engineering Group
Course Code: CO/CM/CD/IF/CW Semester: SIXTH
Subject:- ADVANCED JAVA PROGRAMMING Subject Code :-(17085)
Marks:- 100 Hours :- 2 Hrs
Remember Level 1M
Chapter 1
1. Which class can be used to represent the Checkbox with a textual label that can appear
in a menu?
A. MenuBar
B. MenuItem
C. CheckboxMenuItem
D. Menu
76
7. Which of the following is not a constructor of JTree
A. JTree(Object obj[])
B. JTree(TreeNodetn)
C. JTree(Vector v)
D. JTree(int x)
Chapter 2
1. Which of these methods is used to obtain the object that generated a WindowEvent?
A. getMethod()
B. getWindow()
C. getWindowEvent()
D. getWindowObject()
Chapter 3
1. Which of these is a return type of getAddress method of DatagramPacket class?
A. DatagramPacket
B. DatagramSocket
C. InetAddress
D. ServerSocket
2. In the format for defining the URL what is the last part?
A. Protocol.
B. File path.
C. Port number.
77
D. Host name.
3. What is the first part of URL address?
A. Host name.
B. Port number.
C. File path.
D. Protocol.
4. Which of these methods of DatagramPacket is used to obtain the byte array of data
contained in a datagram?
A. getData()
B. getBytes()
C. getArray()
D. recieveBytes()
Chapter 4
1. Native – protocol pure Java converts ……….. in to the ………… used by DBMSs
directly.
A. JDBC calls, network protocol
B. ODBC class, network protocol
C. ODBC class, user call
D. JDBC calls, user call
3. For execution of DELETE SQL query in JDBC, ............. method must be used.
A. executeQuery()
B. executeDeleteQuery()
C. executeUpdate()
D. executeDelete()
Chapter 5
1. Name the class that includes the getSession() method that is used to get the HttpSession
object
A. HttpServletRequest
B. HttpServletResponse
C. SessionContext
78
D. SessionConfiig
4. in a web
w applicatiion, running
g in a webseerver, who iis responsib
ble for creatting requestt and
responsee object,
A. Web
W server
B. Servlet
C. Container
C
D. Client
C
Undersstand Leveel 2M
M
Chapterr 1
1. Which
W comp
ponents are used in the following ooutput?
A. Label,
L TextFiield, Button
79
B. Applet,
A Labell
C. Applet,
A Butto
on
D. G Layout, Label, Butto
Grid on
3. Which
h method is used to disp play icon on
n a componeent?
A. ro
ollOverIcon((ImageIcon i)i
B. seetIcon(ImageIcon i)
C. displayIcon(IImageIcon i))
D. reemoveIcon (ImageIconi
( )
4. Which componen
nts will be needed
n to geet following output?
A. Label,
L TabbedPane, ChecckBox
B. TabbedPane,
T List, Applett
C. Panel, Tabbed
dPane, List
D. Applet,
A TabbedPane, Pannel
Chapterr 2
importjavva.awt.*;
importjavva.applet.*;
/*
<applet code="mous
c e" width=30
00 height=10
00>
</applet>
>
*/
public claass mouse extends
e Applet implemennts MouseListener, MouuseMotionLiistener
{
String mssg = "";
intmouseeX = 0, mousseY = 0
public vo
oid init()
{
80
}
public void mouseClicked(MouseEvent me)
{
mouseX = 0;
mouseY = 10;
msg = "Mouse clicked.";
repaint();
}
public void mouseEntered(MouseEvent me)
{
mouseX = 0;
mouseY = 10;
msg = "Mouse entered.";
repaint();
}
public void mouseExited(MouseEvent me)
{
mouseX = 0;
mouseY = 10;
msg = "Mouse exited.";
repaint();
}
public void mousePressed(MouseEvent me)
{
mouseX = me.getX();
mouseY = me.getY();
msg = "Down";
repaint();
}
public void mouseReleased(MouseEvent me)
{
mouseX = me.getX();
mouseY = me.getY();
msg = "Up";
repaint();
}
public void mouseDragged(MouseEvent me)
{
mouseX = me.getX();
mouseY = me.getY();
msg = "*";
showStatus("Dragging mouse at " + mouseX + ", " + mouseY);
repaint();
}
public void mouseMoved(MouseEvent me)
{
showStatus("Moving mouse at " + me.getX() + ", " + me.getY());
}
public void paint(Graphics g)
81
{
g.drawSttring(msg, mouseX,
m mou
useY);
}
}
a) addMMouseMotion nListener(thhis);
b) addM MouseListeneer(this);
c) imporrt java.awt.eevent.*;
d) all of above
a))
b)
82
c))
d)
3. To
T get the fo
ollowing outtput complete the code given below
w.
83
im
mport java.aw wt.*;
im
mport javax.swing.*;
/*
*
<applet
< code= ="jscroll" wiidth=300 heiight=250>
</applet>
<
*//
puublic class jsscroll extend
ds JApplet
{
puublic void in
nit()
{
Container
C conntentPane = getContentP Pane();
co
ontentPane.ssetLayout(neew BorderLaayout());
}
}
in
nt v = ScrollP PaneConstan nts.VERTIC CAL_SCROL LLBAR_AL
LWAYS;
in
nt h = ScrollP PaneConstan nts.HORIZO ONTAL_SCR ROLLBAR__AS_NEED
DED;
JS
ScrollPanejssp = new JSccrollPane(jp,, v, h);
co
ontentPane.aadd(jsp, BorrderLayout.C CENTER);
}
}
A)
A Containerr contentPanne = getContentPane();
contentPaane.setLayou
ut(new GridL
Layout());
B)
B JPaneljp = new JPaneel();
jp.setLayo
out(new GridLayout(20,, 20));
C)
C int b = 0;
for(int i = 0; i < 20; i+
++) {
for(int j = 0; j < 20; j+
++) {
84
jp.add(new JButton("Button " + b));
++b;
Chapter 3
1. Select the proper method to retrieve the host name of local machine
85
{
System.out.println("Could not find this computer's address.");
}
}
}
Chapter 4
Chapter 5
86
3. Differencee between doGet()
d and doPost() mmethods is_____________________. S Select
any of given options
A.
A In doG
Get() the parrameters are appended too the URL annd sent alonng with headeer
inform
mation.
B.
B In doP
Post(),will seend the inforrmation throough a sockeet back to thee webserver and
itt won't show
w up in the URL bar.
C.
C doGett() is a requeest for inform
mation;
D.
D doPosst() provides information n (such as pl acing an ordder) that the server is
expected to remem mber
A.
A All ab
bove are vallid differencces
B.
B Only A and B
C.
C Only C and D
D.
D A, B, C are valid
d differencess.
Apply
A Level M
2M
Chapter
C 1
A.
A
im
mportjava.aw wt.*;
im
mportjava.ap pplet.*;
puublic class app1
a extendss Applet
{
puublic void in
nit()
{
87
TextFieldtf = new TextField();
TextArea t1=new TextArea(3,20);
Checkbox c=new Checkbox("a",true);
Checkbox c1=new Checkbox("b",false);
add(t1);
add(c);
add(tf);
add(c1);
}
}
/*<applet code=app1.class width=200 height=200>
</applet>*/
B.
importjava.awt.*;
importjava.applet.*;
public class app1 extends Applet
{
public void init()
{
TextFieldtf = new TextField();
TextArea t1=new TextArea(3,20);
Checkbox c=new Checkbox("a",true);
Checkbox c1=new Checkbox("b",false);
add(tf);
add(t1);
add(c);
add(c1);
}
}
/*<applet code=app1.class width=200 height=200>
</applet>*/
C.
importjava.awt.*;
importjava.applet.*;
public class app1 extends Applet
{
public void init()
{
TextFieldtf = new TextField();
TextArea t1=new TextField();
Checkbox c=new Checkbox("a",true);
Checkbox c1=new Checkbox("b",false);
88
add(tf);
add(t1);
add(c);
add(c1);
}
}
D. All of above
importjava.awt.*;
importjavax.swing.*;
/*
<applet code="JTableDemo" width=400 height=200>
</applet>
*/
public class JTableDemo extends JApplet
{
public void init() {
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
final String[] colHeads = { "emp_Name", "emp_id", "emp_salary" };
final Object[][] data = {
{ "Ramesh", "111", "50000" },
{ "Sagar", "222", "52000" },
{ "Virag", "333", "40000" },
{ "Amit", "444", "62000" },
{ "Anil", "555", "60000" },
};
JTable table = new JTable(data);
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPanejsp = new JScrollPane(table, v, h);
contentPane.add(jsp, BorderLayout.CENTER);
}
}
A. Error in statement in which JTable is created
B. Error in statement in which JScrollPane is created
C. Error in statement in which applet tag is declared
D. None of the above
89
/*
<applet code="combodemo11" width=300 height=100>
</applet>
*/
public class combodemo11 extends JApplet
{
public void init()
{
Container co = getContentPane();
co.setLayout(new FlowLayout());
JComboBoxjc=new JComboBox();
jc.addItem("cricket");
jc.addItem("football");
jc.addItem("hockey");
jc.addItem("tennis");
co.add(jc);
}
}
A. Javac combodemo11.java
B. java combodemo11
C. appletviewer combodemo11.java
D. All of above
importjava.awt.*;
importjava.applet.*;
public class LayoutDemo5 extends Applet
{
public void init()
{
inti,j,k,n=4;
setLayout(new BorderLayout());
Panel p1=new Panel();
Panel p2=new Panel();
p1.setLayout(new FlowLayout());
p1.add(new TextField(20));
p1.add(new TextField(20));
p2.setLayout(new GridLayout(5,3));
p2.add(new Button("OK"));
p2.add(new Button("Submit"));
90
dd(p1,BordeerLayout.EA
ad AST);
ad
dd(p2,BordeerLayout.WE
EST);
}
}
/*
*<applet cod
de=LayoutDemo5.class width=300
w hheight=400>
>
</applet>*/
<
E.
E The outpu
ut is obtained
d in Frame with
w two layoouts: Frame layout and F Flow Layouut.
F. The outpu
ut is obtained
d in Applet with
w two layyouts: Framee layout and Flow Layouut.
G.
G The outpu
ut is obtained
d in Applet with
w two layyouts: Framee layout and Border Layoout.
H.
H The outpu
ut is obtained
d in Applet with
w two layyouts: Bordeer layout andd Flow Layouut.
Chapter
C 2
A.
A
im
mportjava.aw wt.*;
im
mportjava.ap pplet.*;
puublic class choice11
c exteends Applet
{
puublic void in
nit()
{
Choice
C os=new Choice());
os.add("wnn1 18");
os.add("wnnx xp");
os.add("wnnn nt");
os.add("win 2000");
2
ad
dd(os);
}
}
*<applet cod
/* de="choice11" height=20 00 width=3000>
</applet>*/
<
91
B.
importjava.awt.*;
importjava.applet.*;
public class choice11 extends Applet
{
public void init()
{
Choice os=new Choice();
os.add("wnn18");
os.add("wnnxp");
add(os);
}
}
/*<applet code="choice11" height=200 width=300>
</applet>*/
C.
importjava.awt.*;
importjava.applet.*;
public class choice11 extends Applet
{
public void init()
{
Choice os=new Choice();
os.add("wnn18");
os.add("wnnxp");
os.add("wnnnt");
os.add("win 2000");
add(os);
}
}
D.
importjava.awt.*;
importjava.applet.*;
public class choice11 extends Applet
{
public void init()
{
Choice os=new Choice();
os.add("wnn18");
os.add("wnnxp");
os.add("wnnnt");
os.add("win 2000");
}
}
/*<applet code="choice11" height=200 width=300>
</applet>*/
92
2. Select the miissing statem
ment in the program too get the folllowing outp
put
im
mportjava.aw wt.*;
im
mportjava.aw wt.event.*;
im
mportjavax.sswing.*;
/*
*
<applet
< code= ="combodem mo" width=3 300 height=1100>
</applet>
<
*//
pu ublic class combodemo
c extends JAp pplet
im
mplementsItemListener
{
JLLabeljl;
ImmageIconfraance, german ny, italy, japaan;
pu ublic void in
nit()
{
Container
C conntentPane = getContentP Pane();
co ontentPane.ssetLayout(neew FlowLay yout());
JCComboBoxjc = new JCo omboBox();
jcc.addItem("F France");
jcc.addItem("G Germany");
jcc.addItem("Italy");
jcc.addItem("JJapan");
jcc.addItemLisstener(this);
co ontentPane.aadd(jc);
co ontentPane.aadd(jl);
}
pu ublic void ittemStateChaanged(ItemE Eventie)
{
String s = (Sttring)ie.getItem();
jll.setIcon(neww ImageIcon n(s + ".gif"));
93
}
}
A. jl = new JLabel(new ImageIcon("star.gif"));
B. jl = new JLabel("star.gif");
C. jl = new JLabel( ImageIcon("star.gif"));
D. JLabel(new ImageIcon("star.gif"));
import java.awt.*;
public class MenuDemo extends Frame
{
public static void main(String args[])
{
MenuDemo m = new MenuDemo();
m.setVisible(true);
MenuBar mbr = new MenuBar();
m.setMenuBar(mbr);
Menu filemenu = new Menu("File");
Menu editmenu = new Menu("Edit");
Menu viewmenu = new Menu("View");
mbr.add(filemenu);
mbr.add(editmenu);
MenuItem new1 = new MenuItem("New");
MenuItem open1 = new MenuItem("Open");
filemenu.add(new1);
filemenu.add(open1);
}
}
A. mbr.add(view);
B. mbr.add(menu);
94
C. mbr.add(vieweditmenu);
D. mbr.add(viewmenu);
4. Consider the following output. Find the missing statement in the program.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
/*
<applet code="SimpleKey1" width=300 height=100>
</applet>
*/
public class SimpleKey1 extends JApplet
implements KeyListener
{
String msg = "";
int X = 10, Y = 20; public void init()
{
addKeyListener(this);
requestFocus();
}
public void keyPressed(KeyEvent ke)
{
showStatus("Key Down");
}
public void keyReleased(KeyEvent ke)
{
showStatus("Key Up");
public void keyTyped(KeyEvent ke)
{
msg += ke.getKeyChar();
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg, X, Y);
}
95
}
A. Missing Semicolon
B. }
C. {
D. ()
5. For the following code select the method that can be used to handle event.
importjava.awt.event.*;
import java.awt.*;
importjava.applet.*;
public class checkbackg extends Applet implements ItemListener
{
Checkbox m1,m2,m3;
public void init()
{
m1=new Checkbox("A");
m2=new Checkbox("B");
m3=new Checkbox("C");
add(m1);
add(m2);
add(m3);
m1.addItemListener(this);
m2.addItemListener(this);
}
A. actionPerformed(ActionEvent ae)
B. itemStateChanged(ActionEvent ie)
C. itemStateChanged(ItemEvent ie)
D. adjustmentPerformed(AdjustmentEvent ae)
Chapter 3
1. Consider the following program
What will be displayed in the output?
import java.net.*;
96
class myAddress
{
public static void main (String args[])
{
try
{
InetAddress address = InetAddress.getLocalHost();
System.out.println(address);
}
catch (UnknownHostException e)
{
System.out.println("Could not find this computer's address.");
}
}
}
Chapter 4
1. Consider the following program.
What should be the correction done in the program to get correct output?
import java.sql.*;
class Ddemo1
97
{
public static void main(String args[]) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," ");
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("select *from StudTable");
System .out.println("Name" + " \t " + "Roll_No" + " \t " + "Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t \t"+rs.getDouble(3));
s.close();
c.close();
}
}
A. Missing semicolon
B. Missing {
C. Missing }
D. Missing statement.
A. Missing semicolon
B. Missing {
C. Missing }
D. Missing statement.
98
import java.sql.*;
class Ddemo1
{
public static void main(String args[]) throws Exception;
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," ");
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("select *from StudTable");
System .out.println("Name" + " \t " + "Roll_No" + " \t " + "Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t \t"+rs.getDouble(3));
}
s.close();
c.close();
}
}
A. Error in main()
B. Error in loop
C. Error in connection statement
D. Error in close()
A. Missing semicolon
B. Missing {
C. Missing }
D. Missing package statement.
99
5. Consider the following program
Select the statement that should be added to the program to get correct output.
import java.sql.*;
public class db15
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c =DriverManager.getConnection("jdbc:odbc:MyDSN","","");
PreparedStatement s=c.prepareStatement( "update db3 set Name=? where Roll_no=?");
Statement s=c.createStatement( );
s.setString(1,args[0]);
s.setString(2,args[1]);
s.setString(3,args[2]);
ResultSet rs=s.executeQuery("select* from db3");
System.out.println("Name"+"\t"+"Roll no"+"\t"+"Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+"\t"+rs.getInt(2)+"\t"+rs.getDouble(3));
}
s.close();
c.close();
}
}
A. s.executeUpdate()
B. c.createStatement( )
C. s.close()
D. c.close()
Chapter 5
1. Choose missing statements in following code from given options.
100
pw.println("Current date: " + date);
}
}
2. In following Java program fill statement showing ***.Select any one option fro
given options
import javax.servlet.*;
import javax.servlet.http.*;
public class AddCookieServlet extends HttpServlet
{
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throwsServletException, IOException
{
String data = request.getParameter("data");
Cookie cookie = ***************
response.addCookie(cookie);
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<B>MyCookie has been set to");
pw.println(data);
pw.close();
}
}
3. Consider the following program. Identify the exception that might be thrown
import java.net.*;
class URLDemo
{
public static void main(String args[]) throws ______________________
{
URL netAddress= new URL(“http://www.sun.com:8080//index.html”);
System.out.println(“Protocol :”+netAddress.getProtocol());
System.out.println(“Port :”+netAddress.getPort());
System.out.println(“Host :”+netAddress.getHost());
101
System.out.println(“File :”+netAddress.getFile());
}
}
A. IoException
B. MalformedURLException
C. Arithmetic Exception
D. UnknownHostException
4. Consider the following program. Identify the missing statement from the output.
import java.net.*;
class URLDemo
{
public static void main(String args[]) throws MalformedURLException
{
URL netAddress= new URL(“http://www.sun.com: //index.html”);
System.out.println(“Protocol :”+netAddress.getProtocol();
System.out.println(“Port :”+netAddress.getPort());
System.out.println(“Host :”+netAddress.getHost());
System.out.println(“File :”+netAddress.getFile());
}
}
A. Port :8080
B. Port :1024
C. Port: -1
D. None of the above
class URLDemo
{
public static void main(String args[]) throws MalformedURLException
{
URL netAddress= new URL("http://www.sun.com:/index.html");
System.out.println("Protocol :"+netAddress.getProtocol());
System.out.println("Port :"+netAddress.getPort());
System.out.println("Host :"+netAddress.getHost());
System.out.println("File :"+netAddress.getFile());
}
}
A. Missing semicolon
B. Missing package statement
102
C. Missing initialization
D. None of the above
103
6.2.3 Answer Key
Answer key for Unit test I
1. Answer : C: remove()
2. Answer: A: Controls or components allow users to interact with application
3. Answer: A: Windows, Panel, ScrollPane
4. Answer :A: CheckboxGroup
5. Answer: A : An event is an object that describes a state change in a source.
6. Answer: C: addMouseMotionListner()
7. Answer: A getID()
8. Answer: B: List, Button
9. Answer : C: Panel, TabbedPane, List
10. Answer: B: addMouseListener(this);
addMouseMotionListener(this);
import java.awt.event.*;
11. Answer:C:AdjustmentEvent
12. Answer: B
13. Answer: A:
import java.awt.*;
import java.applet.*;
public class choice11 extends Applet
{
public void init()
{
Choice os=new Choice();
os.add("wnn18");
os.add("wnnxp");
os.add("wnnnt");
os.add("win 2000");
add(os);
}
}
104
/*<applet code="choice11" height=200 width=300>
</applet>*/
14. Answer: C:
105
Answer key for Unit test II
1. Answer : B: getPort()
2. Answer: B: File path
3. Answer: C: Structured Query Language
4. Answer :D: Parametrized
5. Answer: A : Servlets are small program used for developing and executing web
applications.
6. Answer: C: InetAddress
7. Answer: A static InetAddressgetLocalHost( )throws UnknownHostException
8. Answer: D: All of above
9. Answer : B: d-a-e-b-c
10. Answer: C: Browser will interpret content as HTML source code.
11. Answer: C: The internet address of the host
12. Answer: A
import java.sql.*;
class Ddemo1
{
public static void main(String args[]) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," ");
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("select *from StudTable");
System .out.println("Name" + " \t " + "Roll_No" + " \t " + "Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t \t"+rs.getDouble(3));
}
s.close();
c.close();
}
}
106
Answer Key for AJP 100 marks Paper
Remember Level
Chapter 1
1. Answer: C: CheckboxMenuItem
2. Answer: A: Labels, Push buttons, Check boxes, Choice lists.
3. Answer: A: FlowLayout
4. Answer: A: AWT Components create a process where as Swing Component create a thread
5. Answer: D: setBorderLayout()
6. Answer: B: Cotent
7. Answer: D: JTree(int x)
8. Answer: B: Platform Independent
Chapter 2
1. Answer: B: getWindow()
2. Answer: B: getXCoordinate()
3. Answer: D: All of the mentioned
4. Answer: B: ComponentEvent
Chapter 3
1. Answer: C: InetAddress
2. Answer: B: File path.
3. Answer: D: Protocol.
4. Answer: A: getData()
Chapter 4
Chapter 5
1. Answer: A: HttpServletRequest
2. Answer: A: GET method
3. Answer: A: TCIP/IP
4. Answer: B: Servlet
Understand Level
Chapter 1
Chapter 2
1. Answer: D: All of the above.
107
2. Answer:
A C:
3. Answer:
A D:
JP
Paneljp = new
n JPanel(();
jp.setLay yout(new GridLayout(3
G 3,3));
int b = 0;
0
for(int i = 0; i <3; i++)
{
for(int j = 0; j <3; j++)
j
{
jp.add(new JButton n("Button " + b));
++b;
Chapter
C 3
1. Answer: A: static InetAd
ddressgetLocaalHost( )thro
ows Unknown
nHostException.
2. Answer: D: All of above
3. Answer: A: ServerSocke et(int port, intt maxQueue))
4. Answer: C: The internett address of the host
hapter 4
Ch
1. Answer: B: ResultSet ob
bject
2. Answer: B: Statement
3. Answer: C: Integer
Ch
hapter 5
App
ply Level
apter 1
Cha
108
1. Answer : B
importjava.awt.*;
importjava.applet.*;
public class app1 extends Applet
{
public void init()
{
TextFieldtf = new TextField();
TextArea t1=new TextArea(3,20);
Checkbox c=new Checkbox("a",true);
Checkbox c1=new Checkbox("b",false);
add(tf);
add(t1);
add(c);
add(c1);
}
}
/*<applet code=app1.class width=200 height=200>
</applet>*/
Chapter 2
1. Answer: A
importjava.awt.*;
importjava.applet.*;
public class choice11 extends Applet
{
public void init()
{
Choice os=new Choice();
os.add("wnn18");
os.add("wnnxp");
os.add("wnnnt");
os.add("win 2000");
add(os);
}
}
/*<applet code="choice11" height=200 width=300>
</applet>*/
109
2. Answer: A: jl = new JLabel(new ImageIcon("star.gif"));
3. Answer: D: mbr.add(viewmenu);
4. Answer C: {
5. Answer: C: itemStateChanged(ItemEvent ie)
Chapter 3
1. Answer: C: The internet address of the host
2. Answer: D: Use of created object not correct
Chapter 4
1. Answer: C: Missing }
2. Answer: D: Missing statement.
3. Answer: A: Error in main()
4. Answer: D: Missing package statement.
5. Answer: A: s.executeUpdate()
Chapter 5
110