Ajp CT2 QB
Ajp CT2 QB
Q. QUESTION
1. An event is generated when internal state of event source is________
A. Not change
B. changed
C. Either change or not
D. None of these
Answer: B
4. Select proper sequence of following classes used for writing menudriven program:
1. Menu 2. MenuBar 3. MenuItem
A. 2,1,3
B. 1,2,3
C. 3,2,1
D. None Of The Above
Answer: A
6. To handle all the events related to ScrollBar, the following method of AdjustmentListener needs
to be overriden.
A. public void adjustmentValueChanged(AdjustmentEvent obj)
B. public void adjustmentChanged(AdjustmentEvent obj)
C. public void actionPerformedActionEvent obj)
D. None of the above
Answer: A
11. Which of the following are valid return types, for listener methods?
A. Boolean.
B. Void.
C. the type of event handled.
D.Component.
Answer: B
13. Which of the following statements about anonymous inner classes is false?
A. They are declared without name
B. They typically appears in method declartion
C. They are declared with annonymous keyword
D. They can access their top level members
Answer: C
15. Which of these methods are used to register a mouse motion listener?
A. addMouseMotion()
B. addMouseListener()
C. addMouseMotionListener()
D. addMotionListener()
Answer: C
17. You have created a simple Frame and overridden the paint method as follows
public void paint(Graphics g)
{ g.drawString("Dolly",50,10);
}
What will be the result when you attempt to compile and run the program?
A. The string "Dolly" will be displayed at the centre of the frame
B. The string "Dolly" will be shown at the Right of the form.
C. The word "Dolly" will be seen at the top-left of the form.
D. The string "Dolly" will be shown at the bottom of the form.
Answer: C
23. ______________method returns a reference to the component that was added to or removed
from the container.
A. getContainer()
B. getChild()
C. getValue()
D. None of these
Answer: B
24. _____________method returns a Point object that contains both X and Y coordinates.
A. getLocationOnScreen()
B. getXOnScreen()
C. getYOnScreen()
D. None of the above
Answer: A
25. ___________method returns a value that indicates which modifier keys were pressed when the
event was generated.
A. getModifiers()
B. setModifiers()
C. getActionCommand()
D. none of the above
Answer: A
27. Clicking the closing button on the upper-right corner of a frame generates a(n) __________ event.
A. ItemEvent
B. WindowEvent
C. MouseMotionEvent
D. ComponentEvent
Answer: B
31. Pick the correct statement to register a button b for event handling
A. b.addActionListener(this);
B. b.addItemListener(this);
C. b.addMouseListener(this);
D. b.addFocusListener(this);
Answer: A
32. Suppose that you want to have an object 'eh' to handle the TextEvent of a TextArea object.How
should you add eh as the event handler to it.
A. t.addTextListener(eh)
B. eh.addTextListener(t)
C. addTextListener(eh,t)
D. addTextListener(t,eh)
Answer: A
35. To listen to mouse clicked events, the listener must implement the __________ interface or
extend the _______ adapter.
A. mouselistner / mouseadapter
B. mousemotionlistner / mousemotionadapter
C. WindowListener/WindowAdapter
D. ComponentListener/ComponentAdapter
Answer: A
C. D.
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.applet.*; import java.applet.*;
public class Fifth5 extends Applet implements public class Fifth5 extends Applet implements
ItemListener ItemListener
{ {
Checkbox cb1,cb2,cb3; Checkbox cb1,cb2,cb3;
CheckboxGroup cbg; CheckboxGroup cbg;
Label l1; Label l1;
public void init() public void init()
{ {
cbg=new CheckboxGroup(); cbg=new CheckboxGroup();
cb1=new Checkbox("C cb1=new Checkbox("C
programming",cbg,false); programming",cbg,false);
cb2=new Checkbox("C++ cb2=new Checkbox("C++
programming",cbg,false); programming",cbg,true);
cb3=new Checkbox("Java cb3=new Checkbox("Java
programming",cbg,false); programming",cbg,false);
l1=new Label("Before ItemSelection"); l1=new Label("Before ItemSelection");
add(cb1); add(cb1);
add(cb2); add(cb2);
add(cb3); add(cb3);
add(l1); add(l1);
} } } }
Answer: D
37. Complete the code to display the selected item of the list.
/* <applet code="MyControl11" width=300 height=300> </applet> */
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class MyControl11 extends Applet implements ItemListener
{
List list;
Label l;
public void init()
{
list=new List();
l=new Label();
list.add("one");
list.add("two");
list.add("three");
setLayout(null);
list.setBounds(20,20,100,20);
l.setBounds(20,150,100,20);
add(list);
add(l);
list.addItemListener(this);
}
public void itemStateChanged(ItemEvent ie)
{
________________________
} }
A. List.getSelectedObjects();
B. l.setText(list.getSelectedItem());
C. label.setText(list.getSelectedItem());
D. list.getItem();
Answer: B
38. Consider following output. Find missing statement from following code.
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class keyEp extends Applet implements KeyListener
{
String msg=" ";
int x=10, y=20;
public void init()
{
addKeyListener(this);
}
public void keyPressed(KeyEvent k)
{
showStatus("key pressed");
int kl=k.getKeyCode();
switch(kl)
{
case KeyEvent.VK_LEFT:
msg+="<left arrow>";
break;
case KeyEvent.VK_RIGHT:
msg+="<right arrow>";
break;
}
repaint();
}
public void keyReleased(KeyEvent k)
{
showStatus("key up");
}
public void keyTyped(KeyEvent l)
public void paint(Graphics g)
{
g.drawString(msg,x,y);
} }
A. Missing }
B. Missing ;
C. Missing ( )
D. Missing{}
Answer: D
40. Consider the following output. Find the missing statement in the program.
import java.awt.Frame;
import java.awt.event.*;
public class HandleMouseListenerInWindowExample extends Frame implements MouseListener{
int x=0, y=0;
String strEvent = "";
HandleMouseListenerInWindowExample(String title){
super(title);
addWindowListener(new MyWindowAdapter(this));
addMouseListener(this);
setSize(300,300);
setVisible(true); }
public void mouseClicked(MouseEvent e) {
strEvent = "MouseClicked";
x = e.getX();
y = getY();
repaint(); }
public void mouseReleased(MouseEvent e) {
strEvent = "MouseReleased";
x = e.getX();
y = getY();
repaint(); }
public void paint(Graphics g){
g.drawString(strEvent + " at " + x + "," + y, 50,50); }
public static void main(String[] args) {
HandleMouseListenerInWindowExample myWindow =
new HandleMouseListenerInWindowExample("Window With Mouse Events Example");
} }
class MyWindowAdapter extends WindowAdapter{
HandleMouseListenerInWindowExample myWindow = null;
MyWindowAdapter(HandleMouseListenerInWindowExample myWindow){
this.myWindow = myWindow;
}
public void windowClosing(WindowEvent we){
myWindow.setVisible(false);
}
A. B.
public void mouseExited(MouseEvent e) { public void mouseEntered(MouseEvent e) {
strEvent = "MouseExited"; strEvent = "MouseEntered";
x = e.getX(); x = e.getX();
y = getY(); y = getY();
repaint(); } repaint(); }
C. D.
public void mousePressed(MouseEvent e) { All of the Above
strEvent = "MousePressed";
x = e.getX();
y = getY();
repaint(); }
Answer: D
41. 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(); }
public void paint(Graphics g)
{
g.drawString(msg, X, Y); }
}
A. paint();
B. paintGraphics()
C. repaint();
D. None of these
Answer: C
42. Consider the following program. What correction should be done in the program to get correct
output?
import java.applet.*;
import java.awt.event.*;
/* <APPLET Code="SimpleKey" Width=200 Height=250> </APPLET> */
public class SimpleKey extends Applet 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)
{
}
A. Missing {
B. Missing }
C. Missing statement
D. Missing semicolon
Answer: B
43. Consider the following program. Choose the missing statements to get correct output.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
{
List year, branch;
public void init()
{
add(new Label("Select year and branch:"));
year=new List(3);
branch=new List(5);
year.add("First Year");
year.add("Second Year");
year.add("Third Year");
add(year);
branch.add("AE");
branch.add("CO");
branch.add("EE");
branch.add("EJ");
branch.add("IF");
branch.add("ME");
add(branch);
}
public void paint(Graphics g)
{
g.drawString("You selected: "+year.getSelectedItem()+" "+branch.getSelectedItem(),10, 160);
}}
A. B.
public class Sample extends Applet implements public class Sample extends Applet implements
ItemListener ActionListener
year.addItemListener(this); year.addActionListener(this);
branch.addItemListener(this); branch.addActionListener(this);
public void itemStateChanged(ItemEvent ie) public void actionPerformed(ActionEvent ae)
{ {
repaint(); repaint();
} }
C. D.
public class Sample extends Applet implements public class Sample extends Applet implements
AdjustmentListener WindowListener
year.addAdjustmentListener(this); year.addWindowListener(this);
branch.addAdjustmentListener(this); branch.addWindowListener(this);
public void itemStateChanged(AdjustmentEvent public void windowActivated(WindowEvent we)
ae) {
{ repaint();
repaint(); }
}
Answer: A
44. Consider the following program. Find which statement contains error.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*<applet code = "PasswordAL.java" width = 600 height=600></applet>*/
public class PasswordAL extends Applet implements ActionListener
{
Button b1; String msg;
TextField t1;
public void init()
{
b1 = new Button("Click ME");
b1.addActionListener(this);
add(b1);
msg ="Wait";
t1 = new TextField(10);
t1.setEchoChar('#');
add(t1); }
public void actionPerformed()
{
String t;
t = ae.getActionCommand();
if(t.equals("Click ME") )
{
t = t1.getText();
if(t.equals("java") )
msg = "Correct";
else
msg="Wrong";
repaint();
} }
public void paint(Graphics g)
{
g.drawString(msg,200,200);
} }
A. error in the statement where ActionListener is implemented
B. error in the statement where getActionCommand is called
C. error in the statement where public void actionPerformed() method is called
D. None of the above
Answer: C
C. public class TestDemo extends JApplet D public class TestDemo extends JApplet
{ {
public void init() public void init()
{ {
JButton b = new JButton("Button"); JButton b = new JButton("Button");
Container c = getContentPane(); c.setLayout(new FlowLayout());
c.setLayout(new FlowLayout()); c.add(b);
} }
} }
Answer: A
47. Debug the following code and find which statement contains error.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class DemoAdjustmentEvent extends Applet
implements AdjustmentListener
{
Scrollbar sbRed,sbGreen,sbBlue;
public void init()
{
sbRed=new Scrollbar(Scrollbar.VERTICAL,20,10,0,255);
sbGreen=new Scrollbar(Scrollbar.VERTICAL,20,10,0,255);
sbBlue=new Scrollbar(Scrollbar.VERTICAL,20,10,0,255);
add(sbRed);add(sbGreen);add(sbBlue);
sbRed.addAdjustmentListener(this);
sbGreen.addAdjustmentListener(this);
sbBlue.addAdjustmentListener(this);
}
public void itemStateChanged(AdjustmentEvent ae)
{
int r=sbRed.getValue();
int g=sbGreen.getValue();
int b=sbBlue.getValue();
Color c=new Color(r,g,b);
setBackground(c);
}}
/*<applet codebase="DemoAdjustmentEvent.class" width=300 height=300></applet>*/
A. Error in statement were itemStateChanged( ) method is defined
B. Error in <applet> tag
C. Error in statement were Scrollbar sbRed is created
D. Both A and B
Answer: A
50. For the following code select the listener implemented by class
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/* <applet code="JRadioEvent" width=300 height=100> </applet> */
public class JRadioEvent extends JApplet implements ______________
{
ButtonGroup grp;
JRadioButton red,pioonk,green;
JTextArea ta;
public void init()
{
setLayout(new FlowLayout());
ta=new JTextArea(5,10);
setupButtons();
addListeners();
add(red);
add(pink);
add(green);
add(ta);
}
public void setupButtons()
{
red=new JRadioButton("Red");
pink=new JRadioButton("Pink");
green=new JRadioButton("Green");
grp=new ButtonGroup();
grp.add(red);
grp.add(pink);
grp.add(green);
}
public void addListeners()
{
red.addItemListener(this);
pink.addItemListener(this);
green.addItemListener(this);
}
public void itemStateChanged(ItemEvent ie)
{
Object src=ie.getSource();
if(ie.getStateChange()==ItemEvent.SELECTED)
{
if(src==red)
ta.append("We like Redn");
else if(src==pink)
ta.append("We like Pink n");
else
ta.append("We like Green n");
} } }
A. ActionListener
B. ComponentListener
C. ItemListener
D. MouseListener
Answer: A
CHAPTER 4: Networking
Q. QUESTION
1. -------is protocol
A. netnews
B. finger
C. e-mail
D. all of the above
Answer: D
7. getAllByName() method returns an array of_____________ that represents all of the addresses
that specific host name has
A. host names
B. InetAddresses
C. ipaddresses
D. objects
Answer: B
11. If server socket is created using serversocket () constructer then which method should we use to
bind the serve socket ?
A. isbind()
B. bind()
C. bind To()
D. bind ( socketAddress host , int backlog)
Answer: D
13. In Uniform Resource Locator (URL), path is pathname of file where information is
A. Stored
B. Located
C. to be transferred
D. Transferred
Answer: A
20. Unlike User Datagram Protocol (UDP), Transmission Control Protocol (TCP) has Services which is
A. Connection Oriented
B. Connectionless
C. Connection Available
D. Connection Origin
Answer: A
23. What happens if server socket is not able to listen on specified port ?
A. The system exits gracefully with
appropriate message
B. The system will wait till port is free.
C. IOExeption is thrown when opening the
socket
D. PortOccupiedException is thrown.
Answer: C
25. When you will use this ServerSocket(int port, int que) constructor to create server socket
A. to create ServerSocket with port number
B. to create ServerSocket with port number & Ip address
C. to create ServerSocket with port number and number of incoming client queue
D. B&C
Answer: C
26. If port number is not specified in the URL, getPort() method returns _______
A. -1
B. 8080
C. 80
D. 25
Answer: A
27. If server socket is created using serversocket() constructer then which method should we use to
bind the serve socket?
A. isbind()
B. bind()
C. bindTo()
D. bind(socketAddress host , int backlog)
Answer: D
28. If you use either Telnet or FTP, which is the highest layer you are using to transmit data?
A. Application
B. Presentation
C. Session
D. Transport
Answer: A
30. In Uniform Resource Locator (URL), path is pathname of file where information is
A. Stored
B. Located
C. to be transferred
D. Transferred
Answer: A
36. For the following client side code of TCP implementation of sockets, what should be the server
side code in order to establish connection between both the machines?
import java.io.IOException;
import java.net.*;
public class Client
{
public static void main(String[] args) throws UnknownHostException, IOException
{
Socket sock=new Socket("127.0.0.1",2000);
}
}
A. B.
import java.io.IOException; import java.io.IOException;
import java.net.*; import java.net.*;
public class Server public class Server
{ {
public static void main(String[] args) public static void main(String[] args)
throws IOException throws IOException
{ {
ServerSocket ss=new ServerSocket(2000); ServerSocket ss=new ServerSocket();
Socket sock=ss.accept(); Socket sock=new Socket(2000);
System.out.println("Connection System.out.println("Connection
Established"); Established");
} }
} }
C. D.
import java.io.IOException; import java.io.IOException;
import java.net.*; import java.net.*;
public class Server public class Server
{ {
public static void main(String[] args) public static void main(String[] args)
throws IOException throws IOException
{ {
ServerSocket ss=new ServerSocket(2000); ServerSocket ss=new ServerSocket(2000);
System.out.println("Connection Socket sock=ssop.accept();
Established"); System.out.println("Connection
} Established");
} }
}
Answer: A
C. D.
URL url; None of the above
try
{
url = new URL("...");
conection = url.openConnection();
}
catch (MalFormedURLException e)
{}
Answer: A
C. D.
static InetAddress getLocalHost( ) throws All of the mentioned
UnknownHostException
Answer: D
41. In following Java program fill statement showing ***. Select any one option from given options.
class URLDemo
{
public static void main(String args[]) throws MalformedURLException
{
******************
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. URL netAddress=new URL(http://www.sun.com.8080//index.html);
B. URL netAddress=new URL(http://www.sun.com.//index.html);
C. URL netAddress=new URL(http://www.sun.com//*.html);
D. URL net=new URL(http://www.sun.com.8080//index.html)
Answer: B
42. In following java program fill statement showing *****. Select any one option from given options.
import java.net.*;
public class InetDemo
{
public static void main(String[] args)
{
try
{
InetAddress ip=InetAddress.****************
System.out.println("Host Name: "+ip.getHostName());
System.out.println("IP Address: "+ip.getHostAddress());
}
catch(Exception e)
{
System.out.println(e);
}
}
}
A. getByName();
B. getByName("www.msbte.com");
C. getName( );
D. getName("www.msbte.com");
Answer: B
43. In the following code, what type of protocol is Socket object "skt" uses?
import java.io.*;
import java.net.*;
public class NetClient
{
public static void main(String args[]) throws Exception
{
Socket skt = new Socket("host",88);
}
}
A. Connectionless
B. FTP
C. UDP
D. TCP
Answer: D
44. In the following program choose the correct strings from given options to pass in URL constructor
to get an output without any exception.
import java.net.*;
class URLDemo
{
public static void main(String args[]) throws MalformedURLException
{
URL hp = new URL("__________");
System.out.println("Protocol: " + hp.getProtocol());
System.out.println("Port: " + hp.getPort());
System.out.println("Host: " + hp.getHost());
System.out.println("File: " + hp.getFile());
}
}
a) http://www.msbte.com/mainsite/index.php
b) http://www.msbte.com:80/mainsite/index.php
c) www.msbte.com/
d) www.msbte.com/mainsite/index.php
A. Only a
B. Only b
C. Either a or b
D. All
Answer: C
C. D.
Protocol: https Protocol: https
Port: -1 Port: -1
Host: www.google.com Host: www.google.com
File: /downloads File: google
Ext: https://www.google.com
Answer: B
B.
C.
D.
Answer: C
48. Select the source code to display following output.
A. B.
import java.net.*; import java.net.*;
class NetworkDemo class NetworkDemo
{ {
public static void main(String args[]) public static void main(String args[]) throws
{ UnknownHostException
InetAddress ip[]=InetAddress.getAllByName {
("www.yahoo.com"); InetAddress ip[]=InetAddress.getAllByName
for(int i=0;i<ip.length;i++) ("www.yahoo.com");
{ for(int i=0;i<ip.length;i++)
System.out.println(ip[i].getHostAddress()); {
} System.out.println(ip[i].getHostAddress());
} }
} }
}
C. D.
import java.net.*; import java.net.*;
class NetworkDemo class NetworkDemo
{ {
public static void main(String args[]) throws public static void main(String args[]) throws
UnknownHostException UnknownHostException
{ {
InetAddress ip[]=InetAddress.getByName InetAddress ip=InetAddress.getByName
("www.yahoo.com"); ("www.yahoo.com");
for(int i=0;i<ip.length;i++) System.out.println(ip[i].getHostAddress());
{ }
System.out.println(ip[i].getHostAddress()); }
}
}
}
Answer: B
50. 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
Answer: D
CHAPTER 5: Databases
Q. QUESTION
1. Can we retrieve a whole row of data at once, instead of calling an individual ResultSet.getXXX
method for each column ?
A. No
B. Yes
C. Statement is incorrect
D. None of the above
Answer: A
5. Identify Correct Syntax for following method of ResultSet ______ absolute (______);
A. boolean, int
B. boolean, void
C. void, int
D. void, void
Answer: A
11. Type of server in two-tier architectures which provides data to client stored on disk pages is called
A. transaction server
B. functional server
C. disk server
D. data server
Answer: D
12. What happens if you call the method close() on a ResultSet object?
A. the method close() does not exist for a
ResultSet. Only Connections can be
closed.
B. the database and JDBC resources are
released
C. you will get a SQLException, because only
Statement objects can close ResultSets
D. the ResultSet, together with the
Statement which created it and the
Connection from which the Statement
was retrieved, will be closed and release
all database and JDBC resources
Answer: B
18. Which of the Following is NOT a valid Syntax for getConnection() Method
A. public static Connection
getConnection(String url)
B. public static Connection
getConnection (String url, String
userID, String password)
C. public static Connection
getConnection(jdbc:<subprotocol>:
<subname>, String userID, String
password)
D. None of the Above
Answer: C
21. Which type of Driver communicate using a network protocol to a middleware server
A. Type 1 Driver
B. Type 2 Driver
C. Type 3 Driver
D. Type 4 Driver
Answer: C
22. ________ is an open source DBMS product that runs on UNIX, Linux and Windows.
A. MySQL
B. JSP/SQL
C. JDBC/SQL
D. Sun ACCESS
Answer: A
24. Application program interface in two tier architecture database management system is provided
by the
A. close module connectivity
B. open module connectivity
C. close database connectivity
D. open database connectivity
Answer: D
25. The _____________ method executes an SQL statement that may return multiple results.
A. executeUpdate()
B. executeQuery()
C. execute()
D. noexecute()
Answer: C
28. How will JDBC help the programmers to write java applications that manage programming
activities:
A. It helps us to connect to a data source, like a database.
B. It helps us in sending queries and updating statements to the database
C. Retrieving and processing the results received from the database in terms of answering to your
query.
D. All of Above
Answer: D
30. In DriverManager class which method is used to establish the connection with specified url
A. public static void deregisterDriver(Driver driver)
B. public static void registerDriver(Driver driver)
C. public static Connection getConnection(String url)
D. public static Connection getConnection (String url,String userName,String password)
Answer: C
31. In setXXX() methods used for Prepared-Statement the first argument specifies which value?
A. index of column
B. index of row
C. index of Question mark
D. index of Resultset
Answer: C
32. In the following JDBC drivers which is known as partially java driver?
A. JDBC-ODBC bridge driver
B. Native-API driver
C. Network Protocol driver
D. Thin driver
Answer: B
33. In three tier model, middle tier of the services acts as a mediator between _____ and _____.
A. Java applet and DBMS
B. Java application and databases
C. Data source and Application server
D. DBMS and user
Answer: B
34. In the three-tier model, commands are sent to a middle tier of services, which then send SQL
statements to the _______________
A. Client
B. Server
C. Database
D. JDBC
Answer: C
38. To execute a SELECT statement "select * from Address" on a Statement object stmt, use
A. stmt.execute("select * from Address");
B. stmt.executeQuery("select * from Address");
C. stmt.executeUpdate("select * from Address");
D. stmt.query("select * from Address");
Answer: B
41. Using JDBC you can send SQL, PL/SQL statements ___________________
A. to almost any relational database.
B. to MySQL database
C. to MSAccess
D. to Oracle
Answer: A
44. What contains object specific to database, and used to create Connection object from the
options?
A. Driver Interface / Connect()
B. ResultSet
C. Statement
D. Driver Manager
Answer: A
}
}
CHAPTER 6: Servlet
Q. QUESTION
1. _____ is the first phase of servlet life cycle
A. service
B. initialization
C. destroy
D. both ii and iii
Answer: B
3. _________ class provides functionality that makes it easy to handle requests and responses.
A. ServetRequest
B. ServletResponse
C. GenericServlet
D. None of these
Answer: C
8. A user types the URL http://www.msbte.com/result. php. Which HTTP request gets generated? Select the one
correct answer
A. GET method
B. POST method
C. HEAD method
D. PUT method
Answer: A
10. An image file representing a company's logo has to be uploaded to the server. Which of the following HTTP methods
can be used in this situation?
A. doGet()
B. doPost()
C. doTrace()
D. doPut()
Answer: D
16. For a given ServletResponse response, which retrieve an object for writing text data?
A. response.getOutputWriter()
B. response.getWriter()
C. response.getWriter().getOutputStream()
D. response.getWriter(Writer.OUTPUT_TEXT)
Answer: B
19. Given an HttpServletRequest request and HttpServletResponse response, which sets a cookie "username" with the
value "joe" in a servlet?
A. request.addCookie(new Cookie("username", "joe"));
B. response.addCookie(new Cookie("username", "joe"));
C. response.addCookie("username", "joe");
D. request.addCookie("username", "joe");
Answer: A
24. Identify the correct sequence of Steps for creation and execution of java and html file for servlet
A) Create a directory structure under Tomcat for your application. Write the servlet source code. You need to import the
B) Javax.servlet package and the javax.servlet.http package in your source file.
C) Compile your source code.
D) Create a deployment descriptor.
E) Run Tomcat.
F) Call your servlet from a web browser.
A. ABCDEF
B. ACBDEF
C. BCADEF
D. none of the above
Answer: A
25. In Session tracking which method is used in a bit of information that is sent by a web server to a browser and which
can later be read back from that browser?
A. HttpSession
B. URL rewriting
C. Cookies
D. Hidden from Fields
Answer: C
26. Which method is used to get HttpSession object and it belongs to which object?
A. getSession method and HttpServletRequest
B. getSession method and HttpServletResponse
C. getHttpSession and HttpServletResponse
D. getHttpSession and HttpServletRequest
Answer: A
28. Which method returns a servletConfig object that contains any initialization parameters?
A. servletConfig getServletConfig()
B. ServiceConfig getServlet()
C. ServiceConfig getServletConfig()
D. ServiceConfig getConfig()
Answer: B
29. Which methods are used to Extract all names and value pairs from the Http request
A. getParameter() and getParameterValues()
B. getParameter() and getParameterNames()
C. getParameterNames() and getParameterValues()
D. getParameterNameValues() and getParameter()
Answer: C
30. Which of following is not true for servlet?
A. it is persitent
B. platform independence
C. high performance
D. it is single threaded
Answer: D
31. Which of the following are class? 1.ServletContext 2.Servlet 3.GenericServlet 4.HttpServlet
A. 1,2,3,4
B. 1,2
C. 3,4
D. 1,4
Answer: C
33. Which of the following methods are main methods in life cycle of servlet?
1. init()
2. service()
3. destroy()
4.stop()
5.wait()
A. 1,2,3,4,5
B. 1,2,3
C. 3,4,5
D. 1,4,5
Answer: B
34. Sessions is a part of the session tracking and it is for maintaining the client state at server side?
(a) True
(b) False
ANSWER: A
35. In session tracking which method is used in a bit of information that is sent by a web server to a browser
and which can later be read back from that browser?
(a) HttpSession
(b) URL rewriting
(c) Cookies
(d) Hidden form fields
ANSWER: C
B.
import javax.servlet.http.*;
import java.util.*;
C.
import javax.servlet.*;
import java.util.*;
D.
import javax.servlet.http.*;
import java.io.*;
Answer: A
45. Consider the following code.Select the missing statement to get proper output.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class CookEx extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
String name=req.getParameter("name");
String value=req.getParameter("age");
Cookie c=new Cookie(name,value);
String p1=c.getName();
String p2=c.getValue();
out.println("Name:" +p1);
out.println("Age:"+p2);
out.println(" ");
} }
A. req.addCookie(c);
B. res.addCookie(c);
C. addCookie(c);
D. res.addCookie();
Answer: B
responce.setContentType("text/html");
PrintWriter pw = responce.getWriter();
pw.println("<B>MyCookie has been set to");
pw.println(data);
pw.close();
}
}
A. responce.cookie(cookie);
B. responce.add(cookie);
C. responce.addCookie(cookie);
D. none of the above
Answer: C
48. Consider the following program and find out the missing statement
import javax.servlet.*;
import java.io.*;
public class image extends GenericServlet
{
public void service(ServletRequest req,ServletResponse res)throws ServletException,IOException
{
res.setContentType("image/jpeg");
pw.println("<html>");
pw.println("<img src='Sunset.jpg' width=600 height=800>");
pw.println("</html>");
}}
A. PrintWriter pw=res.getWriter();
B. Cookie pw=res.getCookies();
C. InputStream pw=res.getInputStream();
D. String pw;
Answer: A
49. 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", dat;
B. new Cookie("MyCookie", data);
C. new Cookie("MyCookie", data2);
D. new Cookie("MyCookie", database);
Answer: B
50. In following Java program fill statement showing ******.Select any one option from given options.
import java.io.*;
import java.util.*;
import javax.servlet.*;
public class PostParametersServlet extends GenericServlet {
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
PrintWriter pw = response.getWriter();
Enumeration e = ******;
// Display parameter names and values.
while(e.hasMoreElements()) {
String pname = (String)e.nextElement();
pw.print(pname + " = ");
String pvalue = request.getParameter(pname);
pw.println(pvalue);
}
pw.close();
} }
A. request.getParameterNames();
B. request.getparameterNames();
C. Request.getParameterNames();
D. request.getParameterName();
Answer: A