Sie sind auf Seite 1von 136

1.Model is the _________ of the MVC architecture.

A.middle level
B.top most level
C.bottom most level
D.none of these
ANS:-bottom most level option C.

2.Which method is used to change the name of a menu item


A.String getLabel()
B.void setLabel(String newName)
C.boolean isEnabled()
D.none of the above
ANS:-void setLabel(String newName) option B.

3.getContentPane() method of which class.


A.JApplet
B.JFrame
C.JButton
D.None of this
ANS:-JApplet option A.

4.JTabbedPane class is present in which package?


A.java.awt
B.java.awt.event
C.javax.swing
D.javax.swing.table
ANS:-javax.swing Option C.

5.How many checkboxes we can check at a time.


A.1
B.2
C.3
D.multiple
ANS:-multiple option D.

6.Frame is a standard window,which is _______of Window class from AWT hierarchy.


A.sub class
B.main class
C.parent class
D.super class
ANS:-sub class option A.

7.Which is/are the methods used in AbstractButton class.


A.void setDisabledIcon(Icon di)
B.void setPressedIcon(Icon pi)
C.void setRolloverIcon(Icon ri)
D.all of the above
ANS:-all of the above option D.
8.Which constructor creates a TextArea with 10 rows and 20 columns?
A.new TextArea(10, 20)
B.new TextArea(20, 10)
C.new TextArea(new Rows(10), new columns(20))
D.new TextArea(200)
ANS:-new TextArea(10, 20) option A.

9.Which of the following is not a swing class?


A.JApplet
B.JButton
C.Canvas
D.JLabel
ANS:-Canvas option C.

10.The method _____creates a IconImage for file c:\image\us.gif.


A.new ImageIcon("c:\image\us.gif");
B.new Icon("c:\image\us.gif");
C.new ImageIcon("c:\\image\\us.gif");
D.new Icon("c:\\image\\us.gif");
ANS:-new ImageIcon("c:\image\us.gif")option A.

11.Which is Controll in swing a combination of a text field and a dropdown list.


A.Table
B.ToolTip
C.JComboBox
D.JScrollPane
ANS:-JComboBox option C.

12.Default layout manager for Window is.


A.GridLayout
B.CardLayout
C.GridBaglayout
D.Borderlayout
ANS:-Borderlayout option D.

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.

14.getSelectedCheckbox() mehod of which class.


A.CheckboxGroup
B.Checkbox
C.Choice
D.List
ANS:-CheckboxGroup Option A.

15.The default layout manager of Frame is ______.


A.GridLayout
B.CardLayout
C.GridBaglayout
D.Borderlayout
ANS:-Borderlayout option D.

16.Which class is on the top of the AWT event hierarchy? A.java.awt.AWTEvent


B.java.awt.Event
C.java.util.eventObject
D.javax.swing.Object
ANS:-java.awt.AWTEvent option A.

17.In AWT Radio buttons are created using_______________.


A.CheckBox
B.RadioButton
C.List
D.CheckBoxGroup
ANS:-CheckBoxGroup option D.

18._________ method is used to add the menubar on frame window.


A.add()
B.setMenubar()
C.setMenuBar()
D.addMenuBar( )
ANS:-setMenuBar() option C.

19.Which method is used to check the status of checkbox


A.setState()
B.getState()
C.setLabel()
D.getLabel()
ANS:-getState() 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.

21.________ arranges the component in rows and column.


A.BorderLayout
B.FlowLayout
C.GridLayout
D.CardLayout
ANS:-GridLayout option C.

22.Which is the class responsible for handling key press activity.


A.EventObject
B.ActionEvent
C.ObjectEvent
D.KeyEvent
ANS:-KeyEvent option D.

23.Event Class library is define in following package.


A.Java .io
B.java.util
C.java.awt
D.java .net
ANS:-java.util option B.

24.The general form to set a specific type of layout manager is.


A.Void setLayout(Layoutmanager lm)
B.void setLayout(layoutManager lm)
C.Void setLayout(LayoutManager lm)
D.void setLayout(LayoutManager lm)
ANS:-void setLayout(LayoutManager lm) option D.

25.To fetch caption of button___________ method is used.


A.getText( )
B.getCaption( )
C.getLabel( )
D.None of these
ANS:-getLabel( ) option C.

26.To create a multiline ediitable control ________ class is used.


A.TextField
B.TextArea
C.Choice
D.Button
ANS:-TextArea 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.

30.____________ class is used to create radio button in AWT.


A.RadioButton
B.Button
C.CheckboxGroup
D.Chechbox
ANS:-CheckboxGroup option C.

31. ________method returns the string of item which is currently selected.


A.getSelectedItem ( )
B.getsSelectedIndex ( )
C.select( int index)
D.getItem (int index)
ANS:-getSelectedItem ( ) option A.

32.To make the group of radio button______________ is used.


A.ButtonGroup
B.GroupButton
C.GroupModel
D.None of these
ANS:-ButtonGroup option A.

33.By default the Frame has a _________________.


A.Panel,Radiobutton,button.
B.Menubar,,borders.
C.Titlebar,borders,resizing corners
D.Resizing corners,borders,checkbox
ANS:-Titlebar,borders,resizing corners option C.

34.You an determine which check box is currently selected by calling _________method.


A.getSelectedCheckbox()
B.getSelectedcheckBox()
C.getSelectedCheckboxIndex()
D.getCheckBox()
ANS:-getSelectedCheckbox() option A.

35.Which abstract class is super class of menu related classes? A.MenuBar


B.MenuItem
C.MenuComponent
D.CheckboxMenuItem
ANS:-MenuComponent option C.

36.______ class used to create node in tree.


A.MutableTreeNode
B.TreeNode
C.DefaultMutableTreeNode
D.Node
ANS:-DefaultMutableTreeNode option C.

37.What 'C' specifies in MVC architecture?


A.Counting
B.Checking
C.Control
D.cache
ANS:-Control option C.

38.Which is immediate super class for TextField?


A.TextArea
B.TextComponent
C.JComponent
D.Container
ANS:-TextComponent option B.

39.Which of the following is the constructor of JLabel.


A.JLabel( )
B.JLabel (String str,ImageIcon i)
C.JLabel(String str)
D.All of the above
ANS:-All of the above option D.

40.Following is true about List class.


A.It is a multiple-choice scrolling list.
B.Only one item can be selected from the list.
C.It can show multiple selected items in the visible window.
D.All of these
ANS:-It is a multiple-choice scrolling list. option A.

41.Which h costructor creates a TextArea with 10 rows and 20 columns ?


A.new TextArea(new Rows(10),new columns(20)).
B.new TextArea(20 , 10 )
C.new TextArea(10 , 20 )
D.new TextArea(200 )
ANS:-new TextArea(10 , 20) option C.

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.

43.Which package use for import the swing components?


A.import java.swing.*;
B.import javax.swing.*;
C.import java.awt.swing.*;
D.None of these
ANS:-import javax.swing.*; option B.

44.The default orientation of JProgressBar is ___________.


A.Horizontal
B.Vertical
C.Both A and B
D.None of the above
ANS:-Horizontal option A.

45.Which of the following may a menu contain?


A.check box
B.menu
C.button
D.panel
ANS:-menu 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.

47.Which method is method to set the layout of a container?


A.startLayout( )
B.initLayout( )
C.layoutContainer( )
D.setLayout( )
ANS:-setLayout( ) option D.

48.You can construct a JTabbedPane using ____________.


A.new JTabbedPane()
B.new JTabbedPane(Component)
C.new JTabbedPane(Component[])
D.new JTabbedPane(Component, Component)
ANS:-new JTabbedPane() option A.
49.Which Listener handles all List related Events.
A.MouseListener
B.ItemListener
C.FocusListener
D.ButtonListener
ANS:-ItemListener option B.

50.Event is called as ______________ .


A.Change in the state of object.
B.Change in the state of Component
C.Change in the state of Textbox
D.Change in the state of Button
ANS:-Change in the state of object. option A.

51.What is a listener in context to event handling?


A.A listener is a variable that is notified when an event occurs.
B.A listener is a object that is notified when an event occurs.
C. A listener is a method that is notified when an event occurs.
D. None of the mentioned .
ANS:-A listener is a object that is notified when an event occurs. option B.

52.Some of the event listener interfaces are_____________.


A.ActionListener, ComponentListener
B.ItemListener, KeyListener
C.WindowListener, MouseListener
D.All of these
ANS:-All of these option D.

53.Which of these interfaces define a method actionperformed()?


A.ComponentListener
B.ContainerListener
C.ActionListener
D.InputListener
ANS:-ActionListener option C.

54.Which of these interfaces define a method itemStateChanged()?


A.ComponentListener
B.ContentListener
C.ActionListener
D.ItemListener
ANS:-ItemListener option D.

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.

56.What is an event in delegation event model used by Java programming language?


A.An event is an object that describes a state change in a source.

B.An event is an object that describes a state change in processing.

C.An event is an object that describes any change by the user and system.

D.An event is a class used for defining object, to create events.

ANS:-An event is an object that describes a state change in a source. option A.

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.

59.FocusEvent is subclass of which of these calsses ?


A.ComponenEvent
B.ContainerEvent
C.ItemEvent
D.InputEvent
ANS:-ComponenEvent option A.

60.ComponenetEvent is the superclass of _______________.


A.FocusEvent
B.MouseEvent
C.WindowEvent
D.All of the above
ANS:-All of the above option D.

61.The ________ interface is used to handle button events.


A.ContainerListener
B.ItemListener
C.ActionListener
D.WindowListener
ANS:-ActionListener option C.

62.TextEvent defines the integer constant__________________.


A.TEXT_VALUE_CHANGED
B.TEXT_CHANGED_VALUE
C.text_value_changed
D.text_changed_value
ANS:-TEXT_VALUE_CHANGED option A.

63.Focus events are fired whenever a component _____________________the focus.


A.gains or loses
B.ideal
C.gains
D.loses
ANS:-gains or loses option A.

64.How to obtain the command name for invoking ActionEvent?


A.Using getActionCommand( )
B.Using getCommand( ) method.
C.Using getAction( ) method.
D.Using obtainAction( ) method.
ANS:-Using getActionCommand( ) method. option A.

65.Interface used to handle menu events is ___.


A.ContainerListner
B.ActionListner
C.FocusListner
D.WindowListner
ANS:-ActionListner option B.

66.Which of these is superclass of all Adapter classes?


A.Applet
B.ComponenetEvent
C.Event
D.InputEvent
ANS:-Applet 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.

70.Method of ActionListener Interface which need to overide.


A.actionPerformed()
B.itemStateChanged()
C.AdjustmentValueChanged()
D.None of Above
ANS:-actionPerformed() 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.

72.The KeyEvent class does not defines the _____________integer constant.


A.KEY_PRESSED
B.KEY_ENTERED
C.KEY_RELEASED
D.KEY_TYPED
ANS:-KEY_ENTERED 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.

79.The ______________class is used to create TCP server.


A.Socket
B.ServerSocket
C.Socket Server
D.None Of Above.
ANS:-ServerSocket option B.

80.Port number of Telnet is…...


A.21
B.23
C.25
D.79
ANS:-23 option B.
81.InetAddress class has no visible constructors.
A.TRUE
B.FALSE
ANS:-True option A.

82._______ class is used to create client in TCP/IP.


A.Socket
B.SocketPacket
C.ServerSocket
D.portSocket
ANS:-Socket option A.

83.UDP Packets are known as ___________________.


A.Data Packets
B.PDU
C.Datagram
D.Package
ANS:-Datagram option C.

84.Port number for HTTP is ______.


A.1024
B.2048
C.80
D.119
ANS:-80 option C.

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.

86.Port number of Email is ____________.


A.25
B.79
C.21
D.23
ANS:-25 option A.

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.

88.URLConnection, Socket, InetAddress are part of which package.


A.java.net
B.javax.net
C.java.network
D.java.socket
ANS:-java.net option A.

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.

92.Which socket class can send packets unreliably?


A.java.net.DatagramSocket()
B.java.net.URL()
C.java.net.Socket()
D.java.net.UDPSocket()
ANS:-java.net.DatagramSocket() option A.

93.3 byte[] getData() method is defined by _____ class.


A.Datagram
B.Socket
C.ServerSocket
D.DatagramPacket
ANS:-DatagramPacket option D.

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.

97.What is use of PreparedStatement interface?


A.Excecute dynamic SQL statements
B.Excecute static SQL statements
C.Excecute dynamic as well as static SQL statements
D.Excecute dynamic statements
ANS:-Excecute dynamic SQL statements option A.

98.Which of following method is used to create object of PreparedStatement interface.


A.preparedStatement()
B.prepareCall()
C.prepareStatement()
D.None of these
ANS:-prepareStatement() option C.

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.

100.Which of the following is interfaces?


A.Connection
B.Statement
C.ResultSet
D.DriverManager
ANS:-Statement 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.

103.Which interface gives the flexibility of supplying arguments dynamically?


A.Statement
B.PreparedStatement
C.CallableStatement
D.All of the mentioned
ANS:-PreparedStatement option B.

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.

105.prepareStatement method is from which class.


A.PreparedStatement class
B.PrepareStatement class
C.Connection Class
D.Statement Class
ANS:-Connection Class option C.

106.Which type of driver is unqiue in JDBC?


A.JDBC-ODBC bridge driver
B.JDBC-Native API
C.JDBC- Net Pure Java
D.100% Pure Java
ANS:-JDBC-Native API option B.

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.

109.Which method is used for an SQL statement that is executed frequently?


To execute sql statement whih methods are is used?
A.execute()
B.executeQuery()
C.executeUpdate()
D.All of the above
ANS:-All of the above option D.

110.Native API converts _______into the ________ used by DBMS.


A.JDBC API, network protocol
B.JDBC API, Native API calls
C.JDBC API, User call
D.JDBC API, ODBC API calls
ANS:-JDBC API, Native API calls option B.

111.Observe the following figure and identify the type of architecture.


T4U_2579.jpeg Y1
A.Two-Tier
B.Three-Tier
C.N-tier
D.None of the above
ANS:-Two-Tier option A.

112.Database meta data are retrieved through ________.


A.a Connection object
B.a ResultSet Object
C.a Statement object
D.a PreparedStatement object
ANS:-a ResultSet Object option B.

113.__________ ResultSet navigation method consist of


A.getRow()
B.previous()
C.beforeFirst()
D.All of the above
ANS:-All of the above option D.

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.

115.Which method is used to retrive the resultset created.


A.setresultset()
B.getresultset()
C.getResultSet()
D.setResultSet()
ANS:-getresultset() option B.

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.

117.Prepared statement object in JDBC used to exexute ______________ queries.


A.Executeble
B.Simple
C.High level
D.Parametrized
ANS:-Simple 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.

119.PreparedStatements are used for calling_____________.


A.precompile Statement
B.Callable Statement
C.Storeprocedure
D.None of the above
ANS:-precompile Statement option A.

120.A init() ,service(),destroy() methods are declared in ______.


A.javax.servlet.Servlet interface
B.javax.servletHttp interface
C.javax.servlet.servletConfig interface
D.javax.servlet.Http interface
ANS:-javax.servlet.Servlet interface option A.

121.How to send data in get method?


A.we can't
B.as a part of the URL
C.as a part of the request body
D.None of the above
ANS:-as a part of the URL option B.

122.…………………is destructive phase of JSP life cycle.


A.Compilation
B.Cleanup
C.initialization
D.execution
ANS:-Cleanup option B.

123.A cookie contains _____________.


A.Program information
B.State information of user like name, address
C.Server information
D.Client information
ANS:-State information of user like name, address option B.

124.TLD stands for________.


A.Transport level data
B.Tag library descriptor
C.Transmission level descriptor
D.Tag level descriptor
ANS:-Tag library descriptor 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.

126._______ method gives the current session.


A.getSessionId()
B.getSession()
C.session()
D.getWriter()
ANS:-getSession() option B.

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.

128.The include() method of RequestDispatche.


A.sends a request to another resource like servlet, jsp or html
B.includes resource of file like servlet, jsp or html
C.appends the request and response objects to the current servlet
D.None of the above
ANS:-includes resource of file like servlet, jsp or html option B

129.JSP Start and end With the Symbol___________.


A.{ }
B.<# #>
C.<
D.>
ANS:-> option D.

130.JSP page performs request processing by calling………………….method.


A.service()
B.jspService()
C.jspService()
D.jsp_Service()
ANS:-jspService() option B.

131.The servlet can read its initialization arguments through ________.


A.ServletConfig object
B.Configuration
C.ServeltConfiguration
D.ConfigureServlet
ANS:-ServletConfig object option A.

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.

133.A JSP page consists of which tags?


A.HTML tags
B.JSP tags
C.Both A & B
D.None of the above
ANS:-Both A & amp; B option C.
134.Servlet is __________.
A.Class
B.Method
C.Interface
D.None of these
ANS:-Interface option C.

135.JSP embeds in ................ in .....................


A.Servlet into HTML
B.HTML into Java
C.HTML into Servlet
D.Java into HTML
ANS:-Java into HTML option D.

136.Which method of HttpServletResponse is used to redirect an HTTP request to another URL?


A.sendURL()
B.redirectURL()
C.sendRedirect()
D.getRequestDispactcher()
ANS:-sendRedirect() option C.

137.Which of the following is the deployment descriptor file in servlet.


A.web.xml
B.web.html
C.web.jsp
D.index.html
ANS:-web.xml option A.
138.JSP life cycle includes following methods.
A.spInit()
B.jspService()
C.jspDestroy()
D.All
ANS:-All option D.

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.

140.JSP stands for____________.


A.Java Script page
B.Java Server Program
C.Java Server Pages
D.Java Script Program
ANS:-Java Server Pages option C.
141.Name the http method used to send resources to the server.
A.FTP method
B.PUT method
C.WRITE method
D.COPY method
ANS:-PUT method option B.

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.

144.Which method is used to display title on titlebar of Frame?


A.displayTitle(String title)
B.setTitle(String title)
C.showTitle(String title)
D.addTitle(String title)
ANS:-setTitle(String title) option B.

145.Which components are used in this code?

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

public class Iconbutton{


public static void main(String[] args){
JFrame frame = new JFrame("Icon on button");
JButton button = new JButton("JAVA");
Icon imgicon = new ImageIcon("java.gif");

JPanel panel = new JPanel();


button.setIcon(imgicon);
panel.add(button);
frame.add(panel, BorderLayout.NORTH);
frame.setSize(400, 400);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
A.Button and ImageIcon
B.Button andRadioButton
C.CheckBox and ImageIcon
D.Applet And Panel
ANS:-Button and ImageIcon option A.

146.Which method is used to display icon on a JButton component?


A.rollOverIcon(ImageIcon i)
B.setIcon(ImageIcon i)
C.displayIcon(ImageIcon i)
D.removeIcon (ImageIcon i )
ANS:-setIcon(ImageIcon i) option B.

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.

148.Steps for Adding TabbedPane Control.


A.1.Create a JTabbedPane object
2.Call addTab() to Add a tab to the pane
3.Repeat Step 2 for each Tab
4.Add the Tabbed Pane to the content pane

B.1. Create a JTabbedPane object


2.Repeat Step 2 for each Tab
3.Call addTab() to Add a tab to the pane

C.1.Add the Tabbed Pane to the content Pane of the Applet


2.Repeat Step 2 for each Tab
3.Create a JTabbedPane object

D.1.Create a JTabbedPane object


2.Call addTab() to Add a tab to the pane
3.Add the Tabbed Pane to the content Pane of the Applet

ANS:-1.Create a JTabbedPane object


2. Call addTab() to Add a tab to the pane
3.Repeat Step 2 for each Tab
4. Add the Tabbed Pane to the content pane option A.

149.Write the sequence of component to be added on applet ?

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.

150.Which Components are used in Following output?


T1U 893.jpeg Y1
A.JRadioButton ,JTextArea
B.JRadioButton ,JTextField
C.Jcheckbox,JTextField
D.CheckBox,TextArea
ANS:-JRadioButton ,JTextField option B.

151.What is the purpose of ScrollPane.


A.ScrollPanel displays component in Tabular form
B.ScrollPane displays component in Tree form
C.ScrollPane Displays component in a rectangular area
D.None
ANS:-ScrollPane Displays component in a rectangular area option C.

152.Which method is used to processes mouse click?


A.MouseClicked()
B.Mouse_CLICKED()
C.MOUSE_PRESSED()
D.MOUSE_ENTERED ()
ANS:-MouseClicked() option A.

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

cb = new JCheckBox("Java", false);


cb.addItemListener(this);
contentPane.add(cb);

cb = new JCheckBox("Perl", false);


cb.addItemListener(this);
contentPane.add(cb);

jtf = new JTextField(15);


contentPane.add(jtf);
}
public void itemStateChanged(ItemEvent ie)
{
JCheckBox cb = (JCheckBox)ie.getItem();
jtf.setText(cb.getText());
}
}
T1U_8890.jpeg Y1
A.cb.addActionListener(this)
B.cb.addItemListener(this);
C.contentPane.addItemListener(this);
D.contentPane.add(jcb);
ANS:-cb.addItemListener(this); option B.

155.What is the use of String getActionCommand( ) method of ActionEvent class?


A.To obtain the label(caption) of Button
B.To obtain the reference of Button
C.To obtain the object of Button
D.To obtain the label(caption) & object of Button
ANS:-To obtain the label(caption) of Button option A.

156.The follwowing is an example of which layout?


T1U_5914.jpeg Y1
A.CardLayout
B.null Layout
C.BorderLayout
D.GridLayout
ANS:-CardLayout option A.

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.

161._______method to specify the text for a standard tooltip.


A.setToolTipText()
B.JToolTip()
C.getToolTipText()
D.createTooltip()
ANS:-setToolTipText() option a.

162.Which components are used in the following output?


T1U_8579.jpeg Y1
A.Label , Button, TextArea, Checkbox
B.Applet , Button , FlowLayout ,RadioButton
C.Frame,Button,FlowLayout ,RadioButton
D.Label,Button, TextField, Checkbox
ANS:-Label,Button, TextField, Checkbox option D.

163.setEnabled(false); method used in menuitem for __________.


A.Used to disable menu item
B.Used to disable menu
C.Used to invisible menuitem
D.None of the above
ANS:-Used to disable menu item option A.

164.What will be displayed when you run the following code.


import java.awt.*;
import javax.swing.*;
public class Demo2 extends JFrame
{
Demo2()
{
JButton b1=new JButton("Hello");
JButton b2=new JButton("Welcome");
add(b1);
add(b2);
setSize(300,300);
setVisible(true);
}
public static void main(String argv[])
{
Demo2 d=new Demo2();
}
}
Y2
A.S1Q28O1.jpeg T1U_7714_a1.jpeg
B.S1Q28O2.jpeg T1U_7714_a2.jpeg
C.S1Q28O3.jpeg T1U_7714_a3.jpeg
D.S1Q28O4.jpeg T1U_7714_a4.jpeg
ANS:-S1Q28O4.jpeg option D.

165.Which components are used in the following output?


T1U_4798.jpeg Y1
A.ScrollPane, Label, List
B.Scrollbar, Label, List
C.Scrollbar, Label, Choice
D.ScrollPane, Label, Choice
ANS:-Scrollbar, Label, Choice option C.

166.Find out missing statement from following code


import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class choice extends Applet
{
{
Choice c=new Choice();
c.add("red");
c.add("yellow");
add(c);
}
}
/*<applet
code="choice",width="300",height="400"></applet>*/
A.public void init()
B.add(choice)
C.import java.event.*;
D.None of the above
ANS:-public void init() 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.

168.What will be output of following program


import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code=tbutton.java width=300 height=300></applet>*/
public class tbutton extends Applet implements ActionListener
{
Button b;
public void init()
{
b=new Button("Start");
add(b);
}
public void actionPerformed(ActionEvent ae)
{
String s=b.getLabel();
if(s.equals("Start"))
b.setLabel("Stop");
else
b.setLabel("Start");
}
}
A.One Button will be Displayed with caption stop
B.One Button will be Displayed and Event will be handled
C.One Button will be Displayed and event will not be handled
D.One Button will be displayed with caption start and event will be handled
ANS:-One Button will be Displayed and event will not be handled option C.

169.Identify the components in the given output.


T2U_1333.jpeg Y1
A.Applet,Frame,Menu,MenuItems,MenuBar
B.Applet,Menu,MenuItems
C.Frame,Menu,MenuItem,MenuBar
D.Frame,Menu
ANS:-Applet,Frame,Menu,MenuItems,MenuBar option A.

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("ok"); option A.

173.Which is the correct code for following output.


T2U_8647.jpeg Y1
A.
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>
*/

public class HandleActionEventExample extends Applet implements ActionListener


{
String actionMessage="";

public void init()


{

Button Button1 = new Button("Ok");


Button Button2 = new Button("Cancel");
add(Button1);
add(Button2);

Button1.addActionListener(this);
Button2.addActionListener(this);
}

public void paint(Graphics g){


g.drawString(actionMessage,10,50);
}
public void actionPerformed(ActionEvent ae){
String action = ae.getActionCommand();
if(action.equals("Ok"))
actionMessage = "Ok Button Pressed";
else if(action.equals("Cancel"))
actionMessage = "Cancel Button Pressed";
repaint();
}
}

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

public class HandleActionEventExample extends Applet implements ActionListener


{
String actionMessage;

public void init()


{

Button Button1 = new Button("Ok");


Button Button2 = new Button("Cancel");
add(Button1);
add(Button2);

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

public class HandleActionEventExample extends Applet implements ActionListener


{
String actionMessage="";

public void init()


{

Button Button1 = new Button("Ok");

add(Button1);
add(Button2);

public void paint(Graphics g){


g.drawString(actionMessage,10,50);
}
public void actionPerformed(ActionEvent ae){
String action = ae.getActionCommand();
if(action.equals("Ok"))
actionMessage = "Ok Button Pressed";
else if(action.equals("Cancel"))
actionMessage = "Cancel Button Pressed";
repaint();
}
}

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

public class HandleActionEventExample extends Applet implements ActionListener{


String actionMessage="";

public void init(){

Button Button1 = new Button("Ok");


Button Button2 = new Button("Cancel");

Button1.addActionListener(this);
Button2.addActionListener(this);
}

public void paint(Graphics g){


g.drawString(actionMessage,10,50);
}
public void actionPerformed(ActionEvent ae){
String action = ae.getActionCommand();
if(action.equals("Ok"))
actionMessage = "Ok Button Pressed";
else if(action.equals("Cancel"))
actionMessage = "Cancel Button Pressed";
repaint();
}
}

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

public class HandleActionEventExample extends Applet implements ActionListener


{
String actionMessage="";

public void init()


{

Button Button1 = new Button("Ok");


Button Button2 = new Button("Cancel");
add(Button1);
add(Button2);

Button1.addActionListener(this);
Button2.addActionListener(this);
}

public void paint(Graphics g){


g.drawString(actionMessage,10,50);
}
public void actionPerformed(ActionEvent ae){
String action = ae.getActionCommand();
if(action.equals("Ok"))
actionMessage = "Ok Button Pressed";
else if(action.equals("Cancel"))
actionMessage = "Cancel Button Pressed";
repaint();
}
} option A.

174.Which of following constants is not defined in WindowEvent class?


a)WINDOW_ACTIVATED
b)WINDOW_CLOSED
c)WINDOW_DEICONIFIED
d)none of the above
A.a and c
B.c
C.b
D.d
ANS:-d option D.
175.Identify correct sequence of states of following controls.
T2U_8833.jpeg Y1
A.True,False,True,False
B.False,True,False,True
C.False,False,True,True
D.True,True,False,False
ANS:-True,False,True,False option A.

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.

177.MouseListener interface belongs which of the following methods?


A.mouseDragged,mouseExited,mouseEntered,mousePressed,mouseClicked,mouseMoved,mouseRelease
d

B.mouseExited,mouseEntered,mousePressed,mouseClicked,mouseReleased

C.mouseDragged,mousePressed,mouseClicked,mouseMoved,mouseReleased

D.mousePressed,mouseReleased,mouseClicked,mouseMoved

ANS:-mouseEntered,mousePressed,mouseClicked,mouseReleased
option B.

178.Select the missing statement in given code


import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="SimpleKey" width=300 height=100>
</applet>
*/
public class SimpleKey extends Applet

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

179.Action event is applied on.


A.Frame
B.Checkbox, Choice, List
C.Scrollbar
D.Button, TextField, List, Menu
ANS:-Button, TextField, List, Menu option D.

180.Which of following purpose of the enableEvents() method is true?


A)The enableEvents() method is used to enable an event for a particular object.

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.

181.Select the proper output for following code:


import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code="InnerClassDemo" width=200 height=100></applet>*/
public class InnerClassDemo extends Applet
{
public void init()
{
addMouseListener(new MyMouseAdapter());
}
class MyMouseAdapter extends MouseAdapter
{
public void mousePressed(MouseEvent me)
{
showStatus("Mouse Pressed");
}
}
}
Y2
A.S2Q30O1.JPG T2U_8708_a1.jpeg
B.S2Q30O2.JPG T2U_8708_a2.jpeg
C.S2Q30O3.JPG T2U_8708_a3.jpeg
D.S2Q30O4.JPG T2U_8708_a4.jpeg
ANS:-S2Q30O1.JPG 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.

183.To handle JRadiobutton which Listener and Event Class is Required?


T2U_4740.jpeg Y1
A.ActionListener and ActionEvent
B.ActionListener and ItemEvent
C.ItemListener and ItemEvent
D.None of the Above
ANS:-ActionListener and ActionEvent option A.

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.

186.Select the proper constructor for creating TCP client.


A.ServerSocket(int port)
B.ServerSocket(int port,int maxqueue)
C.Socket(String Host,int port)
D.Socket(int port)
ANS:-Socket(String Host,int port) option C.

187.Which of the following is not correct constructor of URL?


A.URL(String url)
B.URL(String protocol,String host,String port, String filepath)
C.URL(String protocol,String host, String filepath)
D.URL(URL urlObj, String urlSpecifier)
ANS:-URL(String protocol,String host,String port, String filepath) option B.

189.What is the default length of the queue in following constructor of Serversocket?


ServerSocket(int portno)
A.50
B.25
C.40
D.30
ANS:-50 option A.

190.What is the error in given code?


import java.net.*;
public class Hostname
{
public static void main(String args[])
{
try
{
InetAddress local= InetAddress.getLocalHost();
System.out.println ("Local hostname is: " + local.getLocalHostName());
}
catch (UnknownHostException e)
{ System.err.println ("Can't detect localhost : " + e); }
}
}
A.System.out.println ("Local hostname is: " + local.getLocalHostName()); is wrong

B.Program is Wrong because there should be no main function

C.Program is Wrong because import.java.net is not a package

D.None of the above


ANS:-System.out.println ("Local hostname is: " + local.getLocalHostName()); is
wrong option A.

191._________ are the instance methods of InetAddress class.


A.boolean equals(Object other)
B.String getHostName()
C.String toString()
D.All
ANS:-All option D.

192.what is the function of method int getPort()?


A.Returns remote port to which Socket object is connected
B.Returns local port to which Socket object is connected
C.Both a & b
D.None of above
ANS:-Both a & b option C.

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.

195.What will be displayed in output


import java.net.*;
class UrlDemo
{
Public static vod main(String args[]) throws MalformedURLException
{
URL u1=new u1(http://www.msbte.com/mainsite/);
System.out.println(“Protocol:”+u1.getProtocol());
}
}
A.Port : -1
B.Protocol : http
C.file :/mainsite/
D.Host : www.msbte.com
ANS:-Protocol : http option B.
196.Select the method used to create a URL Connection.
A.URL connection()
B.openConnection()
C.URL()
D.URL Decoder()
ANS:-openConnection() option B.

197.which is the correct syntax for getLocalHost() method.


A.Static Inetaddress getLocalHost()throws UnknownHostException

B.static InetAddress getLocalHost()throws UnknownHostException

C.static Inetaddress getLocalHost()throws UnknownHostException

D.Static Inetaddress GetLocalHost()throws UnknownHostException


ANS:-static InetAddress getLocalHost()throws UnknownHostException option B.

198.For the following output, which method is used in program:


Protocol: http
Port: -1

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("http://www.osborne.com/downloads");
System.out.println("Protocol: "+hp.getProtocol());
System.out.println("Port: " + 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.

200.fill in correct code at blank spaces


import java.net.*;

public class getDatagramExample {

public static void main(String args[]) {

String s = "This is a test.";

byte[] data = new byte[s.length()];


s.getBytes(0, s.length(), data, 0);
try {
InetAddress ia = InetAddress.-------------("www.msbte.com");
int port = 7;
DatagramPacket dp = new DatagramPacket(data, data.length, ia, port);
System.out.println("This packet is addressed to " + dp.getAddress() + " on port
" + dp.getPort());
System.out.println("There are " + dp.getLength() + " bytes of data in the
packet");
System.out.println(new String(dp.getData(), 0, 0, dp.getLength()));
}
catch (----------------------------------- e) {
System.err.println(e);
}
}

}
A.getname,unkwonException
B.getByName, UnknownHostException
C.getbyall,knownhostexception
D.none is correct
ANS:-getByName, UnknownHostException option B.

201.Which of the these is constructor of Socket?


A.Socket(int port,String hostName)
B.Socket(InetAddress ipAddress, int port)
C.Socket(int port,InetAddress ipAddress)
D.Socket(InetAddress ipAddress, String hostName)
ANS:-Socket(InetAddress ipAddress, int port) option B.

202.What is out put of following code


import java.net.*;

class networking {

public static void main(String[] args) throws MalformedURLException {

URL obj = new URL("http://www.google.com");

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.

203.The___________ which contains a set of pre-written networking routines.


A.java.net package
B.java.lang package
C.java.AWT
D.java.awt.event.AWTEvent
ANS:-java.net package option A.

204.Select the proper constructor of serversocket.


A.ServerSocket(intport, intmaxQueue)
B.Socket(InetAddressipAddress, intport)
C.Socket(int port)
D.ServerSocket()
ANS:-ServerSocket(intport, intmaxQueue) option A.

205.openConnection() method returns_____________.


A.void
B.InetAddress instance
C.URLConnection object
D.All of above
ANS:-URLConnection object option C.

206.__________ is a bundle of information passed between machines.


A.Protocol
B.Cache
C.Datagram
D.segment
ANS:-Datagram option C.

207.Which class is used to create UDP client?


A.Socket()
B.DatagramSocket()
C.dataGramPacket()
D.ServerSocket()
ANS:-DatagramSocket() option B.

208.select the proper constructor of DatagramPacket class?


A.DatagramPacket(byte data[],int size)
B.DatagramPacket(byte data[],int offset,int size)
C.DatagramPacket(byte data[],int size,InetAddress ip,int port)
D.All of the above
ANS:-All of the above option D.

209.What does openConnection() method return?


A.Connection object
B.URLConnection object
C.URL object
D.ConnectionURL object
ANS:-URLConnection object option B.

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.

212.______________Returns a ResultSetMetaData object describing the ResultSet.


A.getMetaData
B.getRowData
C.getMetaRowData
D.none of the above
ANS:-getMetaData option A.

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.

215.To connect to a local MySQL database named test, use.


A.Connection connection = DriverManager.getConnection(jdbc:mysql://localhost/test);

B.Connection connection = DriverManager.connect("jdbc:mysql://localhost/test");

C.Connection connection = DriverManager.getConnection("mysql:jdbc://localhost/test");

D.Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/test");

ANS:-Connection connection =
DriverManager.getConnection("jdbc:mysql://localhost/test"); 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.

217.select correct method of statement interface.


A.public ResultSet executeQuery(int s)
B.public ResultSet executeQuery()throws SQLException
C.public void executeQuery(String sql)throws SQLException
D.public ResultSet executeQuery(String sql)throws SQLException
ANS:-public ResultSet executeQuery(String sql)throws SQLException 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.

220.The __________method sets the query parameters of the PreparedStatement Object.


A.putString()
B.InsertString()
C.setString()
D.setTOString()
ANS:-setString() option C.

221.Identify the correct syntax of executeUpdate method.


A.public ResultSet executeUpdate(String sql)
B.public boolean executeUpdate(String sql)
C.public int executeUpdate(String sql)
D.public int[] executeUpdate(String sql)
ANS:-public int executeUpdate(String sql) option C.

222.Which of the following statement is not true?


1) ResultSetMetaData
object is created using getMetaData() of ResultSet object

2)PreparedStatement object is created using prepareStatement() of Connection object

3)DatabaseMetaData object is created using getMetaData() of ResultSet object

4)Statement object is created using createStatement() of Connection object


A.1
B.2
C.3
D.4
ANS:-3 option C.

223.Which of these methods can be used to determine the type of event?


A.getID()
B.getSource()
C.getEvent()
D.getEventObject()
ANS:-getID() option A.

224.Which of the following method should be used to create connection object.


A.Connection getConnection(String url)
B.Connection getConnection(String url,String username,String password)
C.Connection getConnection(String url,Properties info)
D.All of the above
ANS:-All of the above option D.

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

stmt.executeUpdate("insert into emp765 values(33,'Irfan',50000)");


int result=stmt.executeUpdate("update emp765 set name='Vimal',salary=10000
where id=33");
int result=stmt.executeUpdate("delete from emp765 where id=33");

System.out.println(result+" records affected");


con.close();
}
}

A.Statement stmt=con.createStatement();

B.Statement stmt;

C.createStatement();

D.Statement =con.createStatement();

ANS:-Statement stmt=con.createStatement(); option A.

227.Which statement is static and synchronized in JDBC API.


A.executeQuery()
B.executeUpdate()
C.getConnection()
D.prepareCall()
ANS:-getConnection() option C.

228.What will be the out of the following code?


import java.awt.*;
import java.io.*;
public class Demo
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver Loaded");
Connection con=DriverManager.getConnection("jdbc:odbc:mybd1");
System.out.println("Connection Establish");
con.close();
System.out.println("Connection close ");
}
catch(Exception e)
{
System.out.println("Error");
}
}
}
A.Driver Loaded
B.Connection Establish
C.Error
D.Connection Close
ANS:-Error option C.
229.The following methods belongs to the life cycle methods of the servlet.
A.init( )
B.service( )
C.destroy( )
D.All Of Above
ANS:-All Of Above option D.

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.

231.Servlet Life Cycle have _____________________ state.


A.5
B.4
C.3
D.6
ANS:-5 option A.

232.Servlet offer following advantage over CGI.


A.CGI is not platform independent but servlet are platform independent
B.Servlet are more restricted than CGI
C.servlet performance is not better than CGI
D.servlet consist less classes methods than CGI
ANS:-CGI is not platform independent but servlet are platform independent option A.

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.

235.Identify the false statement from the following.


A.Cookie is a small amount of information sent by servlet to the web browser, saved by the web browser
and later sent back to the server

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.

237.Which mechanism is included by jsp for defining custom tags?


A.static attributes
B.local attributes
C.dynamic attributes
D.global attributes
ANS:-dynamic attributes option C.

238.The getInitParameter() method of ServletConfig interface returns_____________.


A.It returns the context parametrs value
B.It returns the parameters passed to servlets
C.It returns the Initialization parameter value.
D.It returns the Enumeration of Initialization parameters
ANS:-It returns the Initialization parameter value. option C.

239.Which file will start tomcat Server?


A.startup.bat
B.start.bat
C.starttom.bat
D.startapache.bat
ANS:-startup.bat option A.

240.Given an HttpServletRequest request and an httpServletResponse response:


41. HttpSession session = null;
42. / / insert code here
43. if (session = = null) {
44. / / do something if session does not exist
45. } else {
46. / / do something if session exists
47. }
To implement the design intent, which statement must be inserted at line 42?
A.session = response.getSession ();
B.session = request.getSession ();
C.session = request.getSession (true);
D.session = request.getSession (false);
ANS:-session = request.getSession (false); option D.

241.In order to create a HttpServlet following import statements are used:


A. import java.io.*;
B. import javax.servlet.*;
C. import javax.servlet.http.*;
Which of the above statements are mandatory?
A.Only statements A and C are compulsory.
B.Only statements A and B are required.
C.Only statements B and C can be used.
D.Statements A, B, C are compulsory.
ANS:-Statements A, B, C are compulsory. option D.

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.

247.Which statements is missing in the given code below.


import java.awt.*;
import java.awt. Event.*;
import javax.swing.*;
/*<applet code = Colur width = 500 height = 500 ></applet>*/

public class Colur extends J Applet implements ActionListener


{
Container cp = getContentPane ();
public void init ()
{
cp.setLayout (new FlowLayout());
JRadioButton b1= new JRadioButton("Red");
b1.addActionListener(this);
cp.add(b1);
JRadioButton b2 = new JRadioButton("Green");
b2.addActionListener(this);
cp.add(b2);
JRadioButton("Green");
b3.addActionListener(this);
cp.add(b3);

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.

249.What will be output for following program:

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.

251.Analyze the following code :


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

public class Test {


public static void main(String[] args) {
JFrame frame = new JFrame("My Frame");
frame.add(new JButton("OK"));
frame.add(new JButton("Cancel"));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 200);
frame.setVisible(true);
}
}

A.Only button OK is displayed.

B.Only button Cancel is displayed.

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.

ANS:-Only button Cancel is displayed. option B.

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

D. An arc starting at 45 degrees, traversing through 90 degrees


clockwise bounded by a box of height 50, width 50 with a centre point of 90, 180

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.

253.Select the proper command to run the following code


import java.awt.*;
import javax.swing.*;
public class tabbeddemo extends JApplet
{
public void init()
{
Container ContentPane=getContentPane();
JTabbedPane jt=new JTabbedPane();
jt.addTab("City",new CityPanel());
jt.addTab("Color",new ColorPanel());
jt.addTab("Flavours",new FlavoursPanel());
getContentPane().add(jt);
}
}
class CityPanel extends JPanel
{
public CityPanel()
{
JButton b1=new JButton("Kolhapur");
add(b1);
JButton b2=new JButton("Pune");
add(b2);
JButton b3=new JButton("Mumbai");
add(b3);
JButton b4=new JButton("Sangali");
add(b4);
}
}
class ColorPanel extends JPanel
{
public ColorPanel()
{
JRadioButton rb1=new JRadioButton("Red");
add(rb1);
JRadioButton rb2=new JRadioButton("Green");
add(rb2);
JRadioButton rb3=new JRadioButton("Blue");
add(rb3);
JRadioButton rb4=new JRadioButton("Pink");
add(rb4);
}
}
class FlavoursPanel extends JPanel
{
public FlavoursPanel()
{
JComboBox jc=new JComboBox();
jc.addItem("Vanilla");
jc.addItem("Chocalate");
jc.addItem("Straberry");
add(jc);
}
}
/*<applet code="tabbeddemo.class"
width=500 height=500>
</applet>*/
A.Javac tabbeddemo.java
B.java tabbeddemo
C.appletviewer tabbeddemo.java
D.All of above
ANS:-appletviewer tabbeddemo.java option C.

254.Which code is correct to generate the following output?


T1A_1344.jpeg Y1
A.Scrollbar vert = new Scrollbar(Scrollbar.VERTICAL,0, 1, 0, 100);
Scrollbar horz = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, 100);

B.Scrollbar vert = new Scrollbar(Scrollbar.VERTICAL,0, 1,);


Scrollbar horz = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1);

C. Scrollbar vert = new Scrollbar(Scrollbar.VERT,0, 1, 0, 100);


Scrollbar horz = new Scrollbar(Scrollbar.HOR, 0, 1, 0, 100);

D.Scrollbar vert = new Scrollbar(SCROLLBAR.VERTICAL, 1, 0, 100);


Scrollbar horz = new Scrollbar(SCROLLBAR.HORIZONTAL, 1, 0, 100);

ANS:-Scrollbar vert = new Scrollbar(Scrollbar.VERTICAL,0, 1, 0, 100);


Scrollbar horz = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, 100); option A.

255.Which code is correct to generate the following output?


import java.awt.*;
class Demo extends Frame
{
public static void main(String args[]){
Frame f=new Frame();
f.setVisible(true);
f.setSize(150,200);
} }
In the above program how can a user hide the frame window.
A.using void setHide();
B.using Void makeHidden(1);
C.using setVisible(false);
D.using hide(false);
ANS:-using setVisible(false); 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.

257.Write a java program for following Output?


T1A_477.jpeg Y1Z
A.
import java.awt.*;
public class Butt extends Frame
{
public static void main(String argv[])
{
Butt MyBut=new Butt();
}
Butt()
{
Button HelloBut=new Button("Hello");
Button ByeBut=new Button("Bye");
add(HelloBut); add(ByeBut);
setSize(300,300);
setVisible(true);
}
}

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("Hello");
Button ByeBut=new Button("Bye");
add(HelloBut); add(ByeBut);
setSize(300,300);
setVisible(true);
}
}
option D.

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


import java.applet.Applet;
import java.awt.*;
public class ButtonTest2 extends Applet {
public void init() {
String[] labelPrefixes = { "Start", "Stop",
"Pause","Resume" };
Panel p1 = new Panel();
for (int i=0; i<4; i++) {
p1.add(new Button(labelPrefixes[i] + " Thread1"));
}
Panel p2 = Panel();
for (int i=0; i<4; i++) {
p2.add(new Button(labelPrefixes[i] + " Thread2"));
}
add(p1);
add(p2);
}
}
A.Error in the statement creating panel object
B.Error in sttement of adding control
C.error in statement of defining package
D.Error in loop
ANS:-Error in the statement creating panel object option A.

259.Consider following program.Select the missing statement from options.


import javax.swing.*;
import java.awt.*;
/*<applet code="TableDemo" width=200 height=200> </applet>*/
public class TableDemo extends JApplet
{
public void init()
{
Container cp=getContentPane();
cp.setLayout(new BorderLayout());
String data[][] =
{{"Neeta","CO","A"},{"Mahesh","CE","B
"},{"Akanksha","IF","C"},{"Neha","ME",
"A"}};
String col[] = {"Name","Branch","Grade"};
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
JScrollPane jsp=new JScrollPane(table,v,h);
cp.add(jsp,BorderLayout.CENTER);
}
}

A.JTable table = new JTable( );


B.JTae table = new JTable(data,col);
C.JTable ta = new JTable(data,col);
D.JTable table = new JTable(data,col);
ANS:-JTable table = new JTable(data,col); 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.

261.Show the output of following code.


import javax.swing.*;
public class Test
{
public static void main(String ar[])
{
JButton b1=new JButton("OK");
System.out.println(b1.isVisible()+" ");
JFrame f1=new JFrame();
System.out.println(f1.isVisible()+" ");
}
}
A.true,false
B.true,true
C.false,true
D.false,false
ANS:-true,false option A.

262.How many buttons will be added with following code?

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

public class MyFlowLayout{


JFrame f;
MyFlowLayout(){
f=new JFrame();

JButton b1=new JButton("1");


JButton b2=new JButton("2");
JButton b3=new JButton("3");
JButton b4=new JButton("4");
JButton b5=new JButton("5");
f.add(b1);f.add(b2);f.add(b3);f.add(b4);f.add(b5);

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.

263.Select the proper command to run the following code

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

265. Given the following code :

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.

268.Select proper code for given output.


T1A_7669.jpeg Y1
A.
Demonstrate JTree.
import java.awt.*;
import javax.swing.event.*;
/*
<applet code="JTreeDemo" width=400 height=200>
</applet>
*/
public class JTreeDemo extends JApplet {
JTree tree;
JLabel jlab;
public void init() {

DefaultMutableTreeNode top = new DefaultMutableTreeNode("Options");


// Create subtree of "A".
DefaultMutableTreeNode a = new DefaultMutableTreeNode("A");
top.add(a);
DefaultMutableTreeNode a1 = new DefaultMutableTreeNode("A1");
a.add(a1);
DefaultMutableTreeNode a2 = new DefaultMutableTreeNode("A2");
a.add(a2);
// Create subtree of "B".
DefaultMutableTreeNode b = new DefaultMutableTreeNode("B");
top.add(b);
DefaultMutableTreeNode b1 = new DefaultMutableTreeNode("B1");
b.add(b1);
DefaultMutableTreeNode b3 = new DefaultMutableTreeNode("B3");
b.add(b3);
// Create the tree.
tree = new JTree(top);
// Add the tree to a scroll pane.
JScrollPane jsp = new JScrollPane(tree);
// Add the scroll pane to the content pane.
add(jsp);
// Add the label to the content pane.
jlab = new JLabel();
add(jlab, BorderLayout.SOUTH);
// Handle tree selection events.
tree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent tse) {
jlab.setText("Selection is " + tse.getPath());
}
});
}
}

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

DefaultMutableTreeNode top = new DefaultMutableTreeNode("Options");


// Create subtree of "A".
DefaultMutableTreeNode a = new DefaultMutableTreeNode("A");
top.add(a);
DefaultMutableTreeNode a1 = new DefaultMutableTreeNode("A1");
a.add(a1);
DefaultMutableTreeNode a2 = new DefaultMutableTreeNode("A2");
a.add(a2);
// Create subtree of "B".
DefaultMutableTreeNode b = new DefaultMutableTreeNode("B");
top.add(b);
DefaultMutableTreeNode b1 = new DefaultMutableTreeNode("B1");
b.add(b1);
DefaultMutableTreeNode b2 = new DefaultMutableTreeNode("B2");
b.add(b2);
DefaultMutableTreeNode b3 = new DefaultMutableTreeNode("B3");
b.add(b3);
// Create the tree.
tree = new JTree(top);
// Add the tree to a scroll pane.
JScrollPane jsp = new JScrollPane(tree);
// Add the scroll pane to the content pane.
add(jsp);
// Add the label to the content pane.
jlab = new JLabel();
add(jlab, BorderLayout.SOUTH);
// Handle tree selection events.
tree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent tse) {
jlab.setText("Selection is " + tse.getPath());
}
});
}
}

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

DefaultMutableTreeNode top = new DefaultMutableTreeNode("Options");


// Create subtree of "A".
DefaultMutableTreeNode a = new DefaultMutableTreeNode("A");
top.add(a);
DefaultMutableTreeNode a1 = new DefaultMutableTreeNode("A1");
a.add(a1);
DefaultMutableTreeNode a2 = new DefaultMutableTreeNode("A2");
a.add(a2);
// Create subtree of "B".
DefaultMutableTreeNode b = new DefaultMutableTreeNode("B");
top.add(b);
DefaultMutableTreeNode b1 = new DefaultMutableTreeNode("B1");
b.add(b1);
DefaultMutableTreeNode b3 = new DefaultMutableTreeNode("B3");
b.add(b3);
// Create the tree.
tree = new JTree(top);
// Add the tree to a scroll pane.
JScrollPane jsp = new JScrollPane(tree);
// Add the scroll pane to the content pane.
add(jsp);
// Add the label to the content pane.
jlab = new JLabel();
add(jlab, BorderLayout.SOUTH);
// Handle tree selection events.
tree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent tse) {
jlab.setText("Selection is " + tse.getPath());
}
});
}
}

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

DefaultMutableTreeNode top = new DefaultMutableTreeNode("Options");


// Create subtree of "A".
DefaultMutableTreeNode a = new DefaultMutableTreeNode("A");
top.add(a);
DefaultMutableTreeNode a1 = new DefaultMutableTreeNode("A1");
a.add(a1);
DefaultMutableTreeNode a2 = new DefaultMutableTreeNode("A2");
a.add(a2);
// Create subtree of "B".
DefaultMutableTreeNode b = new DefaultMutableTreeNode("B");
top.add(b);
DefaultMutableTreeNode b1 = new DefaultMutableTreeNode("B1");
b.add(b1);
DefaultMutableTreeNode b2 = new DefaultMutableTreeNode("B2");
b.add(b2);
DefaultMutableTreeNode b3 = new DefaultMutableTreeNode("B3");
b.add(b3);
// Add the tree to a scroll pane.
JScrollPane jsp = new JScrollPane(tree);
// Add the scroll pane to the content pane.
add(jsp);
// Add the label to the content pane.
jlab = new JLabel();
add(jlab, BorderLayout.SOUTH);
// Handle tree selection events.
tree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent tse) {
jlab.setText("Selection is " + tse.getPath());
}
});
}
}

ANS:-
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() {

DefaultMutableTreeNode top = new DefaultMutableTreeNode("Options");


// Create subtree of "A".
DefaultMutableTreeNode a = new DefaultMutableTreeNode("A");
top.add(a);
DefaultMutableTreeNode a1 = new DefaultMutableTreeNode("A1");
a.add(a1);
DefaultMutableTreeNode a2 = new DefaultMutableTreeNode("A2");
a.add(a2);
// Create subtree of "B".
DefaultMutableTreeNode b = new DefaultMutableTreeNode("B");
top.add(b);
DefaultMutableTreeNode b1 = new DefaultMutableTreeNode("B1");
b.add(b1);
DefaultMutableTreeNode b2 = new DefaultMutableTreeNode("B2");
b.add(b2);
DefaultMutableTreeNode b3 = new DefaultMutableTreeNode("B3");
b.add(b3);
// Create the tree.
tree = new JTree(top);
// Add the tree to a scroll pane.
JScrollPane jsp = new JScrollPane(tree);
// Add the scroll pane to the content pane.
add(jsp);
// Add the label to the content pane.
jlab = new JLabel();
add(jlab, BorderLayout.SOUTH);
// Handle tree selection events.
tree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent tse) {
jlab.setText("Selection is " + tse.getPath());
}
});
}
} option B.

269.Find error in following code.


import java.awt.*;
import java.applet.*;

public class ChoiceDemo extends Applet


{
Choice os;
String msg = "";
public void init()
{
os = new Choice();

// add items to os list


os.add("Windows 98/XP");
os.add("Windows NT/2000");
add(os);
}
}
A.Listener missing
B.applet code is missing
C.package missing
D.All
ANS:-applet code is missing option B.

270.import java.awt.*;
import javax.swing.*;

public class Test {


public static void main(String[] args) {
JFrame frame = new JFrame("My Frame");
frame.add(new JButton("OK"));
frame.add(new JButton("Cancel"));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 200);
frame.setVisible(true);
}
}
A.Only button OK is displayed.

B.Only button Cancel is displayed.

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.

ANS:-Only button Cancel is displayed. option B.

271.Observe the following program ....


import java.awt.Color;
import javax.swing.*;

public class TyifArea {


JTextArea area;
JFrame f;
TyifArea()
{
f=new JFrame();

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

B.The Output will Contain a 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.

273.What error will generate in following program

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

public class sample extends Applet implements ActionListener, FocusListener

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

274.Select the missing statement


public class A1 extends Applet {
Button b1;
Label l1;
public void init()
{ setLayout(new FlowLayout());
b1=new Button("Click");
l1=new Label();
add(l1);
add(b1); }
public void actionPerformed(ActionEvent ae){
if(ae.getSource()==b1)
l1.setText("Hello");
}
}
A.b1.addActionListener(this)
B.this.addActionListener(b1)
C.No statement is required to be added
D.b1.addActionListener()
ANS:-b1.addActionListener(this) option A.

275.Select the missing statement in given code


importjava.awt.*;
importjava.applet.*;
/*
<applet code="mouse" width=300 height=100>
</applet>
*/
public class mouse extends Applet implements MouseListener, MouseMotionListener
{
String msg = "";
intmouseX = 0, mouseY = 0
public void init()
{
}
public void mouseClicked(MouseEvent me)
{
mouseX = 0;
mouseY = 10;
msg = "Mouse clicked.";
repaint();
}
public void mouseEntered(MouseEvent me)
{
mouseX = 0;
mouseY = 10;
msg = "Mouse entered.";
repaint();
}
public void mouseExited(MouseEvent me)
{
mouseX = 0;
mouseY = 10;
msg = "Mouse exited.";
repaint();
}
public void mousePressed(MouseEvent me)
{
mouseX = me.getX();
mouseY = me.getY();
msg = "Down";
repaint();
}
public void mouseReleased(MouseEvent me)
{
mouseX = me.getX();
mouseY = me.getY();
msg = "Up";
repaint();
}
public void mouseDragged(MouseEvent me)
{
mouseX = me.getX();
mouseY = me.getY();
msg = "*";
showStatus("Dragging mouse at " + mouseX + ", " + mouseY);
repaint();
}
public void mouseMoved(MouseEvent me)
{
showStatus("Moving mouse at " + me.getX() + ", " + me.getY());
}
public void paint(Graphics g)
{
g.drawString(msg, mouseX, mouseY);
}
}
A.addMouseMotionListener(this);
B.addMouseListener(this);
C.import java.awt.event.*;
D.all of above
ANS:-all of above option D.

276.Find missing statement in given code:


import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class arith extends Applet implements ActionListener
{Label l1,l2,l3;
TextField t1,t2,t3;
Button b1,b2;
public void init()
{l1=new Label("Number1:");
l2=new Label("Number2:");
l3=new Label("Result:");
t1=new TextField();t2=new TextField();
t3=new TextField();b1=new Button("Add");
b2=new Button("Sub");
b1.addActionListener(this);
b2.addActionListener(this);
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(b1);
add(b2);
}public void actionPerformed(ActionEvent e)
{if(e.getSource()=b1)
{int a=Integer.parseInt(t1.getText());
int b=Integer.parseInt(t2.getText());
int c=a+b;
t3.setText(Integer.toString(c));
}}} /*<applet code="arith.class" width=400 height=300></applet>*/
A.semicolon missing
B.comma missing
C.{ missing
D.= missing
ANS:- = missing option D.

277.Which method should be used to handle event in the given program


import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*<applet code=rgb width=400 height=400></applet>*/
public class rgb extends Applet implements ActionListener
{
Button r=new Button("Red");
Button g=new Button("Green");
Button b=new Button("Blue");
public void init()
{
add(r);add(g);add(b);
r.addActionListener(this);
g.addActionListener(this);
b.addActionListener(this);
}
public void _______________(ActionEvent e)
{
if(e.getSource()==r)
setBackground(Color.red);
if(e.getSource()==g)
setBackground(Color.green);
if(e.getSource()==b)
setBackground(Color.blue);
}
}

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.

279.Identify the proper abstract methods of WindowFocusListener interface.


A.public void focusGained(WindowEvent obj)
public void focusLost(WindowEvent obj)

B.public void windowActivated(WindowEvent obj)


public void windowDeactivated(WindowEvent obj)

C. public void windowGainedFocus(WindowEvent obj)


public void windowLostFocus(WindowEvent obj)

D.public void windowIconified(WindowEvent obj)


public void windowDeiconified(WindowEvent obj)

ANS:-public void windowGainedFocus(WindowEvent obj)


public void windowLostFocus(WindowEvent obj) option C.

280.What correction should be done in given code to generate following output


import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code=listevent width=400 height=400>
</applet>*/
public class listevent extends Applet implements ActionListener
{
List l=new List(10);
String msg=" ";
public void init()
{
l.add("AJP");
l.add("OMD");
l.add("MAN");
add(l);
l.addActionListener(this);
}
public void itemStateChanged(ItemEvent e)
{
msg=e.getActionCommand();
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg,100,100);
}
}
T2A_7054.jpeg Y1O
A.Instead of itemStateChanged method it should be actionPerformed(ActionEvent e).

B.Instead of itemStateChanged method it should be itemChanged(ItemEvent e).

C. The list should be registered with ItemEvent

D.No change should be done

ANS:-Instead of itemStateChanged method it should be actionPerformed(ActionEvent e). option A.

281.What will be the output of following prgram?


import java.awt.*;
import java.awt.event.*;
class Sample extends Frame
{
Sample(String title)
{
super(title);
addWindowListener(new WindowAdapter());
setSize(400,400);
setVisible(true);
}
public void windowClosing(WindowEvent we)
{
setVisible(false);
System.exit(0);
}
public static void main(String args[])
{
Sample f=new Sample("Window Example");
}
}
A.A frame window which can not be closed.

B.Program will not compile as it contains syntax errors.

C.A frame window which will be displayed and keep on closing automatically.
D.A frame window which can be closed.

ANS:-A frame window which can be closed. option D.

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.

283.Adapter classes are similar to EventListener interfaces?A.True


B.False
C.None of this
D.All of this
ANS:-True option A.

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.

287.What will be the output of following code?


import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class ButtonDemo1 extends Applet implements ActionListener
{
String msg=" ";
Button b1,b2,b3;
public void init()
{
b1=new Button("Red");
b2=new Button("Green");
b3=new Button("Blue");
add(b1);
add(b2);
add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String str=ae.getActionCommand();
if (str.equals("Red"))
{
setBackground(Color.red);
}
else if (str.equals("Green"))
{
setBackground(Color.green);

}
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>*/
Y2
A.T2A_5687_a1.jpeg
B.T2A_5687_a2.jpeg
C.T2A_5687_a3.jpeg
D.T2A_5687_a4.jpeg
ANS:-46o1 option A.

288.What will be the output of following code?


import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class ButtonDemo1 extends Applet implements ActionListener
{
String msg=" ";
Button b1,b2,b3;
public void init()
{
b1=new Button("Red");
b2=new Button("Green");
b3=new Button("Blue");
add(b1);
add(b2);
add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String str=ae.getActionCommand();
if (str.equals("Red"))
{
setBackground(Color.red);
}
else if (str.equals("Green"))
{
setBackground(Color.green);

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

290.Consider the following program


What will be displayed in the output?

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

/*<applet code="InnerClassDemo" width=250 height=200>


</applet>*/
public class InnerClassDemo extends Applet
{
public void init()
{
addMouseListener(new MyMouseAdapter());
}

class MyMouseAdapter extends MouseAdapter


{

public void mouseClicked(MouseEvent me)


{
showStatus("Mouse clicked ");

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

291.Which Listener is required to handle event.


T2A_480.jpeg Y1
A.ItemListener
B.ActionListener
C.TextListener
D.None of the above
ANS:-ActionListener option B.

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.*;

/*<applet code="MouseEventDemo" width=250 height=200>


</applet>*/
public class MouseEventDemo extends Applet implements ____________
{ String msg="";
int mouseX=0 ,mouseY=0;
public void init()
{
add____________ (this);
}

public void mouseDragged(MouseEvent me)


{
mouseX= me.getX();
mouseY= me.getY();
msg="*";
showStatus("Dragging mouse at "+ mouseX + ","+mouseY);
repaint();
}

public void mouseMoved(MouseEvent me)


{
showStatus("Moving mouse at "+ me.getX()+","+me.getY());
}

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

296.Which method ******** is missing in following program.


import java.awt.*;
import java.awt.event.*;

class FrameDemo extends Frame


{
FrameDemo()
{
addWindowListener(new MyWindowAdapter());
}

public static void main(String args[])


{
FrameDemo f=new FrameDemo();
f.setSize(100,200);
f.setTitle("Frame window");
f.setVisible(true);
}

public void paint(Graphics g)


{
g.drawString("this is a frame",100,200);
}

class MyWindowAdapter extends WindowAdapter


{
public void _________ (WindowEvent we)
{
System.exit(0);
}
}
}
A.closeWindow()
B.windowClosing()
C.minimizeWindow()
D.maximizeWindow()
ANS:-windowClosing() 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.

298.What is an event in delegation event model used by Java programming language?


A.An event is an object that describes a state change in a source.

B.An event is an object that describes a state change in processing.

C.An event is an object that describes any change by the user and system

D.An event is a class used for defining object, to create events.

ANS:-An event is an object that describes a state change in a source. option A.

299.Select Proper code for given output.


T2A_8664.jpeg Y1
A.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

//<applet code=JCombobox1.class width=300 height=100>

public class JCombobox1 extends JApplet implements ItemListener


{
JLabel jl;
ImageIcon yahoo;

public void init()


{

Container cp=getContentPane();
cp.setLayout(new FlowLayout());

JComboBox jc= new JComboBox();

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

public void itemStateChanged(ItemEvent ie)


{
String s=(String)ie.getItem();
jl.setText(s);
}
}

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

//<applet code=JCombobox1.class width=300 height=100></applet>

public class JCombobox1 extends JApplet implements ItemListener


{

JLabel jl;
ImageIcon yahoo;

public void init()


{
cp.setLayout(new FlowLayout());

JComboBox jc= new JComboBox();


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

public void itemStateChanged(ItemEvent ie)


{
String s=(String)ie.getItem();
jl.setText(s);
}
}

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

//<applet code=JCombobox1.class width=300 height=100></applet>

public class JCombobox1 extends JApplet implements ItemListener


{

JLabel jl;
ImageIcon yahoo;

public void init()


{

Container cp=getContentPane();
cp.setLayout(new FlowLayout());

JComboBox jc= new JComboBox();

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

public void itemStateChanged(ItemEvent ie)


{
String s=(String)ie.getItem();
jl.setText(s);
}
}

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

//<applet code=JCombobox1.class width=300 height=100></applet>

public class JCombobox1 extends JApplet implements ItemListener


{

JLabel jl;
ImageIcon yahoo;

public void init()


{

Container cp=getContentPane();
cp.setLayout(new FlowLayout());

JComboBox jc= new JComboBox();

jc.addItem("Yahoo mail");
jc.addItem("gmail");

jc.addItemListener(this);
cp.add(jc);

yahoo=new ImageIcon("Hydrangeas1.jpg");
cp.add(jl);
}

public void itemStateChanged(ItemEvent ie)


{
String s=(String)ie.getItem();
jl.setText(s);
}
}
ANS:-
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

//<applet code=JCombobox1.class width=300 height=100></applet>

public class JCombobox1 extends JApplet implements ItemListener


{

JLabel jl;
ImageIcon yahoo;

public void init()


{

Container cp=getContentPane();
cp.setLayout(new FlowLayout());

JComboBox jc= new JComboBox();

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

public void itemStateChanged(ItemEvent ie)


{
String s=(String)ie.getItem();
jl.setText(s);
}
} option C.

300.For the following code which interface is use.


importjava.awt.event.*;
import java.awt.*;
importjava.applet.*;
public class checkbackg extends Applet implements __________________
{
Checkbox m1,m2,m3;
public void init()
{
m1=new Checkbox("Windows xp");
m2=new Checkbox("Windows 7");
m3=new Checkbox("Windows vista");
add(m1);
add(m2);
add(m3);
m1.addItemListener(this);
m2.addItemListener(this);
}

public void itemStateChanged(ItemEvent ie)


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

A.actionListener
B.iteminterface
C.itemStateChanged
D.ItemListener
ANS:-ItemListener option D.

301.The following program will display _____________________

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.

303.complete Following server code for accepting client request?


import java.io.*;
import java.net.*;
public class MyServer {
public static void main(String[] args){
try{
ServerSocket ss=new ServerSocket(6666);
_________________________________________
DataInputStream dis=new DataInputStream(s.getInputStream());
String str=(String)dis.readUTF();
System.out.println("message= "+str);
ss.close();
}catch(Exception e){System.out.println(e);}
}
}

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.

304.What is complie time error in following program?


import java.net.*;
class InetAddressInstanceMethodDemo
{
public static void main(String args[]) throws UnknownHostException
{
InetAddress address = InetAddress.getLocalHost();
System.out.println(address.equals(address));
System.out.println(address.getAddress());
System.out.println(address.getHostAddress());
System.out.println(address.getHost());
System.out.println(address.isMulticastAddress());
System.out.println(address.toString());
}
}
A.InetAddressInstanceMethodDemo.java:11: error: cannot find symbol
System.out.println(address.isMulticastAddress());
^
symbol: method isMulticastAddress()
location: variable address of type InetAddress
1 error

B.InetAddressInstanceMethodDemo.java:8: error: cannot find symbol


System.out.println(address.getAddress());
^
symbol: method getAddress()
location: variable address of type InetAddress
1 error

C.InetAddressInstanceMethodDemo.java:10: error: cannot find symbol


System.out.println(address.getHost());
^
symbol: method getHost()
location: variable address of type InetAddress
1 error

D.No compile time error

ANS:-InetAddressInstanceMethodDemo.java:10: error: cannot find symbol


System.out.println(address.getHost());
^
symbol: method getHost()
location: variable address of type InetAddress
1 error option C.

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.

307.TCP and UDPs_______.


A.protocol
B.family
C.A & B
D.None of this
ANS:-A & B option C.

308.select proper method to compile & run the code:

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

B.C:\jdk1.2.2\bin>java sample C:\jdk1.2.2\bin>Appletviewer sample.java

C.C:\jdk1.2.2\bin>javac Demo.java
sample.java

D.C:\jdk1.2.2\bin>java sample.java

ANS:-C:\jdk1.2.2\bin>java sample option A.

309.Consider the following program


Fill in the blanks.
import java.net.*;
import java.io.*;

public class URLTest


{
public static void main(String args[]) throws MalformedURLException
{
_______ ob = new _________________("http://www.msbte.com/download");
System.out.println("Protocol:"+ ob.getProtocol());
System.out.println("Port:"+ ob.getPort());
System.out.println("Host:"+ ob.getHost());
System.out.println("File:"+ ob.getFile());
}
}
A.URLConnection,URL
B.URLConnection,URLConnection C.URL,URL
D.URL,URLConnection ANS:-URL,URL
option C.

310.Select the method to retrieve the computer name & IP address.


import java.net.*;
class MyInet1
{
public static void main(String args[])throws UnknownHostException
{
InetAddress i=InetAddress.getLocalHost();
System.out.println("Computer Name="+___________);
System.out.println("IPAddress="+_________);
}
}

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.

311What is longform of URL?


A.Uniform Resource Locator
B.Uniform Resource Latch
C.Universal Resource Latch
D.Universal Resource Locator
ANS:-Uniform Resource Locator option A.

312.For the following code select the missing statement

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.

314.Which Statement is given the error in the following code


import java.sql.*;
class dataI
{
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();
s.executeUpdate("Insert into Table1 values('hhh',12)");
if(n==1)
{
System.out.println("Record inserted ");
con.close();
}
}
catch(Exception e)
{
System.out.println("not Inserted"+e);
}
}
}

A.Statement Object creation


B.Sql Query Statement and variable 'if' statement
C.Connection Statement
D.Table Statement
ANS:-Sql Query Statement and variable 'if' statement 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.

316.Which of the following is correct about DriverManager.registerDriver() method call?

A.This method is used to register the database driver.

B.This static method is used in case you are using a non-JDK compliant JVM, such as the one provided by
Microsoft.

C.Both of the above.

D.None of the above.

ANS:-Both of the above. option C.

317.What will happen if resultSet() is not present in JDBC?


A.Database does not get update
B.Database does not Open
C.Database does not Close
D.None of the above
ANS:-None of the above option D.

318.Find out error from following code.


import java.sql.*;
public class Updatedbase
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:data2");
Statement st=con.createStatement();
resultSet rs=st.executeQuery("select * from college");

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

B.String b = "delete from emp where ID=1";


PreparedStatement ps=con.prepareStatement(b);
ps.Update();

C.String b = "delete from emp where ID=1";


PreparedStatement ps=con.prepareStatement(b);
ps.executeQuery();

D.String b = "drop table from emp where ID=1";


PreparedStatement ps=con.prepareStatement(b);
ps.executeUpdate();

ANS:-String b = "delete from emp where ID=1";


PreparedStatement ps=con.prepareStatement(b);
ps.executeUpdate(); option A.

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.

321.Observe following code and find out missing statement.


import java.io.*;
import java.sql.*;
class updatdb
{public static void main(String args[])
{try
{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:stud");
Statement s = con.createStatement();
int r = s.executeUpdate("update stud set name=priti where name='preety'");
System.out.println("No. of row updated:"+r)
ResultSet rs=s.executeQuery("select * from stud");
while(rs.next())
{System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getInt(3));
}
con.close();
}
catch(Exception e){ }
}
}
A.Semicolon Missing
B.comma missing
C.Single quotes Missing
D.Package Missing
ANS:-Semicolon Missing option A.

322.Consider the following program.


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

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

B.PreparedStatement ps=con.prepareStatement("insert into employee values(?,?)");


ps.setString(2,"amol");

C.PreparedStatement ps=con.prepareStatement("insert into employee values(?,?)");


int i=ps.executeUpdate();

D.PreparedStatement ps=con.prepareStatement("insert into employee


values(?,?)");
ps.setInt(1,200);
ps.setString(2,"amol");

ANS:-option A.

323.How many values are need to insert for prepareStatement paprameter?


A.1
B.2
C.3
D.4
ANS:-3 option C.

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.

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


public class SimpleDemo
{ public static void main(String[] args)
{
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
try
{ String jdbcurl="jdbc:mysql://localhost:3306/test";
con=DriverManager.getConnection(jdbcurl, "root", "root");
System.out.println("Connection established");
stmt=con.createStatement();
rs=stmt.executeQuery("select * from emp");
System.out.println("Empid \t Emap name \t City \t Salary");
while(rs.next())
{
System.out.print(rs.getInt(1)+"\t");
System.out.print(rs.getString(2)+"\t");
System.out.print(rs.getString(3)+"\t");
System.out.print(rs.getFloat(4));
System.out.println();
}
}
catch(ClassNotFoundException e) { e.printStackTrace();}
catch(SQLException e) {e.printStackTrace()}
finally
{try {
rs.close();
stmt.close();
con.close();
}
catch(Exception e){}
}} }
A.Missing package statement
B.Driver statement Missing
C.Missing semicolon
D.All of the above
ANS:-All of the above option D.

326.Consider the following program.


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

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.

328.What is output of following code


import java.sql.*;
import java.io.*;

public class StudentTableInsert


{
public static void main(String args[])
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String Name;
int Age;

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver Loaded");
String URL = "jdbc:odbc:StudentDatabase";

Connection con = DriverManager.getConnection(URL);


System.out.println("Connection to database created.");

Statement state = con.createStatement();


System.out.println("Statement Object Created.");
}
}Driver Loaded
A.Driver Loaded Connection to database created
B.Driver Loaded
C.Connection to database created Statement Object created
D.Driver Loaded Statement Object created
ANS:-Driver Loaded Connection to database created
Statement Object created option C.

329.Write a comment on following method


Statement state = con.createStatement()
A.to empty the log
B.creates statement object and returns it as the return value.
C.to prepare the statement
D.creating url
ANS:-creates statement object and returns it as the return value. option B.

330.Consider the following program.


What should be the correction done in the program to get correct output?
import java.sql.*;
class Ddemo1
{
public static void main(String args[]) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection();
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.DriverManager.getConnection()
B.Main
C.Class.for()
D.Connection String
ANS:-DriverManager.getConnection() option A.

331.Consider following program.What should be the output.


import java.sql.*;

public class Select_Demo


{
public static void main(String[] argv) throws Exception
{

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.

332.In following Java program fill statement showing ________________.


Select any one option fro given options
import java.sql.*;
class Type1
{
public static void main(String[] args)
{try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:dsn3";
Connection conn = ____________________
System.out.println("successfully connected");
}catch(Exception e)
{System.out.println(e); }
}
}

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

B.sql = ''SELECT* FROM Employees"; Resultset rs = stmt. exectureQuery (sql);while


(rs.next()) { int id = rs. getInt("id"); int age = rs. getInt ("age"); String first=
rs.getstring ("first"); String last = rs.getstring ("last") //Display values

C.sql = ''SELECT* FROM Employees"; Resultset rs = stmt. exectureQuery (sql);while


(rs.next()) { int id = rs. getInt("id"); int age = rs. getInt ("age"); String first=
rs.getstring ("first"); String last = rs.getstring ("last") //Display values

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 = "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"); option A.

334.Provides information about occurance of event___________.


A.javax.sql.Connection
B.javax.sql.ConnectionEvent
C.javax.sql.ConnectEvent
D.javax.sql.Event
ANS:-javax.sql.ConnectionEvent option B.

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

336.Consider the following program.


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

public class dbAccess


{
public static void main(String[] args)throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:ab", "",
"");
String s1="update Table1 set name1='akash' where
rollno='1'";
s.executeUpdate(s1);
s.close();
conn.close();

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

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.Statement s=c.createStatement();
B.Statement1 s=c.createStatement();
C.Statement s=c.deleteStatement();
D.Statement s=c.selectStatement();
ANS:-Statement s=c.createStatement(); option A.

338.To establish the database connection , following are the sequence.


A.
2) import JDBC package
3)Database URL formulation
4) Create Connection Object

B. 1) import JDBC package


2) Register JDBC Driver
3)Database URL formulation
4) Create Connection Object

C. 1) import JDBC package


2) Create Connection Object
3) Database URL formulation
4) Register JDBC Driver•

D. 1) import JDBC package


2) Register JDBC Driver
3) Create Connection Object
4) Database URL formulation

ANS:-1) import JDBC package


2) Register JDBC Driver
3)Database URL formulation
4) Create Connection Object option B.

339.Consider the following program.


What should be the correction done in the program to get correct output?
import java.sql.*;
class login1
{
public static void main(String args[])
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn= DriverManager.getConnection("jdbc:odbc:mcm");
Statement stmt = conn.createStatement()
ResultSet rs= stmt.executeQuery("select password from login where
login='"+args[0]+"'");
if(rs.next())
{
if(args[1].equals(rs.getString(1)))
System.out.println("Login succesfully");
else
System.out.println("Wrong Password");
}
else
System.out.println("Login Name Not Found");
rs.close();
stmt.close();
conn.close();

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

340.Select correct statement for connect mysql database?


a) TYPE_FORWARD_ONLY: creates a nonscrollable result set, that is, one in which the cursor moves only
forward

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.

341.What will the following statement display?


select Student.* from Student, Course, Enrollment
where Student.ssn = Enrollment.ssn and Enrollment.courseId
and Course.title = 'Java Programming' and Student.lastName like 'S%';

A.The statement displays all students.

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.

342._________ requires network support.


A.Native-API driver
B.Network Protocol driver
C.JDBC-ODBC bridge driver
D.Thin driver
ANS:- Network Protocol driver Option B.

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.

344.Output of Following Program


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloServlet extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = req.getWriter();
out.println("<HTML>\n"
+"<HEAD><TITLE>Hello</TITLE></HEAD>\n" +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1>Hello World</H1>\n" +
"</BODY></HTML>");
}
}

A."HelloWorld" will display at Client side

B."HelloWorld" will display at Client side


fill the backgroud with color "#FDF5E6"

C.Compilation Error

D.None of Above

ANS:-Compilation Error option C.

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.

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


public class HelloWorld extends HttpServlet {

private String message;

public void init() throws ServletException


{
message = "Hello World";
}

public void doGet(HttpServletRequest request,


HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");

PrintWriter out = response.getWriter();


out.println("<h1>" + message + "</h1>");
}

public void destroy()


{
}
}
A.Missing semicolon
B.Missing package statement
C.Missing initialization
D.None of the above
ANS:-Missing package statement option B.

347.Choose missing statment for the following code


public class Hello extends HttpServlet
{ public void service(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
response.setContenetType("text/html");
printWriter out=response.getWriter();
BufferReader in=request.getReader();
out.println("<HTML>");
out.println("<HEAD><TITLE>Hello</TITLE></HEAD>");
out.println("<BODY>");
if (request.getParameter("name")==null)
out.println("Hello wordl");
out.println("</BODY></HTML>");
}
}

A.import javax.servlet.; import javax.servlet.http.*;

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

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

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

ANS:-import java.io.*; import javax.servlet.; import javax.servlet.http.*; option C.

348.Which statement is missing to display the image on Servlet


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");
PrintWriter pw=res.getWriter();
pw.println("<html>");

pw.println("</html>");
}
}

A.pw.println("<img src='Sunset.jpg' width=600 height=800>");

B.<img src='Sunset.jpg' width=600 height=800>

C.Nothing is missing.

D.pw.println("<img src='Sunset.jpg' width=600


height=800>");

ANS:-option A.

349.Choose missing statements in following code from given options.


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

public class HelloServlet extends HttpServlet


{

public void service(HttpServletRequest request,HttpServletResponse response)throws


ServletException,IOException
{
PrintWriter pw=response.getWriter();
pw.println("<B>Hello Servlet");
pw.close();
}
}
A.response.setContentType("text/html");
B.import javax.servlet.http.*;
C.Both (i) and (iii)
D.None of these
ANS:-Both (i) and (iii) option C.

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("text/html"); option A.

351.Select missing lines in following code to get ouput .


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

public class First implements Servlet{


ServletConfig config=null;

public void init(ServletConfig config){


this.config=config;
System.out.println("servlet is initialized");
}
public void service(ServletRequest req,ServletResponse res)
throws IOException,ServletException{
res.setContentType("text/html");

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.

C. The getRequestDispatcher(String URL) is defined in both ServletContext and HttpServletRequest


method

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.<%= Math.sqrt(25) >


B.<% Math.sqrt(25) %>
C.Math.sqrt(25)
D. <%= sqrt(25) %>
ANS:- amp;lt;%= sqrt(25) %> option D.

354.select the correct JSP code to display the following output


T5A_7500.jpeg Y1

A.<html>
<head><title>Hello World</title></head>
<body>
Hello World!<br/>

out.println("Your IP address is " + request.getRemoteAddr());

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>
<head><title>Hello World</title></head>
<body>
Hello World!<br/>
<%
out.println("Your IP address is " + request.getRemoteAddr());
%>
</body>
</html> option C.

355.Which of the following statement is reuired in service()method


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class namepass extends GenericServlet
{
public void service(_______________________________________)throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String name=request.getParameter("n1");
String pass=request.getParameter("n2");
out.println("<html>");
out.println("<body>");
out.println("<head>");
out.println("<title>Hello World!</title>");
out.println("</head>");
out.println("<h1>name:</h1>"+name);
out.println("<h1>pass:</h1>"+pass);
out.println("</body>");
out.println("</html>");
out.close();
}
}
A.HttpServletRequest request,HttpServletResponse response
B.ServletRequest request, ServletResponse response
C.HttpServletResponse response ,HttpServletRequest request
D.ServletResponse response ,ServletRequest request
ANS:-ServletRequest request, ServletResponse response option B.

356.Consider the following.Find missing statement in code


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet {
private String message;
public void init() throws ServletException
{
message = "Hello World";
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
PrintWriter out = response.getWriter();
out.println("<h1>" + message + "</h1>");
}
public void destroy()
{
// do nothing.
}
}
A.response.println("text/html");
B.import java.awt.*;
C.response.redirect("text/html");
D.response.setContentType("text/html");
ANS:-response.setContentType("text/html"); option D.

357.________ are JSP code fragments embedded within <% ...%> tags.
A.Scriptlets
B.Applets
C.Japplets
D.none of the above
ANS:-Scriptlets option A.

358.What should we write at the place of _________ to get proper output


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class example extends ___________
{
public void doGet(HttpServletRequest request, HttpServletResponse response)throws IOException,
ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
// print out cookies
String name = request.getParameter("t1");
String value = request.getParameter("t2");
Cookie c = new Cookie(name, value);
response.addCookie(c);
String n1 = c.getName();
String v1 = c.getValue();
out.println("<h3> The Name Of Cookie is:</h3>"+n1);
out.println("<h3> The Value Of Cookie is:</h3>"+v1);
}
}
A.HttpServlet
B.HttpResponse
C.HttpRequest
D.All of the above
ANS:-HttpServlet option A.

359.Find the Syntactally Correct Statement.


A.protected void doPost(HttpServletRequest request HttpServletResponse response) throws
ServletException IOException

B.public void doGet(HttpServletRequest request, HttpServletResponse response) throws


ServletException, IOException
C.a & b Both are Correct Sentence

D.a & b Both Wrong Sentence

ANS:-public void doGet(HttpServletRequest request, HttpServletResponse response) throws


ServletException, IOException option B.

360.Choose missing packages in following code from given options.

public class session1 extends HttpServlet


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

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

B.import java.Vector.* ; import java.Thread.*; import javax.servlet.*;

C. import javax.servlet.http.*; import java.String.*; import java.Vector;

D. import javax.servlet.http.*; import java.Thread.*; import javax.Client.*;

ANS:-import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; 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.*;

public class Mathservlet extends HttpServlet


{
public void (HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><h1>Table Example</h1>");
out.println("<table border = 1>");
out.println("<tr><td> Number </td> <td> Result
<td></tr>");
for(int i=1;1<10;i++)
{
out.println("<tr><td>"+ i + "\t" + Math.pow(2,i) +
"<td><tr>");
}
out.println("</table></html>");
printwriter.close();
}
}
A.service()
B.delete()
C.destroy()
D.init()
ANS:-service() option A.

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>

B.<tr> <td> phone : </td> <td><input type = textbox size "25"


value = "" ></td> </tr>

C.<tr> <td> Employee : </td> <td><input type = textbox name


="Employee' size "25" value = "" ></td> </tr>
D.<tr> <td> phone : </td> <td><input type = textbox name =phone' size
"25" value = "" ></td> </tr>

ANS:-.<tr> <td> phone : </td>


<td><input type = textbox name =phone' size "25"
value = "" ></td> </tr> option D.

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.

364.Analyse the following code and find out error.


import java.io.*;
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("MyCookie",data);
response.addCookie();
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<B>MyCookie has been set to "+data);
pw.close();
}
}
A.Error is in statement in which Cookie object is created
B.Error is in statement in which Cookie is added
C.both a and b
D.No error
ANS:-Error is in statement in which Cookie is added option B.

365.Choose missing statements in following code from given options.


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

public class Hello extends HttpServlet


{
public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter pw=___________________ ;
pw.println("<h2> Hello World...");
pw.close();
}
}
A.new PrintWriter()
B.response.getWriter()
C.res.getWriter()
D.req.getPrintWriter()
ANS:-res.getWriter() option C.
366.Consider following code.Fill _____________statement in following code from option given below
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class CookieExample extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)


throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Cookie[] cookies = request.getCookies();
for (int i = 0; i < cookies.length; i++) {
Cookie c = cookies[i];
String name = c.getName();
String value = c.getValue();
out.println(name + " = " + value);
}

String name = ______________________


if (name != null && name.length() > 0) {
String value = request.getParameter("cookieValue");
Cookie c = new Cookie(name, value);
response.addCookie(c);
}
}
}

A.request.getParameter("cookieName");
B.response.setContentType("cookieName");
C.request.getParameter(cookies);
D.response.getWriter();
ANS:-request.getParameter("cookieName"); option A.

367.write missing statement in bellow code


import java.io*;
import javax.servlet.*;
public class Welcome servlet extends GenericServlet
{
public void service(Servlet request,Servlet Response) throws ServletException,IOException
{
response.setContentType("text/html);
printwriter pw=response.getwriter();
pw.println("<B>WELCOME TO SERVLET!");
__________________________
}
}
A.response.setContentType("text/html);
B.printwriter pw=response.getwriter();
C.printwriter pw=response.get();
D.pw.close();
ANS:-pw.close(); option D.

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.

370.The _______________method on the session object is used to remove a set attribute.


A.removeAllValues()
B.removeAttribute("attribute_Name")
C.removeAttributes()
D.letResponse
ANS:-removeAttribute("attribute_Name") option B.

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.

372.What is Output of following program


//client
<html>
<head></head><body><form name =sd
action="http://127.0.0.1:8080/examples/servlet/sd1">
Name: <input type=text name="name1"value="">
<input type ="submit" value="login">

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