0% found this document useful (0 votes)
20 views

Scheme - G Sample Question Paper Unit Test 1

,m

Uploaded by

Sanskar Rangole
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Scheme - G Sample Question Paper Unit Test 1

,m

Uploaded by

Sanskar Rangole
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 53

Scheme – G

Sample Question Paper Unit Test 1

Course Name: ‐ Computer Engineering Group


Course Code:‐ CO/CD/CM/CW/IF
Semester: ‐ Sixth
Subject Title: ‐ Advanced Java Programming
Marks: ‐ 25 Marks 17625

Q 1. Which of the following methods can be used to remove java.awt.Componenr object


from display?
1M
A. hide()
B. disappear()
C. remove()
D. delete()

Q2. What are controls or components?


1M
A. Controls or components allow users to interact with application
B. Controls or components do not allow users to interact with users
C. Controls or components allow users to interact with users
D. Controls or components allow application to interact with user

Q3. What are the subclasses of the Container class?


1M
A. Windows, Panel, ScrollPane
B. ScrollPane, Vector, String
C. Thread, Vector, String
D. Applet, InetAddress, Vector
Q4. Which object is needed to group Checkboxes to make them exclusive?
1M
A. CheckboxGroup
B. Checkbox
C. RadioButton
D. TextField

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()

Q8. Which components are needed to get above


shown output
2M
A. TextField, Label
B. List, Button
C. Choice, Button
D. Button, TextField

Q9. What components will be needed to get following output? ` 2M

A. Label, TabbedPane, CheckBox


B. TabbedPane, List, Applet
C. Panel, TabbedPane, List
D. Applet, TabbedPane, Panel

59
Q10. Select the missing statement in given code 2M

// Demonstrate the mouse event handlers.


import java.awt.*;
import java.applet.*;
/*
<applet code="mouse" width=300 height=100>
</applet>
*/

public class mouse extends Applet


implements MouseListener, MouseMotionListener
{
String msg = "";
intmouseX = 0, mouseY = 0; // coordinates of mouse
public void init() {
}
// Handle mouse clicked.
public void mouseClicked(MouseEvent me)
{

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

Q12. Select output for given code 2M

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);
}

public void itemStateChanged(ItemEventie)


{
if(ie.getSource()==m1)
setBackground(Color.red);
if(ie.getSource()==m2)
setBackground(Color.green);
}
}
/*<applet code=checkbackg.class height=150 width=150>

</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
{

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>*/

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)

Q15. Debug the following program 2M

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

Q16. What will be the output of the following program? 2M

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

Course Name: ‐ Computer Engineering Group


Course Code:‐ CO/CD/CM/CW/IF
Semester: ‐ Sixth
Subject Title: ‐ Advanced Java Programming
Marks: ‐ 25 Marks 17625
Q 1.Which of these methods of DatagramPacket is used to find the port number? 1M
A. port()
B. getPort()
C. findPort()
D. recievePort()

Q2.In the format of URL what is the last part? 1M


A. Protocol.
B. File path.
C. Port number.
D. Host name.

Q3. . ………………… is a full form of SQL. 1M


A. Standard query language
B. Sequential query language
C. Structured query language
D. Server side query language

Q4.Prepared Statement object in JDBC used to execute........... queries. 1M


A. Executable
B. Simple
C. High level
D. Parameterized

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

A. static InetAddressgetLocalHost( )throws UnknownHostException


B. static InetAddressgetByName(String hostName)throws UnknownHostException
C. static InetAddress[ ] getAllByName(String hostname throws UnknownHostException
D. string getHostAddress()

Q8. Select the proper constructor of URL class. 2M


A. URL(String protocolName, String hostName, intport, String path)
B. URL(String urlSpecifier)
C. URL(String protocolName, String hostName, String path)
D. All of above

Q9.Rearrange the steps to connect to the database in SQL. 2M


A. Create the connection object
B. Execute the query
C. Close the connection object
D. Register the driver class
E. Create the statement object
A. a-b-c-d-e
B. d-a-e-b-c
C. e-d-c-b-a
D. d-a-c-b-e

Q10.What is meaning of following statement.


Res.setContentType(“text/html”); 2M

A. Browser will interpret content as source code.


B. Browser will take contents as plain text
C. Browser will interpret content as HTML source code.
D. Browser will interpret content as Java source code.

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.");
}
}
}

A. The internet address of the server


B. The internet address of the client
C. The internet address of the host
D. The internet address of any other PC

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();
}
}

Q13.Consider the following program 2M

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();

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();
}
}

What should be the input in the position of ’*’


A. Command line argument
B. Array
C. Vector
D. Integer

Q14.Choose the correct syntax for getConnection() method. 2M


A. public static Connection getConnection(String url, String password) throws
SQLException
B. public static Connection getConnection(String name, String password) throws
SQLException

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

Q15. Observe the code and select the proper output. 2M


Contents Of ColorGet.html File :

<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>

Contents Of ColorGetServlet.java File :

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ColorGetServlet extends HttpServlet


{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException
{
String color = request.getParameter("color");
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<B>The selected color is: ");
pw.println(color);
pw.close();
}
}

Output of above program is


Opening : ColorGet.html File

74
After clicking on Submit button :

A. Output shown is correct


B. Output shown is not correct
C. Output shown has some errors
D. Output will be something other than above output

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

2. Which are various AWT controls from following?


A. Labels, Push buttons, Check boxes, Choice lists.
B. Text components, Threads, Strings, Servelts, Vectors
C. Labels, Strings, JSP, Netbeans, Sockets
D. Push buttons, Servelts, Notepad, JSP

3. JPanel and Applet use ___________________ as their default layout


A. FlowLayout
B. GridLayout
C. BorderLayout
D. GridBagLayout

4. Which of the following is true about AWT and Swing Component?


A. AWT Components create a process where as Swing Component create a thread
B. AWT Components create a thread where as Swing Component create a process
C. Both AWT and Swing Component create a process
D. Both AWT and Swing Component create a thread

5. Which of these methods cannot be called on JLabel object?


A. setIcon()
B. getText()
C. setLabel()
D. setBorderLayout()

6. _____________ pane can be used to add component to container


A. Glass
B. Cotent
C. Container
D. All of above

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)

8. Swing Components are_______________________


A. Platform dependent
B. Platform Independent
C. Both a & b
D. Platform oriented

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()

2. Which of these methods is used to get x coordinate of the mouse?


A. getX()
B. getXCoordinate()
C. getCoordinateX()
D. getPointX()

3. Which of these are constants defined in WindowEvent class?


A. WINDOW_ACTIVATED
B. WINDOW_CLOSED
C. WINDOW_DEICONIFIED
D. All of the mentioned

4. Which of these is super class of WindowEvent class?


A. WindowEvent
B. ComponentEvent
C. ItemEvent
D. InputEvent

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

2. The JDBC-ODBC bridge driver resolves……….. and makes equivalent ………..


A. JDBC call, ODBC call
B. ODBC call, ODBC call
C. ODBC call, JDBC call
D. JDBC call, JDBC call

3. For execution of DELETE SQL query in JDBC, ............. method must be used.
A. executeQuery()
B. executeDeleteQuery()
C. executeUpdate()
D. executeDelete()

4. Prepared Statement object in JDBC used to execute........... queries.


A. Executable
B. Simple
C. High level
D. Parameterized

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

2. A userr types the URL http:///www.msbtte.com/resullt.php. Whiich HTTP reequest gets


generateed? Select th
he one correect answer
A. GET
G method d
B. POST method d
C. HEAD
H methood
D. PUT method

3. Which of these iss a protocol for breakin


ng and send
ding packetss to an addrress across a
k?
network
A. TCIP/IP
T
B. DNS
D
C. Socket
D. Proxy Server

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

2. What is the purpo


ose of JTable?
A. JT
Table objectt displays rowws of data.
B. JT
Table objectt displays columns of datta.
C. JT
Table objectt displays rowws and colum mns of data..
D. JT
Table objectt displays daata in Tree fo
orm.

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

1. Select the miissing statem


ment in giveen code

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

2. Select the prroper outputt for followiing code


importjavva.awt.*;
importjavva.applet.*;
public claass list2 exteends Applet
{
public vooid init()
{
List l= neew List(2,truue);
l.add("javva");
l.add("c+++");
l.add("kkkk");
add(l);
}
}
/*<applett code=list2..class heightt=200 width=
=200>
</applet>>*/

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;

D) JPaneljp = new JPanel();


jp.setLayout(new GridLayout(3,3));
int b = 0;
for(int i = 0; i <3; i++)
{
for(int j = 0; j <3; j++)
{
jp.add(new JButton("Button " + b));
++b;

Chapter 3

1. Select the proper method to retrieve the host name of local machine

A. static InetAddressgetLocalHost( )throws UnknownHostException


B. static InetAddressgetByName(String hostName)throws UnknownHostException
C. static InetAddress[ ] getAllByName(String hostname throws
UnknownHostException
D. string getHostAddress()

2. Select the proper constructor of URL class

A. URL(String protocolName, String hostName, intport, String path)


B. URL(String urlSpecifier)
C. URL(String protocolName, String hostName, String path)
D. All of above

3. Select the proper constructor of serversocket


A. ServerSocket(intport, intmaxQueue)
B. Socket(InetAddressipAddress, intport)
C. Socket(int port)
D. ServerSocket()

4. What will be displayed in the output?


import java.net.*;
classmyAddress
{
public static void main (String args[])
{
try
{
InetAddress address = InetAddress.getLocalHost();
System.out.println(address);
}
catch (UnknownHostException e)

85
{
System.out.println("Could not find this computer's address.");
}
}
}

A. The internet address of the server


B. The internet address of the client
C. The internet address of the host
D. The internet address of any other PC

Chapter 4

1. executeQuery() method returns_____________________


A. Single row
B. ResultSet object
C. Single Column
D. Database Table

2. PreparedStatement interface extends____________________ interface


A. Connection
B. Statement
C. ResultSet
D. Driver

3. executeUpdate() method returns_____________________


A. Single row
B. ResultSet object
C. Integer
D. Single Column

Chapter 5

1. Identify correct syntax of service() method of servlet class


A. void service(ServletRequestreq, ServletResponse res)
B. void service(ServletResponse res ServletRequestreq, )
C. void service(ServletRequestreq, ServletRequestreq )
D. void service(ServletResponsereq, ServletResponse res)

2. Advantage of JSP over Servlet is____________


A. JSP is web page and servlets are Java programs
B. JSP is web page scripting language and servlets are Java programs
C. JSP is web page scripting language and servlets are simple programs
D. JSP is program and servlets are scripting language

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

1. Choose the correect sequencee for the folllowing outp


put

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

2. Consider the following program. Find which statement contains error.

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

3. Select the proper command to run the following code


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;

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

3. Observe the following code.


What will be the output of the program?

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

1. Selectt proper cod


de for given
n output

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"));

3. Select the missing statement in the program for following output

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);
}

public void __________________(ItemEvent ie)


{
if(ie.getSource()==m1)
setBackground(Color.red);
if(ie.getSource()==m2)
setBackground(Color.green);
}
}
/*<applet code=checkbackg.class height=150 width=150>
</applet>*/

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.");
}
}
}

A. The internet address of the server


B. The internet address of the client
C. The internet address of the host
D. The internet address of any other PC

2. Consider the following program


What correction should be done in the program to get correct output?
import java.net.*;
import java.io.*;

public class URLTest


{
public static void main(String args[]) throws MalformedURLException
{
URL url = new URL("http://www.msbte.com/download");
System.out.println("Protocol:"+ url1.getProtocol());
System.out.println("Port:"+ url1.getPort());
System.out.println("Host:"+ url1.getHost());
System.out.println("File:"+ url1.getFile());
}
}

A. Exception type is wrong.


B. Class should not be public.
C. Creation of object is not correct.
D. Use of created object not correct

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.

2. Consider the following program.


What should be the correction done in the program to get correct output?
import java.sql.*;
class Ddemo1
{
{
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.

3. Consider the following program.


What should be the correction done in the program to get correct output?

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()

4. Consider the following program.


What should be the correction done in the program to get correct output?
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. 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.

public class session1 extends HttpServlet


{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throwsServletException, IOException
{
HttpSession hs = request.getSession(true);
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.print("<B>");
Date date = (Date)hs.getAttribute("date");
if(date != null) {
pw.print("Last access: " + date + "<br>");
}
date = new Date();
hs.setAttribute("date", date);

100
pw.println("Current date: " + date);
}
}

A. import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*;


B. import java.Vector.* ; import java.Thread.*; import javax.servlet.*;
C. import javax.servlet.http.*; import java.String.*; import java.Vector;
D. import javax.servlet.http.*; import java.Thread.*; import javax.Client.*;

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();
}
}

A. new Cookie("MyCookie", data);


B. new Cookie("MyCookie", data1);
C. new Cookie("MyCookie", data2);
D. new Cookie("MyCookie", database);

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());
}
}

Output of the Program


Protocol :http
Host :www.sun.com
File :/index.html

A. Port :8080
B. Port :1024
C. Port: -1
D. None of the above

5. Consider the following program and identify the missing statement.

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:

15. Answer: A: Error in statement in which JTable is created


16. Answer: D: The output is obtained in Applet with two layouts: Border layout and Flow Layout.

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();
}
}

13. Answer: A: Command line argument


14. Answer: C: public static Connection getConnection(String url, String name, String
password) throws SQLException
15. Answer: A: Output shown is correct
16. Answer:B:The program gives a syntax error because of the statement
<%! String myName=request.getParameter();%>

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

1. Answer: A: JDBC calls, network protocol


2. Answer: A: JDBC call, ODBC call
3. Answer: C: executeUpdate()
4. Answer: D: Parameterized

Chapter 5
1. Answer: A: HttpServletRequest
2. Answer: A: GET method
3. Answer: A: TCIP/IP
4. Answer: B: Servlet

Understand Level

Chapter 1

1. Answer: A: Label, TextField, Button


2. Answer: C: JTable object displays rows and columns of data.
3. Answer: B: setIcon(ImageIcon i)
4. Answer: C: Panel, TabbedPane, List

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

1. Answer: A: void service((ServletRequestreq, ServlletResponse rres)


2. Answer: B: JSP is web paage scripting language an d servlets aree Java prograams
3. Answer: A: All above aree valid differe
ences

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>*/

2. Answer : A: Error in statement in which JTable is created


3. Answer: C: appletviewer combodemo11.java
4. Answer: D: The output is obtained in Applet with two layouts: Border layout and Flow
Layout.

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

1. Answer: A: import java.io.*; import java.util.*; import javax.servlet.*; import


javax.servlet.http.*;
2. Answer: A: new Cookie("MyCookie", data);
3. Answer: B: MalformedURLException
4. Answer: C: Port: -1
5. Answer: B: Missing package statement

110

You might also like