Beruflich Dokumente
Kultur Dokumente
A.middle level
B.top most level
C.bottom most level
D.none of these
ANS:-bottom most level option C.
13.Which class is used to create a pop-up list of items from which the user may choose?
A.List
B.Choice
C.Labels
D.Checkbox
ANS:-Choice option B.
20.___________ AWT component is used to create popup list of string items from which only one can be
selected at a time.
A.List
B.Choice
C.MenuBar
D.Scrollbar
ANS:-Choice option B.
27.Which of the following controls does not support interaction with user?
A.Label
B.Button
C.List
D.Scroll bar
ANS:-Label option A.
28. ____________ is a passive AWT control which do not generate any event.
A.Button
B.Label
C.Checkbox
D.List
ANS:-Label option B.
29.When layout manager is disabled , which method is used to determine the shape and position of
Component?
A.setPosition
B.setSize
C.SetDimension
D.setBounds
ANS:-setBounds option D.
42.What does the following line of code do? TextField text = new TextField(10);
A.Creates the object text and initializes it with the value 10
B.Creates text object that can hold 10 columns of text
C.Creates text object that can hold 10 rows of text
D.The code is illegal
ANS:-Creates text object that can hold 10 columns of text option B.
46.Which of these packages contains all the classes and methods required for event handling in Java?
A.java.applet
B.java.awt
C.java.awt.event
D.java.event
ANS:-java.awt.event option C.
55.If a class extends the ActionListener interface, it must contain a method called __________.
A.actionPerformed()
B.ActionEvent()
C.Componentadded()
D.None Of The Above
ANS:-actionPerformed() option A.
C.An event is an object that describes any change by the user and system.
57.EventObject is in ______________package.
A.java.applet
B.java.util
C.java.io
D.none of the above
ANS:-java.util option B.
58.At the root of the Java event class hierarchy is ___________which is the superclass for all events.
A.Object
B.int
C.String
D.All of these
ANS:-Object option A.
67.Which of these methods will respond when you click any button by mouse?
A.mouseClicked()
B.mouseEntered()
C.mousePressed()
D.all of the mentioned
ANS:-all of the mentioned option D.
68.Which of these packages contains all the classes and methods required for even handling in Java?
A.javapplet
B.java.awt
C.java.event
D.java.awt.event
ANS:-java.awt.event option D.
69.___________is the abstract superclass for all component input event classes.
A.InputEvent
B.ItemEvent
C.AdjustmentEvent
D.WindowEvent
ANS:-InputEvent option A.
71.when we need to use check boxes or item from the list or use a checkable menu,an
_________________is generated.
A.ActionEvent
B.ItemEvent
C.AdjustmentEvent
D.ComponentEvent
ANS:-ItemEvent option B.
73.what value is returned by the readLine() method when it reaches the end of file?
A.\n
B.URL
C.EOF
D.null
ANS:-null option D.
74.Which of these methods is used to know the full URL of an URL object?
A.getLocalHost()
B.getByName()
C.getHostName()
D.getAddress()
ANS:-getLocalHost() option A.
75.Which of the following is a connection oriented protocol?
A.UDP
B.HTTP
C.TCP
D.All of these
ANS:-TCP option C.
76.Which method of ServerSocket will wait for a client to initiate communications and then communicate
with the client.
A.accept()
B.wait()
C.getData()
D.recieveBytes()
ANS:-accept() option A.
77.The factory method which returns an array of InetAddresses that represent all of the addresses that a
particular host name resolves to.
A.getAllByName( )
B.getByName()
C.getLocalHost()
D.getName()
ANS:-getAllByName( ) option A.
78.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()
ANS:-getData() option A.
85. ________ is a low level routing protocol that breaks data into smaller packets.
A.Transmission control protocol.
B.Internet protocol.
C.File transfer protocol.
D.User datagram protocol
ANS:-Internet protocol. option B.
87.Which constructor of DatagramSocket class is used to create a datagram socket and binds it with the
given Port Number?
A.DatagramSocket(int port)
B.DatagramSocket(int port, InetAddress address)
C.DatagramSocket()
D.None of the above
ANS:-DatagramSocket(int port, InetAddress address) option B.
89. _________ class is used for accessing the attribute of a remote resource.
A.URL Class
B.URLConnection Class
C.Connection Class
D.ConnectionUrl Class
ANS:-URLConnection Class option B.
90.Which exception indicate that the IP address of a host could not be determined.
A.UnknownHostException
B.IOException
C.HostNotFoundException
D.None of these
ANS:-UnknownHostException option A.
91._______________ method s is used to retrieve file name in specified URL.
A.getFile()
B.returnFile()
C.recieveFile()
D.retrieveFile()
ANS:-getFile() option A.
94.Which exception is thrown by InetAddress class when it cant resolve the name of address?
A.UnidentifiedAddressException
B.UnknownAddressException
C.UnknownHostException
D.AddressException
ANS:-UnknownHostException option C.
95.In the format for defining the URL what is the last part?
A.Protocol
B.File path
C.Port number
D.Host name
ANS:-File path option B.
96.To access attributes of a remote host which of the following class is used.
A.URL
B.URLConnection
C.Socket
D.InetAddress
ANS:-URLConnection option B.
99.The _________________ method executes a simple query and returns a single Result Set object.
A.execute()
B.executeQuery()
C.executeUpdate()
D.noexecute()
ANS:-executeQuery() option B.
101.Which interface provides various methods for transaction and error handling.
A.Driver
B.Connection
C.Statement
D.ResultSet
ANS:-Connection option B.
102.Which JDBC driver Type(s) can be used in either applet or servlet code?
A.Both Type 1 and Type 2
B.Both Type 1 and Type 3
C.Both Type 3 and Type 4
D.Type 4 only
ANS:-Both Type 3 and Type 4 option C.
104.Connection object can be initialized using the ____________method of the Driver Manager Class.
A.putConnection()
B.setConnection()
C.Connection()
D.getConnection()
ANS:-getConnection() option D.
107. Which of the following methods are needed for loading a database driver in JDBC?
A.registerDriver() method
B.Class.forName ()
C.Both A and B
D.getConnection ()
ANS:-Class.forName () option B.
108.The _______________ method returns the number of rows affected.
A.execute()
B.executeUpdate()
C.executeQuery()
D.None
ANS:-executeUpdate() option B.
114.In which model java application or applet supports for database access?
A.2 tier model
B.3 tier model
C.both a and b
D.None of the above
ANS:-both a and b option C.
116. _______ method of DriverManager class is used to establish connection with the database.
A.openConnection()
B.getConnection()
C.connect()
D.createConnection()
ANS:-getConnection() option B.
118.Which of the following is used generally for reading the content of the database?
A.boolean execute()
B.ResultSet executeQuery()
C.int executeUpdate()
D.None of the above.
ANS:-ResultSet executeQuery() option B.
125.Servlet is ____________.
A.Platform Independent
B.Platform Dependent
C.Both A and B
D.None of the above
ANS:-Platform Independent option A.
127.Which of the following method can be used to get complete list of all parameters in the current
request?
A.request.getParameter()
B.request.getParameterValues()
C.request.getParameterNames()
D.None of the above.
ANS:-request.getParameterNames() option C.
132.Which cookies it is valid for single Session only, it is removed each time when user closes the
browser?
A.Persistent Cookie
B.Non-Persistent Cookie
C.Both A & B
D.None of the above
ANS:-Non-Persistent Cookie option B.
139.getSession() method with true as parameter it will return the appropriate session object.
A.session object is completed
B.session object is passed to another method
C.session does not exists
D.session is existing
ANS:-session is existing option D.
142.If you want to track active session or how many users are there? which listener you should use.
A.ServletRequestListener
B.ServletContextListener
C.HttpSessionListener
D.HttpSessionBindingListener
ANS:-HttpSessionListener option C.
143.The _______ method is called when the servlet is first created, and is not called again as long as the
servlet is not destroyed.
A.service
B.destroy
C.init
D.getServletInfo
ANS:-init option C.
import javax.swing.*;
import java.awt.*;
147.Which of the following creates a List with 5 visible items and multiple selection enabled?
A.new List(5, true)
B.new List(true, 5)
C.new List(5, false)
D.new List(false, 5)
ANS:-new List(5, true) option A.
import java.awt.*;
import java.applet.*;
/*<html><body>
<applet code=Demo height=500 width=500></applet>
</body></html>*/
public class Demo extends Applet
{
Label l1,l2;
Button b1;
TextField t1,t2;
public void init()
{
l1=new Label("ID");
add(l1);
l2=new Label("Pass");
b1=new Button("Save");
t1=new TextField(10);
add(t1);
t2=new TextField(10);
add(t2);
add(l2);
add(b1);
}
}
A.Label, Label, TextField, TextField, Button
B.Label, TextField, TextField, Label, Button
C.Label, TextField, Label, TextField, Button
D.Label, TextField, TextField, Button, Label
ANS:-Label, TextField, TextField, Label, Button option B.
153.Which of the following commands will set a layout manager that divides the container into 3
Columns & 4 Rows?
A.setLayout( new GridLayout(3, 4) )
B.setLayout( new FlowLayout(4, 3) )
C.setLayout( new GridBagLayout(4, 3 ))
D.setLayout( new GridLayout(4, 3) )
ANS:-setLayout( new GridLayout(4, 3) ) option D.
154.Consider the following output. Find the missing statement in the program.
import java.awt.*:
import java.awt.event.*;
import javax.swing.*;
/*
<applet code="JCheckBoxDemo" width=400 height=50>
</applet>
*/
public class JCheckBoxDemo extends JApplet implements ItemListener
{
JTextField jtf;
public void init()
{
Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());
JCheckBox cb = new JCheckBox("C", true);
cb.addItemListener(this);
contentPane.add(cb);
cb = new JCheckBox("C++", false);
contentPane.add(cb);
157.Which among the below is not the method applicable for Button in swing.
A.setDisableIcon()
B.setPressedIcon()
C.setSelectedIcon()
D.setRollovericon()
ANS:-.setDisableIcon() option A.
158.In CardLayout we are going to add components for every card to.
A.Panel
B.Window
C.Frame
D.Applet
ANS:-Panel option A.
159.The concept of the menu bar canbe implemented by using three java classes.
A.MenuBar
B.Menu
C.MenuItem
D.All of these
ANS:-All of these option D.
160.What is Purpose of Jtree ?
A.tree is a component that presents a hierarchical view of data
B.Tree is used to display icon
C.Tree is used display button
D.Tree is used for Label
ANS:-A tree is a component that presents a hierarchical view of data option A.
167.Swing provides a combo box (a combination of a text field and a drop-down list)through the
JComboBox class, which extends_____.
A.Component
B.Container
C.Jcomponent
D.java.swing
ANS:-Jcomponent option C.
170.select the missing statement in the program for the following output
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*<applet code=ColorChange width=250 height=300> </applet>*/
public class ColorChange extends Applet implements ActionListener
{
Button red;
public void init()
{
red=new Button("RED");
add(red);
}
public void actionPerformed(ActionEvent e)
{
setBackground(Color.red);
repaint();
}
}
T2U_2881.jpeg Y1
A.addActionListener(this);
B.red.addActionListener(this);
C.red.addActionListener();
D.red.addActionListener(this)
ANS:-red.addActionListener(this); option B.
171.Which of the following is not one of the seven methods for handling window events?
A.windowClosing
B.windowClosed
C.windowOpened
D.windowOpening
ANS:-windowOpening option D.
172.Choose correct statement from following which implements "create button with caption
'ok' "
A.Button b1=new Button("ok");
B.Button b1=new Button();
C.Button b1= Button("ok");
D.button b1=new button("ok");
ANS:-Button b1=new Button(&quot;ok&quot;); option A.
/*
<applet code="HandleActionEventExample" width=200 height=200>
</applet>
*/
Button1.addActionListener(this);
Button2.addActionListener(this);
}
B.
import java.applet.Applet;
import java.awt.Button;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/*
<applet code="HandleActionEventExample" width=200 height=200>
</applet>
*/
Button1.addActionListener(this);
Button2.addActionListener(this);
}
public void paint(Graphics g){
g.drawString(actionMessage,10,50);
}
public void actionPerformed(){
String action = ae.getActionCommand();
if(action.equals("Ok"))
actionMessage = "";
else if(action.equals("Cancel"))
actionMessage = "Cancel Button Pressed";
repaint();
}
}
C.
import java.applet.Applet;
import java.awt.Button;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/*
<applet code="HandleActionEventExample" width=200 height=200>
</applet>
*/
add(Button1);
add(Button2);
D.import java.applet.Applet;
import java.awt.Button;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/*
<applet code="HandleActionEventExample" width=200 height=200>
</applet>
*/
Button1.addActionListener(this);
Button2.addActionListener(this);
}
ANS:-
import java.applet.Applet;
import java.awt.Button;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/*
&lt;applet code=&quot;HandleActionEventExample&quot; width=200
height=200&gt;
&lt;/applet&gt;
*/
Button1.addActionListener(this);
Button2.addActionListener(this);
}
176.Which of these interfaces handles the event when a component is added to a container?
A.ComponentListener
B.ContainerListener
C.FocusListener
D.InputListener
ANS:-ContainerListener option B.
B.mouseExited,mouseEntered,mousePressed,mouseClicked,mouseReleased
C.mouseDragged,mousePressed,mouseClicked,mouseMoved,mouseReleased
D.mousePressed,mouseReleased,mouseClicked,mouseMoved
ANS:-mouseEntered,mousePressed,mouseClicked,mouseReleased
option B.
{
String msg = "";
int X = 10, Y = 20; // output coordinates
public void init()
{
addKeyListener(this);
requestFocus(); // request input focus
}
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();
}
// Display keystrokes.
public void paint(Graphics g)
{
g.drawString(msg, X, Y);
}
}
A.implements MouseListener
B.implements KeyListener
C.implements keylistener
D.extends KeyListener
ANS:-implements KeyListener option B.
B)The enableEvents() method is used by objects that handle events by overriding their event-dispatch
methods.
A.A and B
B.only A
C.Only B
D.None of these
ANS:- A and B option A.
182.Which of the following statements registers a panel object p as a listener for a button variable jbt?
A.addActionListener(p)
B.jbt.addActionListener(p)
C.jbt.addActionEventListener(p)
D.jbt.addEventListener(p)
ANS:-jbt.addActionListener(p) option B.
184.Select the method used to determine the event ID that represents the natures of the event.
A.public int getID()
B.public object getSource()
C.public String getActionCommand()
D.none of above
ANS:-public int getID() option A.
185.The AWT container is an instance of the ___________ class which holds various components and
other containers.
A.Graphics
B.Container
C.Eventobj
D.None of these
ANS:-Container option B.
193.returns the socket and establish a connection between server and client.
A.public Socket accept()
B.public synchronized void close()
C.both of these
D.none of these
ANS:-public Socket accept() option A.
194.______object is responsible for determining whether code executing in the Java runtime
environment has permission to perform a security-sensitive operation.
A.Policy
B.Permission
C.Serializable
D.Security
ANS:-Policy option A.
A.
import java.net.*;
class URLDemo {
public static void main(String args[]) throws MalformedURLException {
URL hp = new URL("http://www.osborne.com/downloads");
System.out.println("Protocol: " + hp.getProtocol());
System.out.println("Ext:" + hp.toExternalForm());
}
}
B.
import java.net.*;
class URLDemo {
public static void main(String args[]) throws MalformedURLException {
URL hp = new URL("http://www.osborne.com/downloads");
System.out.println("Protocol: " + hp.getProtocol());
System.out.println("Port: " + hp.getPort());
class URLDemo {
public static void main(String args[]) throws MalformedURLException {
URL hp = new URL("http://www.osborne.com/downloads");
System.out.println("Host: " + hp.getHost());
System.out.println("File: " + hp.getFile());
}
}
C.
import java.net.*;
class URLDemo {
public static void main(String args[]) throws MalformedURLException {
URL hp = new URL("http://www.osborne.com/downloads");
System.out.println("Port: " + hp.getPort());
System.out.println("File: " + hp.getFile());
System.out.println("Ext:" + hp.toExternalForm());
}
}
D.import java.net.*;
class URLDemo {
public static void main(String args[]) throws MalformedURLException {
URL hp = new URL(&quot;http://www.osborne.com/downloads&quot;);
System.out.println(&quot;Protocol: &quot;+hp.getProtocol());
System.out.println(&quot;Port: &quot; + hp.getPort());
ANS:-option B.
199.Select the proper method to know the type of content used in the URL.
A.Contenttype()
B.contentType()
C.getContentType()
D.GetContentType()
ANS:-getContentType() option C.
}
A.getname,unkwonException
B.getByName, UnknownHostException
C.getbyall,knownhostexception
D.none is correct
ANS:-getByName, UnknownHostException option B.
class networking {
System.out.print(obj.toExternalForm());
}
A.google
B.google.com
C.www.google.com
D.http://www.google.com
ANS:-http://www.google.com option D.
210.A Select the proper method for retrieving the content length of URL.
A.InputStream getInputStream()
B.String getContentType()
C.int getContentLength()
D.long getDate()
ANS:-int getContentLength() option C.
211.This statement Tells the DB to empty transaction log & bring DB back to the state, before the
changes in transaction log were executed.
A.commit()
B.rollback()
C.connect()
D.prepareStatement()
ANS:-rollback() option B.
213.To syntax for creating a table named Course should begin with ___.
A.create Course
B.create table Course
C.create Course
D.create table Course
ANS:-create table Course option D.
214.JDBC-ODBC Bridge is.
A.Three tiered
B.multithreded
C.best for any platform
D.all of these
ANS:-multithreded option B.
ANS:-Connection connection =
DriverManager.getConnection(&quot;jdbc:mysql://localhost/test&quot;); option D.
216.We can use ResultSet navigation methods when we have ResultSet that is of type.
A.Forword only
B.Scroll sensitive
C.Scroll Insensitive
D.both b and c
ANS:-both b and c option D.
218.Which of the following describes the correct url String format of getConnection() method.
A.subprotocol, protocol,datasource name
B.protocol,datasource name,subprotocol
C.protocol,subprotocol,datasource name
D.datasource name,subprotocol,protocol
ANS:-protocol,subprotocol,datasource name option C.
219.What is the query used to display all tables names in SQL Server ?
A.select * from information_schema.tables
B.select * to information_schema.tables
C.select * to information_schema
D.select * to tables
ANS:-select * from information_schema.tables option A.
225.In Which driver Network connection is indirect that a JDBC client makes to a middleware process
that acts as a bridge to the DBMS server ?
A.JDBC-Net
B.JDBC-ODBC bridge
C. Native API as basis
D. Native -protocol as basis
ANS:-JDBC-Net option A.
226.Given here is simple example of Statement interface to insert, update and delete the record.Write
the missing statement
import java.sql.*;
class FetchRecord{
public static void main(String args[])throws Exception{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system&qu
ot;,"oracle");
---------------------------------------------------------------------------------------
A.Statement stmt=con.createStatement();
B.Statement stmt;
C.createStatement();
D.Statement =con.createStatement();
230.Which interface provides information about finding path,server log file and accessing other servers
over network.
A.ServletConfig
B.ServletContext
C.ServerSocket
D.servletsession
ANS:-ServletContext option B.
233.Suppose you want to know each time request comes in, so that you can log it. Which listener is
appropriate for that?
A.ServletRequestListener
B.ServletRequestAttributeListener
C.ServletContextListener
D.HttpRequestListener
ANS:-ServletRequestListener option A.
234.Consider the following output . find the missing statement in the program
import java.io.*;
import javax.servlet.*;
public class EE extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("image/gif");
File f= new File("C:/Program Files/Apache Software Foundation/Tomcat5.5/webapps/servlets-
examples/images/first.gif");
byte[] a=new byte[(int)f.length()];
FileInputStream is=new FileInputStream(f);
is.read(a);
OutputStream os= response.getOutputStream();
os.write(a);
os.flush();
}
}
T5U_2893.jpeg Y1
A.import javax.servlet.http.*;
B.import javax.servlet.*;
C.import java.io.*;
D.import java.net.*;
ANS:-import javax.servlet.http.*; option A.
B.cookie's value can uniquely identify a client, so cookies are commonly used for session
management.
C.The size of the cookie is 4 MB and a browser can store unlimited cookies.
D.A cookie has a name, a single value, and optional attributes such as a comment, path etc.
ANS:-The size of the cookie is 4 MB and a browser can store unlimited cookies. option C.
236.Which class provides stream to read binary data such as image etc. from the request object?
A.ServletInputStream
B.ServletOutputStream
C.Both A & B
D.None of the above
ANS:-ServletInputStream option A.
242.What is the limit of the data to be passed from HTML when doGet() is used?
A.8kb
B.1kb
C.4kb
D.2kb
ANS:-2kb option D.
243.which is not the methods of GenericServlet class.
A.destroy()
B.getServletConfig( )
C.getSession()
D.getServletContext()
ANS:-getSession() option C.
244.In servlet programming a cookie is represented by the cookie class in _________ package.
A.javax.servlet
B.javax.servlet.http
C.java.servlet.cookie
D.java.servlet.session
ANS:-javax.servlet.http option B.
245.Disadvantage of CGI :
S1] It has lack of scalability and reduced speed.
S2] High response time
S3] CGI is platform dependent
A.S1
B.S2 and S3
C.S1 and S3
D.S1, S2, and S3
ANS:-S1, S2, and S3 option D.
246.Servlets becomes thread safe by implementing the javax. Sevlet. Sigle ThreadModelinterface
___________.
A.as every request is handled by separate instances of the Servlet.
B.as a single thread serves all the client reuests
C.as all the requests are serialized
D.a first to- be loaded sevlet and is loaded by the server during startup
ANS:-as every request is handled by separate instances of the Servlet. option A.
bg.add(b1);
bg.add(b2);
bg.add(b3);
}
public void action Performed(ActionEvent ae )
{
String s;
s= ae.getActionCommand();
if (s=="Red")
cp.setBackground(Color.red);
else if (s=="Green")
cp.setBackground(Color.green);
else if (s=="Blue")
cp.setBackground (Color.blue.);
}
}
A.ButtonGroup bg= new ButtonGroup (this)
B.ButtonGroup bg= new ButtonGroup()
C.Button bg = new ButtonGroup ()
D.ButtonGroup = new ButtonGroup()
ANS:-ButtonGroup bg= new ButtonGroup() option B.
248.Which is the layout manger that occupies the same size on the window?
A.Grid
B.Card
C.Flow
D.Border
ANS:-Grid option A.
import java.applet.*;
import java.awt.*;
public class sample extends Applet
{
public void init()
{
Label l1=new Label(" MSBTE");
List l2=new List(3,true);
l2.addItem("1");
l2.addItem("2");
l2.addItem("3");
TextArea t1=new TextArea(3,4);
add(t1);
add(l1);
add(l2);
}
}
/* <applet code="sample.java" width=300 height=300>
</applet> */
Y2
A.S1Q43O1.jpeg T1A_8783_a1.jpeg
B.S1Q43O2.jpeg T1A_8783_a2.jpeg
C.S1Q43O3.jpeg T1A_8783_a3.jpeg
D.Error
ANS:-S1Q43O3.jpeg option C.
250.Debug the following code and find out which statement contains error.
import java.awt.*;
import java.awt.event.*;
public class MenuDemo extends Frame
{
MenuBar mb;
Menu m1,m2;
MenuItem i1,i2,i3,i4,i5,i6;
MenuDemo(String s)
{
super(s);
mb=new MenuBar();
setMenuBar();
m1=new Menu("File");
m2=new Menu("Edit");
i1=new MenuItem("New");
i2=new MenuItem("Open");
i3=new MenuItem("Exit");
i4=new MenuItem("Cut");
i5=new MenuItem("Copy");
i6=new MenuItem("Paste");
m1.add(i1);
m1.add(i2);
m1.add(i3);
m2.add(i4);
m2.add(i5);
m2.add(i6);
mb.add(m1);
mb.add(m2);
setSize(500,500);
}
public static void main(String args[])
{
MenuDemo m=new MenuDemo("MenuFrame");
m.setVisible(true);
}
}
A.statement where File menu is created
B.statement where New menu item is created
C.statement where New menu item is added to File menu
D.statement where setMenuBar() method is invoked
ANS:-statement where setMenuBar() method is invoked option D.
C.Both button OK and button Cancel are displayed and button OK is displayed on the left side of button
OK.
D.Both button OK and button Cancel are displayed and button OK is displayed on the right side of button
OK.
252.Where g is a graphics instance what will the following code draw on the screen
g.fillArc(45,90,50,50,90,180).
A.An arc bounded by a box of height 45, width 90 with a centre point of 50,50, starting at an angle of
90 degrees traversing through 180 degrees counter clockwise
B.An arc bounded by a box of height 50, width 50, with a centre point of 45,90 starting at an angle of
90 degrees traversing through 180 degrees clockwise
C.An arc bounded by a box of height 50, width 50, with a top left at coordinates of 45, 90, starting at 90
degrees and traversing through 180 degrees counter clockwise
ANS:-An arc bounded by a box of height 50, width 50, with a top left at coordinates of 45, 90, starting at
90
degrees and traversing through 180 degrees counter clockwise option C.
256.if user use following statements in given order on CheckBox B1(“asd”,true) what will happen ....
1.B1.setState(true);
2.B1.setState(false);
3.CheckBoxGroup c=new CheckBoxGroup();
4.B1.setCheckBoxGroup(c);
A.RadioButton c will created with checkbox asd deselected
B.Checkbox is created with selected
C.Checkbox created with deselected
D.RadioButton c will created with checkbox asd selected
ANS:-RadioButton c will created with checkbox asd deselected option A.
B.
import java.awt.*;
public class Butt extends Frame
{
public static void main(String argv[])
{
Butt MyBut=new Butt();
}
Butt()
{
setLayout(new GridLayout(1,2));
Button HelloBut=new Button("Hello");
Button ByeBut=new Button("Bye");
add(HelloBut); add(ByeBut);
setSize(300,300);
setVisible(true);
}
}
}
C.
import java.awt.*;
public class Butt extends Frame
{
public static void main(String argv[])
{
Butt MyBut=new Butt();
}
Butt()
{
setLayout(new GridLayout(2,1));
Button HelloBut=new Button("Hello");
Button ByeBut=new Button("Bye");
add(HelloBut); add(ByeBut);
setSize(300,300);
setVisible(true);
}
}
D.
import java.awt.*;
public class Butt extends Frame
{
public static void main(String argv[])
{
Butt MyBut=new Butt();
}
Butt()
{
setLayout(new FlowLayout(FlowLayout.CENTER));
Button HelloBut=new Button("Hello");
Button ByeBut=new Button("Bye");
add(HelloBut); add(ByeBut);
setSize(300,300);
setVisible(true);
}
}
ANS:-
import java.awt.*;
public class Butt extends Frame
{
public static void main(String argv[])
{
Butt MyBut=new Butt();
}
Butt()
{
setLayout(new FlowLayout(FlowLayout.CENTER));
Button HelloBut=new Button(&quot;Hello&quot;);
Button ByeBut=new Button(&quot;Bye&quot;);
add(HelloBut); add(ByeBut);
setSize(300,300);
setVisible(true);
}
}
option D.
260.In the given program which minimum packages are required to execute program successfully?
/*<applet code="JTableDemo" width=500 height=500>
</applet>
*/
public class JTableDemo extends JApplet
{
JTable table;
JScrollPane jsp;
Container cp;
public void init()
{
String data[][]={
{"1","samarth"},
{"2","Rohan"},
{"3","Ramesh"}
};
String colHead[]={"RollNO","Name"};
cp=getContentPane();
table=new JTable(data,colHead);
cp.setLayout(new FlowLayout());
jsp=new JScrollPane(table);
cp.add(jsp);
}
}
A.import java.awt.*;import javax.swing.*;
B.import java.awt.*;import javax.swing.*;import java.applet.*;
C.import java.awt.*;import java.applet.*;
D.import javax.swing.*;import java.applet.*;
ANS:-import java.awt.*;import javax.swing.*; option A.
import java.awt.*;
import javax.swing.*;
f.setLayout(new FlowLayout(FlowLayout.RIGHT));
//setting flow layout of right alignment
f.setSize(300,300);
f.setVisible(true);
}
public static void main(String[] args) {
new MyFlowLayout();
}
}
A.4
B.5
C.7
D.9
ANS:-5 option B.
/</applet>*/
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
class frameinapp extends Frame
{
String msg=" ";
frameinapp(String title)
{
super(title);
setSize(200,200);
setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
setVisible(false);
}
});
addMouseListener(new MouseAdapter()
{
public void mouseEntered(MouseEvent e)
{
msg="mouse entered in frame";
repaint();
}
public void mouseExited(MouseEvent e)
{
msg="mouse exited from frame";
repaint();
}
});
}
public void paint(Graphics g)
{
g.drawString(msg,50,50);
}
}
public class frameinapp extends Applet
{
framein f;String msg=" ";
public void init()
{
f=new framein("Demo");
addMouseListener(new MouseAdapter()
{
public void mouseEntered(MouseEvent e)
{
msg="mouse entered in Applet";
repaint();
}
public void mouseExited(MouseEvent e)
{
msg="mouse exited from Applet";
repaint();
}
});
}
public void paint(Graphics g)
{
g.drawString(msg,100,100);
}
}
A.java framein
B.java frameinapp
C.Appletviewer frameinapp.java
D.Appletviewer framein.java
ANS:-Appletviewer frameinapp.java option C.
264.Debug the following code and find which statement contains error.
import javax.swing.*;
import java.awt.*;
public class JRadioButtonDemo extends JApplet
{
JRadioButton r1,r2,r3;
Container c;
public void init()
{
c=getContentPane();
c.setLayout(new FlowLayout());
r1=new JRadioButton("Red");
r2=new JRadioButton("Green");
r3=new JRadioButton("Blue");
JRadioButtonGroup b=new JRadioButtonGroup ();
b.add(r1);b.add(r2);b.add(r3);
c.add(r1);c.add(r2);c.add(r3);
}
}
/*<applet code=JRadioButtonDemo.class width=500 height=500></applet>*/
A.Error in statement to create JRadioButton
B.Error in statement to setlayout
C.Error in statement to add JRadioButton
D.Error in statement to create button group i.e. JRadioButtonGroup
ANS:-Error in statement to create button group i.e. JRadioButtonGroup option D.
import java.awt.*;
public class SetF extends Frame
{
public static void main(String argv[])
{
SetF s = new SetF();
s.setSize(300,200);
s.setVisible(true);
}
}
How could you set the frame surface color to pink
A.s.setBackground(Color.pink);
B.s.setColor(PINK);
C.s.Background(pink);
D.s.color=Color.pink
ANS:-s.setBackground(Color.pink); option A.
266.Which control allows user to enter strings and to edit the text using the arrow key,cut and paste keys.
A.Labels
B.buttons
C.textfield
D.list
ANS:-textfield option C.
267.Select the missing statement for given 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 pgLay=new Menu("Page Layout");
Menu ref=new Menu("Reference");
Menu mail=new Menu("Mailing");
mbr.add(pgLay);
mbr.add(ref);
mbr.add(mail);
}
}
T1A_8908.jpeg Y1
A.mail.setEnabled(false);
B.mail.setDisabled(true);
C.mail.setDisabled();
D.setDisabled(mail);
ANS:-mail.setEnabled(false); option A.
B.
import java.awt.*;
import javax.swing.event.*;
import javax.swing.*;
import javax.swing.tree.*;
/*
<applet code="JTreeDemo" width=400 height=200>
</applet>
*/
public class JTreeDemo extends JApplet {
JTree tree;
JLabel jlab;
public void init() {
C.
Demonstrate JTree.
import java.awt.*;
import javax.swing.event.*;
import javax.swing.*;
import javax.swing.tree.*;
/*
<applet code="JTreeDemo" width=400 height=200>
</applet>
*/
public class JTreeDemo extends JApplet {
JTree tree;
JLabel jlab;
public void init() {
D.
Demonstrate JTree.
import java.awt.*;
import javax.swing.event.*;
import javax.swing.*;
import javax.swing.tree.*;
/*
<applet code="JTreeDemo" width=400 height=200>
</applet>
*/
public class JTreeDemo extends JApplet {
JTree tree;
JLabel jlab;
public void init() {
ANS:-
import java.awt.*;
import javax.swing.event.*;
import javax.swing.*;
import javax.swing.tree.*;
/*
&lt;applet code=&quot;JTreeDemo&quot; width=400 height=200&gt;
&lt;/applet&gt;
*/
public class JTreeDemo extends JApplet {
JTree tree;
JLabel jlab;
public void init() {
270.import java.awt.*;
import javax.swing.*;
C.Both button OK and button Cancel are displayed and button OK is displayed on the left side of button
OK
D.Both button OK and button Cancel are displayed and button OK is displayed on the right side of button
OK.
area=new JTextArea(300,300);
area.setBounds(10,30,300,300);
area.setBackground(Color.black);
area.setForeground(Color.white);
f.add(area);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String[] args) {
new TyifArea();
}
}
A.The Output will Contain a multiline textbox having background colour as black
C.The Output will Contain a multiline textbox having background colour as white
D.The Output will Contain a textbox having background colour as black and white
ANS:-The Output will Contain a multiline textbox having background colour as black option A.
272.Which package should be added in the following program to get the proper output:
public class JCheckBoxDemo extends JApplet
implements ItemListener
{
JTextField jtf;
public void init()
{
Container c = getContentPane();
c.setLayout(new FlowLayout());
ImageIcon img1 = new ImageIcon("jpgIcon.jpg");
ImageIcon img2= new ImageIcon("Winter.jpg");
ImageIcon img3 = new ImageIcon("Sunset.jpg");
JCheckBox cb = new JCheckBox("C", img1);
cb.setRolloverIcon(img2);
cb.setSelectedIcon(img3);
cb.addItemListener(this);
c.add(cb);
cb = new JCheckBox("C++",img1);
cb.setRolloverIcon(img2);
cb.setSelectedIcon(img3);
cb.addItemListener(this);
c.add(cb);
jtf = new JTextField(15);
c.add(jtf);
}
public void itemStateChanged(ItemEvent ie)
{
JCheckBox cb = (JCheckBox)ie.getItem();
jtf.setText(cb.getText());
}
}
A.java. awt.*;
B.java.awt.event.*;
C.javax.swing.*;
D.All of these
ANS:-All of these option D.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
{
Button b1;
public void init()
{
b1=new Button("Pink");
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
b1.setBackground(Color.pink");
}
}
A.Can not implement more than one listener at a time
B.FocusListener must be register to any component
C.No Error
D.implementation of FocusListener methods not provide
ANS:-implementation of FocusListener methods not provide option D.
A.itemStateChanged(ActionEvent e)
B.actionPerformed(ActionEvent e)
C.adjustmentValueChanged(ActionEvent e)
D.textValueChanged(TextEvent e)
ANS:-actionPerformed(ActionEvent e) option B.
278.import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="CountVowel.class" width=300 height=100>
</applet>
*/
public class CountVowel extends Applet implements ActionListener
{
TextArea txtArea;
TextField text;
Button btn;
public void init()
{
txtArea = new TextArea();
txtArea.setBounds(30,30,200,200);
add(txtArea);
text = new TextField(20);
text.setBounds(30,240,100,30);
text.setEditable(false);
add(text);
btn = new Button("Calculate");
btn.setBounds(150,230,70,30);
add(btn);
btn.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource() == btn )
{
String strTemp= txtArea.getText();
int count=0;
for(int i=0;i<strTemp.length();i++)
{
if(strTemp.charAt(i)=='a'|| strTemp.charAt(i)=='A'||
strTemp.charAt(i)=='e'|| strTemp.charAt(i)=='E'||
strTemp.charAt(i)=='i'|| strTemp.charAt(i)=='I'||
strTemp.charAt(i)=='o'|| strTemp.charAt(i)=='O'||
strTemp.charAt(i)=='u'|| strTemp.charAt(i)=='U')
{
count++;
}
}
String str=Integer.toString(count);
text.setText(str);
}
}
}
What will be the Output?
T2A_3643.jpeg Y1
A.10
B.12
C.11
D.13
ANS:-12 option B.
C.A frame window which will be displayed and keep on closing automatically.
D.A frame window which can be closed.
282.Find out the missing statement shown by _______________in the following code
import java.awt.event.*;
import java.applet.*;
public class AnnoymousDemoQ extends Applet
{
public void init()
{
________________________________________
{
public void mouseClicked(MouseEvent m)
{
showStatus("MOUSE CLICKED");
}
});
}
}
/*<applet code=AnnoymousDemoQ.class width=500 height=500></applet>*/
A.addMouseMotionListener(new MouseAdapter()
B.addMouseListener(new MouseAdapter())
C.addMouseMotionListner()
D.addMouseListener(this)
ANS:-addMouseListener(new MouseAdapter()) option B.
284.Fill in the blanks so that the following defines a listener that will respond to window closing events:
public class WindowQuitter extends _____________
{
public void _____________( WindowEvent e )
{
System.exit( 0 );
}
}
A.Frame, windowQuitting
B.Frame, windowFrame
C.WindowAdapter, windowClosing
D.WindowAdapter, windowSystem
ANS:-WindowAdapter, windowClosing option C.
285.For the following code, fill up the correct listener name and event name.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/* <applet code="SimpleKeyDemo" width=300 height=100>
</applet> */
public class SimpleKeyDemo extends Applet implements _____________
{
String msg = "";
int X = 10, Y = 20;
public void init()
{
addKeyListener(this);
requestFocus();
}
public void keyPressed( _________ ke)
{
showStatus("Key Down");
}
public void keyReleased( _________ ke)
{
showStatus("Key Up");
}
public void keyTyped( ____________ ke)
{
msg += ke.getKeyChar();
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg, X, Y);
}
}
A.KeyEvent, ItemListener
B.TextListner, KeyEvent
C.Adjustment, AdjustmentEvent
D.KeyListener, KeyEvent
ANS:-KeyListener, KeyEvent option D.
286.For the following code select the methods that can be used to handle event and register the event.
importjava.awt.*;
importjava.applet.*;
/*
<applet code="S1Q50.class" width=300 height=100>
</applet>
*/
public class S1Q50 extends Applet implements MouseMotionListener
{
String msg = "";
intmouseX = 0, mouseY = 0
public void init()
{
add-------------(this);
}
public void ----------------(MouseEvent me)
{
mouseX = me.getX();
mouseY = me.getY();
msg = "*";
showStatus(" Mouse at " + mouseX + ", " + mouseY);
repaint();
}
public void ----------------(MouseEvent me)
{
showStatus("Mouse at " + me.getX() + ", " + me.getY());
}
public void paint(Graphics g)
{
g.drawString(msg, mouseX, mouseY);
}
}
A.addMouseListener(this),mouseClicked(MouseEvent e)
,mouseEntered(MouseEvent e),
B.addMouseWheelListener(this),mouseMoved(MouseEvent e),
mousePressed(MouseEvent e)
C.addMouseMotionListener(this),mouseMoved(MouseEvent e),
mouseDragged(MouseEvent e),
D.addMouseMotionListener(this),mouseClicked(MouseEvent e),
mouseEntered(MouseEvent e),
ANS:-addMouseMotionListener(this),mouseMoved(MouseEvent e),
mouseDragged(MouseEvent e), option C.
}
else if (str.equals("Blue"))
{
setBackground(Color.blue);
}
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg,0,100);
}
}
}
else if (str.equals("Blue"))
{
setBackground(Color.blue);
}
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg,0,100);
}
}
/*<applet code="ButtonDemo1.class" width=200 height=400>
</applet>*/Ç ‹
• Find the missing statement in the program.
/*
<APPLET Code="InnerClassDemo" Width=200 Height=250>
</APPLET>
*/
public class InnerClassDemo extends Applet
{
public void init()
{
addMouseListener(new MyMouseAdapter());
}
class MyMouseAdapter extends MouseAdapter
{
public void mousePressed(MouseEvent me)
{
showStatus("Mouse Pressed")
}
}
}
}
A.Missing semicolon
B.Missing }
C.Missing {
D.Missing package statement
ANS:-Missing semicolon option A.
289.Analyse the following code and fill the appropriate statement in ___________________.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*<applet code="Login" width=200 height=200></applet>*/
public class Login extends Applet implements ActionListener
{
TextField nm,pwd;
Label nml,pwdl;
Button login;
String msg="";
public void init()
{
nml=new Label("Name:", Label.LEFT);
pwdl=new Label("Password:",Label.RIGHT);
nm=new TextField(12);
pwd=new TextField(12);
pwd.setEchoChar('*');
login=new Button("LOGIN");
add(nml);
add(nm);
add(pwdl);
add(pwd);
add(login);
login.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String str=_____________________
if(str.equals("LOGIN"))
{
String n=nm.getText();
String p=pwd.getText();
if(n.equals("MUMBAI")&&p.equals("Mumbai"))
msg="Login Successful";
else
msg="Incorrect User Name and Password";
}
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg,150,150);
}
}
A.ae.getActionCommand();
B.ae.getSource();
C.ae.getCommand();
D.ae.getActionSource();
ANS:-ae.getActionCommand(); option A.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
}
}
A.It wiil display the message in applet window.
B.It will display an exception.
C.It wiil display the message in status bar.
D.It wiil display the message in title bar.
ANS:-It wiil display the message in status bar. option C.
292.For the following code select the listener that can be used to handle events.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
}
A.MouseListener
B.MouseMotionListener
C.WindowListener
D.KeyListener
ANS:-MouseMotionListener option B.
293.For the following code select the method that can be used to handle event.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
/*<applet code="simple"
width=300 height=100>-
</applet>*/
public class simple 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 _________________(KeyEvent ke)
{
showStatus("Key Up");
}
public void keyTyped(KeyEvent ke)
{
msg+=ke.getKeyChar();
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg,x,y);
}
}
A.keyReleased(KeyEvent ke)
B.itemStateChanged(ActionEvent ie)
C.itemStateChanged(ItemEvent ie)
D.adjustmentPerformed(AdjustmentEvent ae)
ANS:-keyReleased(KeyEvent ke) option A.
294.Which of these methods will respond when you click any button by mouse?
A.mouseClicked()
B.mouseEntered()
C.mousePressed()
D.all of the mentioned
ANS:-all of the mentioned option D.
295.Identify the listener which is needed to be implemented and registered for executing the below
program.
/*<applet code="MyKey1" width=300 height=300></applet>*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class MyKey1 extends Applet implements _________________
{
String msg;
public void init()
{
add_____________(this);
msg=" ";
requestFocus();
}
public void keyTyped(KeyEvent ke)
{
msg="Key Typed";
repaint();
}
public void keyPressed(KeyEvent ke)
{
msg="Key Pressed";
repaint();
}
public void keyReleased(KeyEvent ke)
{
msg="Key Released";
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg,20,30);
}
}
A.ClickListener
B.KeyListener
C.MouseListener
D.ActionListener
ANS:-KeyListener option B.
297.Which of these following statement is true in case interfaces handles the event when a component
is added to a container?
a)The ContainerListener defines methods to recognize when a component is added to or removed from a
container.
b)The ComponentListener defines methods to recognize when a component is added to or removed from
a container.
c)The FocusListener defines methods to recognize when a component is added to or removed from a
container.
d)The InputListener defines methods to recognize when a component is added to or removed from a
container.
A.a
B.b
C.c
D.d
ANS:-a option A.
C.An event is an object that describes any change by the user and system
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
jc.addItem("Yahoo mail");
jc.addItem("gmail");
jc.addItemListener(this);
cp.add(jc);
yahoo=new ImageIcon("Hydrangeas1.jpg");
jl=new JLabel(yahoo);
cp.add(jl);
}
B.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
JLabel jl;
ImageIcon yahoo;
jc.addItemListener(this);
cp.add(jc);
yahoo=new ImageIcon("Hydrangeas1.jpg");
jl=new JLabel(yahoo);
cp.add(jl);
}
C.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
JLabel jl;
ImageIcon yahoo;
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
jc.addItem("Yahoo mail");
jc.addItem("gmail");
jc.addItemListener(this);
cp.add(jc);
yahoo=new ImageIcon("Hydrangeas1.jpg");
jl=new JLabel(yahoo);
cp.add(jl);
}
D.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
JLabel jl;
ImageIcon yahoo;
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
jc.addItem("Yahoo mail");
jc.addItem("gmail");
jc.addItemListener(this);
cp.add(jc);
yahoo=new ImageIcon("Hydrangeas1.jpg");
cp.add(jl);
}
JLabel jl;
ImageIcon yahoo;
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
jc.addItem(&quot;Yahoo mail&quot;);
jc.addItem(&quot;gmail&quot;);
jc.addItemListener(this);
cp.add(jc);
yahoo=new ImageIcon(&quot;Hydrangeas1.jpg&quot;);
jl=new JLabel(yahoo);
cp.add(jl);
}
A.actionListener
B.iteminterface
C.itemStateChanged
D.ItemListener
ANS:-ItemListener option D.
import java.net.*;
public class MyNetwork
{
public static void main(String args[]) throws UnknownHostException
{
InetAddress ip [] = InetAddress.getAllByName("www.google.com");
for(int i=0;i<ip.length;i++)
{
System.out.println(ip[i].getHostAddress());
}
}
}
A.IP address of www.google.com
B.All IP addresses of www.google.com
C.All internet protocols of www.google.com
D.All of the mentioned
ANS:-All IP addresses of www.google.com option B.
A.Socket s=ss.accept();
B.ss.accept();
C.Socket s; s.accept()
D.Socket s=accept();
ANS:-Socket s=ss.accept(); option A.
303.what is the out of following code if Host URL was last modified on july 18 tuesday 2013 .
import java.net.*;
class networking {
public static void main(String[] args) throws Exception {
URL obj = new URL("http://www.sanfoundry.com/javamcq");
URLConnection obj1 = obj.openConnection();
System.out.print(obj1.getLastModified);
}
}
A.july
B.18-6-2013
C.Tue 18 Jun 2013
D.Tue Jun 18 2013
ANS:-Tue Jun 18 2013 option D.
305.The abstract class ---------------- is the super class of all classes that represent a communication link
between application and url.
A.URL
B.ServerSocket
C.Socket
D.None of this
ANS:-ServerSocket option B.
306.What is output of following code: import java.io.*;
import java.net.*;
public class portscanner
{
public static void main(String args[])
{
String host=”localhost”;
for(int i=0;i<1024;i++)
{
try{
Socket s= new Socket(host,i);
System.out.println(“There is server on port” +i+ ”of” +host);
}
catch(UnknownHostexception ex)
Break;
}
catch(IOException e){}
}
}
}
A. There is server on port 21 of local host
B.There is server on port 80 of local host
C.There is server on port 110 of local host
D.There is server on port
ANS:-There is server on port 110 of local host option C.
import java.net.*;
class sample
{
public static void main(String[] args) throws Exception
{
URL obj = new URL("http://www.msbte.com");
URLConnection obj1 = obj.openConnection();
int len = obj1.getContentLength();
System.out.print(len);
}
}
A.C:\jdk1.2.2\bin>javac sample.java
C.C:\jdk1.2.2\bin>javac Demo.java
sample.java
D.C:\jdk1.2.2\bin>java sample.java
A.i.getHostName() i.getHostAddress()
B.i.getName()i.getAddress()
C.All of the above
D.None of the above
ANS:-i.getHostName()i.getHostAddress() option A.
import java.net.*;
public class DemoInetAddress
{
public static void main(String args[]) _____________
{
InetAddress address;
String hostName, hostAddrs;
address =InetAddress.getByName("Comp12");
hostName=address.getHostName();
hostAddrs=address.getHostAddress ();
System.out.println("HostName: "+hostName);
System.out.println("HostAddress: "+hostAddrs);
}
}
A.throws IOException
B.throws MalformedURLException
C.throws UnknownFileException
D.None of these
ANS:-None of these option D.
313.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:SName");
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.
ANS:-Missing () option B.
315.Consider the following program.What should be the correction done in the program to get correct
output?
import java.sql.*;
public class UpdatePre
{
public static void main(String args[])
{
Connection con = null;
PreparedStatement pst = null;
ResultSet rs = null;
try
{
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc:odbc:xyz";
Class.forName(driver);
con = DriverManager.getConnection(url);
pst = con.prepareStatement("update Account set Ammount=5000 where Acc_No =12");
pst.executeUpdate();
pst = con.prepareStatement("select * from Account");
rs = pst.executeQuery();
System.out.println("Acc_No\tAcc_Type\tAmmount");
while (rs.next())
{
System.out.print(rs.getInt(1) + "\t");
System.out.print(rs.getString(2) + "\t ");
System.out.println(rs.getInt(3));
}
rs.close();
pst.close();
con.close();
catch (Exception e)
{
System.out.println(e);
}
}
}
A.Missing semicolon
B.Missing {
C.Missing }
D.Missing connection statement
ANS:-Missing } option C.
B.This static method is used in case you are using a non-JDK compliant JVM, such as the one provided by
Microsoft.
while(rs.next())
{
System.out.println("id:"+rs.getInt("id"))
System.out.println("name1:"+rs.getString("name1"));
}
con.close();
}
catch(SQLException e)
{}
catch(Exception e)
{
}
}}
A.; missing
B.Error in while loop
C.both a and b
D.Error in catch()
ANS:- ; missing option A.
319.To delete the records from database, use the following sequence of the part of coding.
A.String b = "delete from emp where ID=1";
PreparedStatement ps=con.prepareStatement(b);
ps.executeUpdate();
320.Find Errors
import java.sql.*;
class Test{
public static void main(String ar[])throws Exception
{
String url="jdbc:odbc:st";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Drivers Loaded");
Connection c=DriverManager.getConnection();
}
}
A.no url is passed for getConnection method
B.Connection object is created
C.url is displayed
D.No error
ANS:-no url is passed for getConnection method option A.
import java.sql.*;
public class JdbcDemo
{
public static void main (String args[]) throws Exception
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mydsn");
PreparedStatement ps=con.PrepareStatement("insert into employee
values(200,'amol')");
int i=ps.executeUpdate();
if(i==1)
System.out.println("row inserted");
else
System.out.println("operation failed");
ps.close();
con.close();
}
catch(Exception e)
{}
}
}
A.PreparedStatement ps=con.prepareStatement("insert into employee values(?,?)");
ps.setInt(1,200);
ps.setString(2,"amol");
ANS:-option A.
324.Find the missing statement from which the output will be displayed as connection established.
import java.sql.*;
class conn
{
public static void main(String h[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver are properly loaded");
String url="jdbc:odbc:abc";
Connection con;
System.out.println("connection established");
}
catch(SQLException e)
{
System.out.println("Sql error has occured");
}
catch(Exception e)
{
System.out.println("error!connection not establishd");
}
}
}
A.con=DriverManager.getConnection();
B.con=DriverManager.getConnection(url);
C.con=DriverManager.getConnection(con);
D.con=DriverManager.getConnection(sql);
ANS:-con=DriverManager.getConnection(url); option B.
class datadd
{
public static void main(String a[])
{
try
{
Driver d= new sun.jdbc.odbc.JdbcOdbcDriver();
DriverManager.registerDriver(d);
Connection con =DriverManager.getConnection("Jdbc:Odbc:xxx");
Statement s=con.createStatement();
ResultSet rs=s.executeQuery("Select * from Table1 ")
while(rs.next())
{
String n=rs.getString("name");
System.out.println("name:"+n);
String n1=rs.getString("rollnu");
System.out.println("rollnumber:"+n1);
}
con.close();
}
catch(Exception e)
{
System.out.println("not Deleted"+e);
}
}
A.Missing semicolon and }
B.Only Missing {
C.OnlyMissing }
D.Missing statement
ANS:-Missing semicolon and } option A.
327.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())
26
{
System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t \t"+rs.getDouble(3));
}
s.close();
c.close();
}
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.
ANS:-Missing package statement. option D.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver Loaded");
String URL = "jdbc:odbc:StudentDatabase";
A.DriverManager.getConnection()
B.Main
C.Class.for()
D.Connection String
ANS:-DriverManager.getConnection() option A.
int records = 0;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:DATA");
String sql = "SELECT COUNT(*) FROM User" ;
PreparedStatement prest = con.prepareStatement(sql);
ResultSet rs = prest.executeQuery();
while (rs.next())
{
records = rs.getInt(1);
}
System.out.println("Number of records: " + records);
con.close();
}
}
A.Output display all record from table.
B.Output display specific row from the table
C.Output display number of row from table.
D.Both I and ii
ANS:-Output display number of row from table. option C.
A.Devicemanager.getConnection(url);
B.DriverManager.getConnection(url);
C.DriverManager.getconnection(URL);
D.DriversManagers.getConnections(url);
ANS:-DriverManager.getConnection(url); option B.
333.Write a java code to access id, age, first from table given below
Employees : l id l first l last l age l
A. sql = "SELECT id, age, first FROM Employees"; ResultSet rs = stmt. executeQuery (sql);
while (rs.next()) { int id = rs. getInt("id"); int age = rs. getInt ("age"); String first=
rs.getString ("first");
D.sql = "SELECT id, First, age FROM Emp "; ResultSet rs = stmt. executeQuery (sql); while
(rs.next()) { int id = rs. getInt("id"); int age = rs. getInt ("age"); String first=
rs.getstring ("first"); String last = rs.getstring ("last")
ANS:-A. sql = &quot;SELECT id, age, first FROM Employees&quot;; ResultSet rs = stmt.
executeQuery (sql); while (rs.next()) { int id = rs. getInt(&quot;id&quot;); int age = rs. getInt
(&quot;age&quot;); String first= rs.getString (&quot;first&quot;); option A.
335.Which code is correct from the following options to make use of PreparedStatement.
A.
import java.sql.*;
import java.io.*;
public class DBDemo
{
public static void main(String []args)throws Exception
{
String sql;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:stud";
Connection con=DriverManger.getConnection(url);
PreparedStatement st;
sql="select * from stud_table where name=*";
st=con.prepareStatement(sql);
st.setInt(1,2);
st.setString(2,'ganesh');
st.setString(3,'pune');
ResultSet rs=st.executeQuery();
st.close();
}
}
B.
import java.sql.*;
import java.io.*;
public class DBDemo
{
public static void main(String []args)throws Exception
{
String sql;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:stud";
Connection con=DriverManger.getConnection(url);
PreparedStatement st;
sql="select * from stud_table where name=?";
st=con.collableStatement(sql);
st.setInt(1,2);
st.setString(2,'ganesh');
st.setString(3,'pune');
ResultSet rs=st.executeQuery();
st.close();
}
}
C.
import java.sql.*;
import java.io.*;
public class DBDemo
{
public static void main(String []args)throws Exception
{
String sql;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:stud";
Connection con=DriverManger.getConnection(url);
PreparedStatement st;
sql="select * from stud_table where name=?";
st=con.createStatement(sql);
st.setInt(1,2);
st.setString(2,'ganesh');
st.setString(3,'pune');
ResultSet rs=st.executeQuery();
st.close();
}
}
D.
import java.sql.*;
import java.io.*;
public class DBDemo
{
public static void main(String []args)throws Exception
{
String sql;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:stud";
Connection con=DriverManger.getConnection(url);
PreparedStatement st;
sql="select * from stud_table where name=?";
st=con.prepareStatement(sql);
st.setInt(1,2);
st.setString(2,'ganesh');
st.setString(3,'pune');
ResultSet rs=st.executeQuery();
st.close();
}
}
ANS:-
import java.sql.*;
import java.io.*;
public class DBDemo
{
public static void main(String []args)throws Exception
{
String sql;
Class.forName(&quot;sun.jdbc.odbc.JdbcOdbcDriver&quot;);
String url=&quot;jdbc:odbc:stud&quot;;
Connection con=DriverManger.getConnection(url);
PreparedStatement st;
sql=&quot;select * from stud_table where name=?&quot;;
st=con.prepareStatement(sql);
st.setInt(1,2);
st.setString(2,'ganesh');
st.setString(3,'pune');
ResultSet rs=st.executeQuery();
st.close();
}
} option D.
}
}
A.Missing semicolon
B.missing package
C.mssing statement interface
D.All above
ANS:-mssing statement interface option C.
337.Consider following code and state which statement is missing in following code :
import java.sql.*;
class JDBCDEMO
{
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:ODSN"," ","
");
}
catch(ClassNotFoundException ce){System.out.println("1");}
catch(SQLException se){}
}
}
A.error in main()
B.error in getConnection() method
C.error in createStatement() and semicolon missing
D.error in executeQuery()
ANS:-error in createStatement() and semicolon missing option C.
b) TYPE_SCROLL_INSENSITIVE : a scrollable result set does not reflects changes that are made to it while it
is open
c) TYPE_SCROLL_SENSITIVE: a scrollable result set reflects changes that are made to it while it is open
d) none of these.
A.a,b,c
B.a only
C.b only
D.d
ANS:-a,b,c option A.
B.The statement displays all students taking the Java Programming course.
C.The statement displays all students taking the Java Programming course with last name starting with S.
D.The statement displays all students taking the Java Programming course with letter S in the last name.
ANS:-The statement displays all students taking the Java Programming course with last name starting with
S. option C.
343.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 = new Cookie("My Cookie",data);
response.*********;
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<B>MyCookie has been set to");
pw.println(data);
pw.close();
}
}
A.addFile(cookie);
B.addSeesion(cookie);
C.addAttribute(cookie);
D.addCookie(cookie);
ANS:-addCookie(cookie); option D.
C.Compilation Error
D.None of Above
345.What we should write at the place of____________ to get the proper output.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class password extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)throws IOException,
ServletException
{
response.setContentType("text/html");
PrintWriter out = ________________
out.println("<html>");
out.println("<head>");
out.println("<title>Hello World!</title>");
out.println("</head>");
out.println("<body>");
String a= request.getParameter("t1");
String b= request.getParameter("t2");
int a1 =a.length();
int b1= b.length();
if(b.length()<=6)
{
out.println("<h3> Welcome To Home Page<h3>");
}
else
{
out.println("<h3>Password Should not more than 6 Character<h3>");
}
out.println("</body>");
out.println("</html>");
}
}
A.request.getWriter();
B.response.getWriter();
C.response.printWriter();
D.none of the above
ANS:-response.getWriter(); option B.
pw.println("</html>");
}
}
C.Nothing is missing.
ANS:-option A.
350.In following Java program fill statement showing ***.Select any one option fro given options
import java.io.*;
importjavax.servlet.*;
importjavax.servlet.http.*;
public class p172 extends HttpServlet{
public void doPost(HttpServletRequestrequest,HttpServletResponse response)
throwsServletException,IOException
{
PrintWriter z;
z=new PrintWriter(response.getOutputStream());
String x=request.getParameter("data");
String y=request.getParameter("data");
String a=request.getParameter("data");
String b=request.getParameter("data");
Cookie c=new Cookie("MyCookie",x);
response.addCookie(c);
*******
z.println("<b>mycookie has been set to");
z.println(x);
z.close();
}
}
A.response.setContentType("text/html");
B.response.ContentType("text/html");
C.request.setContentType("text/html");
D.response.getContentType("text/html");
ANS:-response.setContentType(&quot;text/html&quot;); option A.
out.print("<html><body>");
out.print("<b>hello simple servlet</b>");
out.print("</body></html>");
}
public void destroy(){System.out.println("servlet is destroyed");}
public ServletConfig getServletConfig(){return config;}
public String getServletInfo(){return "copyright 2007-1010";}
}
A.PrintWriter out=res.getWriter();
B.PrintWriter out=req.getWriter();
C.PrintWriter out=res.getReader();
D.PrintWriter out=req.getReader();
ANS:-PrintWriter out=res.getWriter(); option A.
352.Which of the following are correct statements? Select the two correct answers.
A. The getRequestDispatcher method of ServletContext class takes the full path of the servlet, whereas
the getRequestDispatcher method of HttpServletRequest class takes the path of the servlet relative to the
ServletContext.
B. The include method defined in the RequestDispatcher class can be used to access one servlet from
another. But it can be invoked only if no output has been sent to the server.
D. The getNamedDispatcher(String) defined in HttpServletRequest class takes the name of the servlet and
returns an object of RequestDispatcher class.
A.A and B
B.B and C
C.A and C
D.B and D
ANS:-A and C option C.
353.To calculate square root of 25, fill the correct option in the ********* in the following JSP code
<html>
<head><title>Hello World</title></head>
<body>
The square root of 25 is ************
</body>
</html>
A.<html>
<head><title>Hello World</title></head>
<body>
Hello World!<br/>
B.</body>
</html>
<head><title>Hello World</title></head>
<body>
Hello World!<br/>
<%
out.println("Your IP address is " + request.getAddress());
%>
C.</body>
</html>
<head><title>Hello World</title></head>
<body>
Hello World!<br/>
<%
out.println("Your IP address is " + request.getRemoteAddr());
%>
D.</body>
</html>
<head><title>Hello World</title></head>
<body>
Hello World!<br/>
<%
System.out.println("Your IP address is " + request.getRemoteAddr());
%>
ANS:-</body>
</html>
&lt;head&gt;&lt;title&gt;Hello World&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;
Hello World!&lt;br/&gt;
&lt;%
out.println(&quot;Your IP address is &quot; + request.getRemoteAddr());
%&gt;
&lt;/body&gt;
&lt;/html&gt; option C.
357.________ are JSP code fragments embedded within <% ...%> tags.
A.Scriptlets
B.Applets
C.Japplets
D.none of the above
ANS:-Scriptlets option A.
361.Consider following code of servlet and find out missing method in the program
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
362.following servlet read parameters passed through the html page. Write the correct HTML code for
given servlet.
import jba. Io.*;
import java.util.&;
import javax.servlet.*;
public class Example2servlet extends Generic servlet {
public viod serice request reg, ServletResponse res) throws ServletException, IOException {
PrintWriter pw = res.getWriter();
Enumeration E= reg.get PaarameterNames();
while ( e. has More Elecment()) {
strignpaname =(string)e.nextElecment(); pw.printin(pname+="");
String pvalue = req.getParameter(pname);
pw . printIn (pvalue); } pw. close();
}
}
<html> <head> <title><title> <meta htt-equiv="Content-type"
content ="text/html; charset= UTF-8"> </head> <body> <form name =
"forml" method ="post" action =
http://localhost:8080/WebApplication1/Example2Servlet> <table>
_____________________________________ ___________________________________
______________________________</table> <input type = "subit" value =
"submit" > </body> </html>
A. <tr> <td> Employee : </td> <td><input name ="employee' size
"25" value = "" ></td> </tr>
363.Find out the missing statement to get the correct output in bellow program
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class SessionTracking extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter w=res.getWriter();
Integer count=(Integer)ss.getAttribute("tracker.count");
if(count==null)
{
count=new Integer(1);
}
else
count=new Integer(count.intValue()+1);
ss.setAttribute("tracker.count",count);
w.println("<h1>Sessiontracking Demo</h1>");
w.println("You have visited this page"+count+"times");
w.println("here is session data");
Enumeration enu=ss.getAttributeNames();
while(enu.hasMoreElements())
{
String name=(String)enu.nextElement();
w.println(name+" "+ss.getAttribute(name));
}
}
}
A.HttpSession ss=req.getSession();
B.HttpSession ss=res.getSession();
C.HttpSession ss=req.getCookie();
D.HttpSession ss=res.getCookie();
ANS:-HttpSession ss=req.getSession(); option A.
A.request.getParameter("cookieName");
B.response.setContentType("cookieName");
C.request.getParameter(cookies);
D.response.getWriter();
ANS:-request.getParameter(&quot;cookieName&quot;); option A.
368.Which of the following depicts correct order of phases in JSP life cycle?
A.Compilation, Initialization, Execution, Cleanup
B.Initialization, Compilation, Cleanup, Execution
C.Initialization, Cleanup, Compilation, Execution
D.Cleanup, Compilation, Initialization, Execution
ANS:-Compilation, Initialization, Execution, Cleanup option A.
369.What is the missing statement in the following program to get the proper output
import java.io.*;
import java.util.*;
public class HelloWorld extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
HttpSession hp=request.getSession(true);
Date create=new Date(hp.getCreationTime());
Date access=new Date(hp.getLastAccessedTime());
out.println("<h1><br>Session is created at "+create);
out.println("<h1><br>Last access time is "+access);
out.println("<h1><br>Session id is "+hp.getId());
}
}
A.Missing semicolon
B.missing {}
C.missing Package statement
D.none of the above
ANS:-missing Package statement option C.
371.In following Java program fill statement showing *** . Select any one option from given options
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class DateServlet extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException{
HttpSession hs = *****************
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);
pw.println(“Current date:”+date);
}
}
A.request.getSession(true);
B.response.getSession(true)
C.request.getSession(false)
D.response.getSession(false)
ANS:-request.getSession(true); option A.
</form>
</body>
</html>
//servlet
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class sd1 extends HttpServlet
{
public void service(HttpServletRequest rq,HttpServletResponse rs)throws ServletException,IOException
{
rs.setContentType("text/html");
PrintWriter out=rs.getWriter();
String nm=(String)rq.getParameter("name1");
out.println("Hello "+nm);
}
}
A.Hello name1
B.Hello name inputed in text box
C.hello
D.None of above
ANS:-Hello name inputed in text box option B.