0% found this document useful (0 votes)
61 views55 pages

UNIT 01 - Abstract Windowing Toolkit (AWT)

This document contains 60 multiple choice questions about the Abstract Window Toolkit (AWT) in Java. It covers topics like common AWT components like Frame, Panel, Container, basic event handling using Listeners, layout managers like FlowLayout and BorderLayout, and graphics drawing methods. The questions test knowledge of AWT concepts like which classes are containers that can hold other components, the default layout managers for different containers, properties and methods of common components like Buttons, Labels and TextFields.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views55 pages

UNIT 01 - Abstract Windowing Toolkit (AWT)

This document contains 60 multiple choice questions about the Abstract Window Toolkit (AWT) in Java. It covers topics like common AWT components like Frame, Panel, Container, basic event handling using Listeners, layout managers like FlowLayout and BorderLayout, and graphics drawing methods. The questions test knowledge of AWT concepts like which classes are containers that can hold other components, the default layout managers for different containers, properties and methods of common components like Buttons, Labels and TextFields.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

UNIT 01 – Abstract Windowing Toolkit (AWT)

Q. 1. Give the abbreviation of AWT ?


(a) Applet Windowing Toolkit
(b) Abstract Windowing Toolkit
(c) Absolute Windowing Toolkit
(d) None of the above
Answer: b

Q. 2 Which is the container that contain title bar and can have MenuBars. It can have
other components like button, textfield etc.?
(a) Panel
(b) Frame
(c) Window
(d) Container
Answer: b

Q. 3 Which is a component in AWT that can contain another components like buttons,
textfields, labels etc.?
(a) Window
(b) Container
(c) Panel
(d) Frame
Answer:b

Q. 4 AWT is used for GUI programming in java?


(a) True
(b) False
Answer:a

Q. 5 Which class provides many methods for graphics programming?


(a) java.awt
(b) java.Graphics
(c) java.awt.Graphics
(d) None of the above
Answer:c

Q. 6 These two ways are used to create a Frame


By creating the object of Frame class (association)
By extending Frame class (inheritance)
(a) True
(b) False
Answer:a
Q. 7 Which is the container that doesn't contain titlebar and MenuBars. It can have other
components like Bbutton, textfield etc?
(a) Window
(b) Frame
(c) Panel
(d) Container
Answer:c

Q. 8 How many types of controls does AWT supports these controls are subclasses of
component?
(a) 7
(b) 6
(c) 5
(d) 8
Answer:a

Q. 9 Which are passive controls that do not support any interaction with the user?
(a) Choice
(b) List
(c) Labels
(d) Checkbox
Answer:c

Q. 10 By which method You can set or change the text in a Label ?


(a) setText()
(b) getText()
(c) Both A & B
(d) None of the above
Answer:a

Q. 11 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
Answer:b

Q. 12 Which object can be constructed to show any number of choices in the visible
window?
(a) Labels
(b) Choice
(c) List
(d) Checkbox
Answer:c
Q. 13 Which is used to store data and partial results, as well as to perform dynamic
linking, return values for methods, and dispatch exceptions?

(a) Window
(b) Panel
(c) Frame
(d) Container
Answer:c

Q. 14 The following way is used to create a frame is by creating the object of Frame class?
(a) inheritance
(b) association
(c) Both A & B
(d) None of the above
Answer: c

Q. 15 AWT more powerful components like tables, lists, scroll panes, color chooser, tabbed
pane etc.?
(a) True
(b) False
Answer: a

Q. 16 These four methods commonly used in?


(i) public void add(Component c)
(ii) public void setSize(int width,int height)
(iii) public void setLayout(LayoutManager m)
(iv) public void setVisible(boolean)

(a) Graphics class


(b) Component class
(c) Both A & B
(d) None of the above
Answer: b

Q. 17 In Graphics class which method is used to draws a rectangle with the specified width and
height?
(a) public void drawRect(int x, int y, int width, int height)
(b) public abstract void fillRect(int x, int y, int width, int height)
(c) public abstract void drawLine(int x1, int y1, int x2, int y2)
(d) public abstract void drawOval(int x, int y, int width, int height)
Answer: b

Q. 18 Implement the Listener interface and overrides its methods is required to perform in event
handling?
(a) True
(b) False
Answer: a
Q. 19 Public class MenuBar extends .
(a) MenuComponent
(b) MenuContainer
(c) ComponentMenu
(d) MenuBar
Answer: a

Q. 20. Which of the following is true about AWT and Swing components?
(a) AWT components creates a process where as swing components creates a thread
(b) AWT components creates a thread whereas swing components creates a process
(c) Both AWT and Swing components creates a process
(d) Both AWT and swing components creates a thread
Answer: c

Q. 21 Panel is defined as .
(a) The Panel class is a concrete subclass of Container.
(b) A Panel is a window that does not contain titlebar, menubar and border.
(c) Panel is a superclass of Applet.
(d) All of the above.
Answer: d

Q. 22. What is API?


(a) Application Programming Interchange
(b) Application Programming Interaction
(c) Application Programming Interface
(d) None of these
Answer: c

Q. 23.What is default layout for Dialog?


(a) FlowLayout
(b) GridLayout
(c) CardLayout
(d) BorderLayout
Answer: a

Q. 24 Which method is used to count the number of items is the List.


(a) getItem( )
(b) getSelectedItem( )
(c) getItemCount( )
(d) getCount( )
Answer: c
Q. 25 The correct hierarchy for Panel is
(a) Component – Container – Window – Panel
(b) Component – Container – Applet – Panel
(c) Component – Container – Panel
(d) Container – Component – Panel
Answer: c

Q. 26 Which is the correct constructor of GridLayout.


(a) GridLayout(int a)
(b) GridLayout(int num_rows, int num_columns)
(c) GridLayout(int rows, int cols, int vert)
(d) GridLayout(int hor)
Answer: b

Q. 27 What are the types of DialogBox?


(a) Modal DialogBox
(b) Modal and Modeless DialogBox
(c) Modam
(d) None of the above
Answer: b

Q. 28 In the give constructor what third parameter indicates :


ScrollBar s = new ScrollBar(0,10,20,0,1000);
(a) size of thumb
(b) minimum value
(c) Increment value
(d) Initial Value
Answer: a

Q. 29 Which class is used to represent a single line textbox with password character
facility?
(a) TextField
(b) TextArea
(c) Label
(d) Checkbox
Answer: a

Q. 30 To set the title to the Frame window method is used.


(a) void setTitle(String str)
(b) void setText(String str)
(c) void settitle(String str)
(d) None of the above
Answer: a
Q. 31 Suppose a Panel is added to a Frame and a Button is added to the Panel. If the
Frame’s font is set to 12 point Times New Roman, the panel’s font is set 10 points Times
New Roman and the Button’s font is not set. What font will be used to display the
Button’s label?
(a) 12 point Times New Roman
(b) 11 point Times New Roman
(c) 10 point Times New Roman
(d) 9 point Times New Roman
Answer: c

Q. 32 Which of the following is true about FlowLayout?


(a) FlowLayout can use multiple rows if the horizontal space in the container is too small to
hold the component.
(b) FlowLayout is the default layout manager of panel and applet.
(c) It is the default layout manager for window.
(d) Both A & B.
Answer: d

Q. 33 Which of the method can be used to output a String in an Applet?


(a) display( )
(b) print( )
(c) drawString( )
(d) transient( )
Answer: c

Q. 34 positions are the components into 5 regions east, west, south, north, center.
(a) CardLayout
(b) BorderLayout
(c) GridLayout
(d) FlowLayout
Answer: b

Q. 37 Which component of AWT provides compact, multichoice, scrolling component?


(a) List
(b) Choice
(c) Panel
(d) TextArea
Answer: a

Q. 38 When there is a switching condition like ON or OFF, which control is used of


following?
(a) Button
(b) RadioButton
(c) ToggleButton
(d) TextField
Answer: c
Q. 39 Which method is used to set password character for a TextField?
(a) setPasswordCharacter( )
(b) setEchoChar( )
(c) setPassChar( )
(d) setEchoCharacter( )
Answer: b

Q. 40 The getContentPane( ) method is of which class?


(a) JApplet
(b) JFrame
(c) JButton
(d) None of these
Answer: d

Q. 41 Which class defines setSize( ) method?


(a) Frame
(b) Applet
(c) Component
(d) Panel
Answer: c

Q. 42 is a swing class that allows to enter a single line of text.


(a) TextField
(b) JTextField
(c) EditTextField
(d) TextArea
Answer: b

Q. 43 Which Text Component method is used to set a TextComponent to the read‐ only
state?
(a) Editable
(b) NonEditable
(c) setEchoChar
(d) setEditable
Answer:d

Q. 44 How would you set the color of graphics context called g to cyan?
(a) g.setColor(“cyan”);
(b) g.setCurrentColor(cyan);
(c) g.setColor(“Color.cyan”);
(d) g.setColor(Color.cyan);
Answer: d
Q. 45 What is use of second parameter in given constructor Lable(String,int)
(a) specifies height of label
(b) specifies width of label in terms of pixel
(c) specifies the alignment of text in label in terms of pixel
(d) specifies width of label
Answer: c

Q. 46 The setBackground() method is part of which of the following class java.awt


package?
(a) Component
(b) Applet
(c) Object
(d) Graphics
Answer: a

Q. 47 What does the following line of code do? TextField tf = new TextField(10);
(a) will set 10 to TextField as its initial text.
(b) Will set the character capacity to 10
(c) Both A & B
(d) None of These
Answer: b

Q. 48 Frame is a standard window, which is of Window class from AWT hierarchy?


(a) Derived class / Subclass
(b) Base class / Super class
(c) Root class
(d) Family class
Answer: a

Q. 49 A is a passive AWT control that do not generate any event?


(a) Button
(b) RadioButton
(c) Choice
(d) Label
Answer: d

Q. 50 The default layout manager of Frame is .


(a) FlowLayout
(b) BorderLayout
(c) GridLayout
(d) CardLayout
Answer: b
Q. 51 Which method is used to check the status of checkbox?
(a) getStatus( )
(b) getState( )
(c) isChecked( )
(d) getChecked( )
Answer: b

Q. 52 Which of the following method is used to set a TextComponent to read‐ only


mode?
(a) Editable( )
(b) nonEditable( )
(c) setEchoChar( )
(d) setEditable( )
Answer: d

Q. 53 generates action events when an item is double‐ clicked.


(a) List
(b) Checkbox
(c) MenuItem
(d) TextField
Answer: c

Q. 54 Which of the following does not have its default layout as BorderLayout.
(a) Frame
(b) Dialog
(c) JApplet
(d) All of Above
Answer: d

Q. 55 Which of the following statement about GUI component is wrong?


(a) swing exists since the version 1.2 of the JDK
(b) AWT stands for Abstract Window Toolkit
(c) You cannot place AWT component on swing container.
(d) The AWT classes are deprecated.
Answer: c

Q. 56 Which of the following package is used for Graphical User Interface?


(a) java.applet
(b) java.awt
(c) java.awt.image
(d) java.io
Answer: b
Q. 57 What are the variables defined in Dimension?
(a) length and width
(b) height and length
(c) height and width
(d) None of these
Answer: c

Q. 58 Which AWT component is not editable?


(a) Button
(b) TextField
(c) FlowLayout
(d) Label
Answer: b

Q. 59 Current text of Label can be obtained using .


(a) setAlignment( )
(b) getAlignment( )
(c) getText( )
(d) setText( )
Answer: c

Q. 60 The method places a Menu m into the MenuBar mb.


(a) mb.addMenuItem(m)
(b) mb.addItem(m)
(c) mb.add(m)
(d) None of these
Answer: c

Q. 61 Which of these Components cannot be added to Frame?


(a) Label
(b) Button
(c) CheckboxGroup
(d) All of above
Answer: c

Q. 63 Which of these classes can be added to any Container class, using the add method
defined in Container class?
(a) Button
(b) CheckboxMenuItem
(c) Menu
(d) MenuBar
Answer: a
Q. 64 What is the use of setEchoChar( ) method?
(a) to set echo in symbol form
(b) to set char in symbol form
(c) Both A & B
(d) to create password in symbol form
Answer: c

Q. 65 method returns currently selected item in choice.


(a) getSelectedItem( )
(b) getSelectedElement( )
(c) getSelectedIndex( )
(d) getItem( )
Answer: a

Q. 66 Which statement with respect to inner class is true.


A. It is a way of logically grouping classes that are only used in one place.
B. It increases encapsulation.
C. It can lead to more readable and maintainable code.
(a) Only A statement is true.
(b) Only B statement is true.
(c) Only C statement is true.
(d) All A,B and C are true.
Answer: d

Q. 67 The default layout of Applet is .


(a) GridLayout
(b) CardLayout
(c) FlowLayout
(d) BorderLayout
Answer: c

Q. 68 Java Applets are used to create applications.


(a) Graphical
(b) user interactive
(c) Both A & B
(d) None of these
Answer: c
Q. 69 The following example shows the creation of applet
Import java.applet.*;
Import java.awt.*;
public class Main extends Applet
{
public void paint(Graphics g)
{
g.drawString("Welcome in Java Applet.",40,20);
}
}
a) Banner using Applet
b) Basic Applet
c) Display clock
d) None of the above
Answer: b

Q. 70. Which of the following is a valid HTML file to run an applet program store in
MyApplet.java file?
a) <APPLET CODE = "MyApplet.class"></APPLET>
b) <APPLET CODE="MyApplet.java" WIDTH=250 HEIGHT=200>
c) <applet code="MyApplet.class" width=250 height=200></applet>
d) <applet code="MyApplet" height =”250” width =”200”></applet>
Answer: c

Q. 71. Which of the following sets the frame, say frame to 300 pixels wide by 200 high?
a)frame.setSize( 300, 200 );
b) frame.setSize( 300, 200 );
c) frame.paint( 300, 200);
d)frame.setVisible(300, 200 );
Answer: a

Q. 72. Fill in the blanks so that this program displays a Frame:


Import java.awt.*;
public class microGUI
{
public static void main ( String[] args )
{
Frame frm = new ( );
frm. ( 150, 100 );
frm. ( true );
}
}
a) Form, setVisible, setOn
b) Frame, setSize, setVisible
c) Frame, setVisible, setSize
d) Window, setSize, paint
Answer: b.

Q. 73. What is the length of the application box made by this program?
Import java.awt.*;
Import java.applet.*;
public class myapplet extends Applet
{
public void paint(Graphics g)
{
g.drawString("A Simple Applet", 20, 20);
}
}
a)20
b) 50
c)100
d)System Dependent
Answer: a
Chapter 02 – Swings

Q. 1 The following specifies the advantages of It is lightweight.


It supports pluggable look and feel.
It follows MVC (Model View Controller) architecture.
(a) Swing
(b) AWT
(c) Both A & B
(d) None of the above
Answer: a

Q. 2 Swing is not a part of JFC (Java Foundation Classes) that is used to create GUI
application?
(a) True
(b) False
Answer:b

Q. 3 The Swing Component classes that are used in Encapsulates a mutually exclusive set of
buttons?
(a) AbstractButton
(b) ButtonGroup
(c) JButton
(d) ImageIcon
Answer: b

Q. 4 The Java Foundation Classes (JF(c) is a set of GUI components which simplify the
development of desktop applications?
(a) True
(b) False
Answer: a

Q. 5 Which package is used for import the swing components?


(a) java.swing
(b) java.awt
(c) javax.swing
(d) All of the above
Answer: c

Q. 6 The String parameter to JButton constructor .


(a) tell which region to put the JButton in.
(b) tells the color of the JButton.
(c) tells what text will appear on JButton.
(d) tells what should happen when JButton is pressed.
Answer: c
Q. 7 MVC architecture is
(a) Modelling – Visual – Controller
(b) Model – View – Controller
(c) Model – Viewable – Controller
(d) Many – View – Controller
Answer: b

Q. 8 Alignment constants of JLabel are the part of


a) SwingConstants interface
b) SwingConstants class
c) Swing class
d) Graphics class
Answer: a

Q. 9 In swing, Buttons are subclasses of which class?


(a) AbstractButton
(b) JButton
(c) Button
(d) JRadioButton
Answer: a

Q. 10 JTree class belongs to which package?


(a) java.awt
(b) java.applet
(c) java.swing
(d) javax.swing
Answer: d

Q. 11 Which component is swing represents data in row and columns?


(a) JTextArea
(b) JTable
(c) JPanel
(d) JtabbedPane
Answer: b

Q. 12 Which of the following is not constructor of JTree?


(a) JTree(TreeNode tn)
(b) JTree(Vector v)
(c) JTree(int x)
(d) none of the above
Answer: c
Q. 13 class used to create node in tree.
(a) TreeNode
(b) DefaultMutableNode
(c) DefaultMutableTreeNode
(d) Node
Answer: c

Q. 14 JTabbedPane class is present in which package?


(a) java.awt
(b) java.swing
(c) java.awt.swing
(d) javax.swing
Answer: d

Q. 15 What is purpose of JTree?


(a) To show data in form of parent and child nodes.
(b) To show data in list view.
(c) To show data in tabular form.
(d) To show data in menu‐ bar.
Answer: a

Q. 16 What is the use of : Container getContentPane( )


(a) Returns Container for a JDialog.
(b) Returns a ContentPane for Menu
(c) Returns a ContentPane for Applet
(d) None of the above
Answer: c

Q. 17 Which of the following method is not applicable for Button in swing.


(a) setDiableIcon( )
(b) setPressedIcon( )
(c) setSelectedIcon( )
(d) setRollOverIcon( )
Answer: c

Q. 18 Which of the following method is used to retrieve icon of JButton?


(a) Icon getIcon( )
(b) ImageIcon getImageIcon( )
(c) ImageIcon getIcon( )
(d) ImageIcon GetImageIcon( )
Answer: c
Q. 19. Which method is used to display icon on a Button?
a) setImage(ImageIcon i)
b) setIcon(ImageIcon i)
c) setPicture(ImageIcon i)
d) setImageIcon(ImageIcon i)
Answer: b

Q. 20. How will you set icon for the Jlabel?


a) Using Icon class directly
b) Using setIcon( ) method
c) Using makeIcon( ) method
d) It is not possible to set icon for JLabel
Answer: b

Q. 21. What is the return type of getText( ) method of JButton class?


a) void
b) String
c) Character array
d) There is no such method
Answer: b

Q. 22. The constructor JCheckBox(true, “YES”) suggests that


a) Checkbox is selected and displays the string “YES” on it.
b) Checkbox is deselected and displays the string “YES” on it.
c) Checkbox is selected and it shows the tick always on it.
d) There is no such constructor
Answer: d

Q. 23. How to make the group of Radio buttons?


a) Using ButtonGroup class
b) Using JButtonGroup class
c) Using JRadioButton
d) Using AbstractButton class
Answer: a

Q. 24. How to contents of whole vector into the JComboBox?


a) Use the constructor of JComboBox
b) Use method addItem( )
c) Use method addVector( )
d) Use method addValues( )
Answer: a

Q. 25. The scroll bar constants for scroll pane are defined in
a) Scrollbar class
b) ScrollPane class
c) ScrollPaneConstants interface
d) Component class
Answer: c
Q. 26. Which of the following constants shows scroll bars always?
a) HORIZONTAL_SCROLLBAR_ALWAYS
b) HORIZONTAL_SCROLLBAR_AS_NEEDED
c) HORIZONTAL_SCROLLBARS
d) HORIZONTAL_ALWAYS
Answer: a

Q. 27. Is it possible to add array of objects to trees? How?


a) Not possible
b) Yes, using its one of the forms of constructor
c) Yes, using the add( ) method
d) Yes, using the addItem( ) method
Answer: b

Q. 28. Find an error of following program


Import javax.swing.JFrame;
Import javax.swing.JTree;
import javax.swing.SwingUtilities;
Import javax.swing.tree.DefaultMutableTreeNode;
public class TreeExample extends JApplet
{
JTree tree;
public void init() {
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
DefaultMutableTreeNode vegetableNode = new DefaultMutableTreeNode("Vegetables");
DefaultMutableTreeNode fruitNode = new DefaultMutableTreeNode("Fruits");
root.add(vegetableNode);
root.add(fruitNode);
tree = new JTree();
add(tree);
}}
/*<applet code=”TreeExample” width=300 height=300>
</applet>*/
a) Error in statement in which JTree is created
b) Error in Applet code
c) No error
d) Error in Frame
Answer: a
Q. 29. Identify missing statement:
Import java.awt.*;
Import java.applet.*;
Import javax.swing.*;
public class Combo extends JApplet{
public void init()
{
Container c=getContentPane();
JComboBox jc=new JComboBox();
jc.addItem("AJP");
jc.addItem("STE")
jc.addItem("AMI"); jc.addItem("EDP");
}}
/*<applet code="Combo.class" height=200 width=200></applet>*/
a) Add(jc);
b) Jc.add(c);
c) c.add(jc);
d) Add(c);
Answer: c

Q. 30. The default orientation to display the progress bar is?


a) CENTER
b) TOP
c) HORIZONTAL
d) VERTICAL
Answer: c

Q. 31. MutableTreeNode is extends ................... interface


a) TreePath
b) TreeNode
c) DefaultMutableTreeNode
d) MutableTreeNode
Answer: b

Q. 32. Which two parameters are required for JTree constructor to create a tree?
a) Data array and Row Headings
b) Data array and Column Headings
c) Single data element and Column heading
d) Single data element and Row heading
Answer: b
Q. 33. How to create for Vector elements?
a) Pass vector as parameter for JTree
b) Use method addElements( ) for JTree class.
c) Use method addVector( ) method of JComponent class
d) It is not possible
03 – Event Handling

Q. 1. The Following steps are required to perform Implement the Listener interface and
overrides its methods Register the component with the Listener
(a) Exception Handling
(b) String Handling
(c) Event Handling
(d) None of the above
Answer: c

Q. 2 In which places can put the event handling code


(a) Same class
(b) Other class
(c) Annonymous class
(d) All mentioned above
Answer: d

Q. 3 Which package provides many event classes and Listener interfaces for event
handling?
(a) java.awt
(b) java.awt.Graphics
(c) java.awt.event
(d) None of the above
Answer: c

Q. 4 To use the ActionListener interface it must be implemented by a class there are


several ways to do that find in the following?
(a) Creating a new class
(b) using the class the graphical component
(c) an anonymous inner class
(d) All mentioned above
Answer: d

Q. 5 The ActionListener interface is not used for handling action events?


(a) True
(b) False
Answer: b

Q. 6 The ActionListener interface is used for handling action events, For example, it's
used by a
(a) JButton
(b) JCheckbox
(c) All of these
(d) JMenuItem
Answer: c
Q. 7 Which class is used for this Processing Method processActionEvent( )?
(a) Button,List,MenuItem
(b) Button,Checkbox,Choice
(c) Scrollbar,Component,Button
(d) None of the above
Answer: a

Q. 8 In Graphics class Which method is used to set the graphics current color to the
specified color?
(a) public abstract void setFont(Font font)
(b) public abstract void setColor(Color c)
(c) public abstract void drawString(String str, int x, int y)
(d) None of the above
Answer: b

Q. 9 Which of the following method is used to determine the type of adjustment event?
(a) getType( )
(b) getEventType( )
(c) getAdjustmentType( )
(d) getEventObjectType( )
Answer: c

Q. 10 TextField generates event.


(a) ActionEvent,ItemEvent
(b) ActionEvent, TextEvent
(c) ScrollEvent,TextEvent
(d) ActionEvent, ScrollEvent
Answer: b

Q. 11 void keyTyped(KeyEvent ke) called when a key on the keyboard is .


(a) pressed and then released.
(b) pressed
(c) released
(d) none of the above
Answer: a

Q. 12 Which event is generated when the position of scrollbar is changed?


(a) KeyEvent
(b) MouseEvent
(c) ItemEvent
(d) AdjustmentEvent
Answer: d
Q. 13 The signature for the registration method for a ActionEvent should be .
(a) public void addActionListener(ActionEvent L)
(b) public void setAction(ActionListener L)
(c) public void setActionListener(ActionListener L)
(d) public void addActionListener(ActionListener L)
Answer: d

Q. 14 Which of the following component generates ActionEvent?


(a) Window
(b) RadioButton
(c) ScrollBar
(d) None
Answer: d

Q. 15 method is used to register a keyboard event listener.


(a) KeyListener( )
(b) addKeyListener( )
(c) addKeyListenerEvent( )
(d) eventKeyboardListener( )
Answer: b

Q. 16 Name the method defined in EventObject class that returns the object generated
from the event.
(a) getEvent( )
(b) getObject( )
(c) getId( )
(d) getSource( )
Answer: d

Q. 17 The MouseListener interface is used to make mouse handling.


(a) True
(b) False
Answer: a

Q. 18 ActionEvent is applied on
(a) Frame
(b) Checkbox, Choice, List
(c) Scrollbar
(d) Button, TextField, List, Menu
Answer: d

Q. 19 ComponentEvent is the super class of .


(a) FocusEvent
(b) MouseEvent
(c) WindowEvent
(d) All of the above
Answer: d
Q. 20 If we close an applet window events will be generated.
(a) ActionEvent
(b) ComponentEvent
(c) AdjustmentEvent
(d) WindowEvent
Answer: d

Q. 22 Which Listener handles all List related Events?


(a) ItemListener
(b) InputEvent
(c) SelectEvent
(d) ListEvent
Answer: a

Q. 23 How to obtain the command name for invoking ActionEvent?


(a) getCommandName( )
(b) getActionEventCommand( )
(c) getActionCmd( )
(d) getActionCommand( )
Answer: d

Q. 25 When we need to use Checkbox or Item from the list or use a checkable Menu an is
generated.
(a) ActionEvent
(b) ItemEvent
(c) MenuEvent
(d) ClickEvent
Answer: b

Q. 26 Which of the following constant is not defined in WindowEvent class?


(a) WINDOW_ACTIVATED
(b) WINDOW_CLOSED
(c) WINDOW_DEICONIFIED
(d) None of these
Answer: d

Q. 27 Which of the following is not the method of handling window events?


(a) void windowClosed(WindowEvent we)
(b) void windowClosing(WindowEvent we)
(c) void windowAfterClosing(WindowEvent we)
(d) All of these
Answer: c
Q. 28 Which method is used to process mouse click?
(a) public void mouseClicked(MouseListener m)
(b) public void mouseIsClicked(MouseEvent m)
(c) public void mouseClicked(MouseEvent m)
(d) public void mouseClick(MouseEvent m)
Answer: c

Q. 29 Which class is used for this processing method processActionEvent( ) method?


(a) Button, List, MenuItem
(b) Button,Checkbox,Choice
(c) ScrollBar, Component, Button
(d) None of the above.
Answer: a

Q. 30 Which of this package contains all the classes and methods required for event
handling in Java.
(a) java.applet
(b) java.awt
(c) java.event
(d) java.awt.event
Answer: d

32 Which of these interfaces define a method actionPerformed()


(a) ComponentListener
(b) ContainerListener
(c) ActionListener
(d) InputListener
Answer: c

Q. 33 Button Control implements following listener interface.


(a) ItemListener
(b) ActionListener
(c) FlowListener
(d) Adapter
Answer: b

Q. 34 Clicking the closing button on the upper right corner of a frame generates a (n)‐
event.
(a) ItemEvent
(b) WindowEvent
(c) MouseMotionEvent
(d) ComponentEvent
Answer: b
Q. 35 Which of the following method must be overridden in the order to handle KeyEvent.
(a) keyPressed(KeyEvent obj)
(b) KeyReleased(KeyEvent obj)
(c) KeyTyped(KeyEvent obj)
(d) All of these
Answer: d

Q. 36 Which of these methods can be used to know the degree of adjustment made by
the user?
(a) getValue( )
(b) getAdjustmentType( )
(c) getAdjustmentValue( )
(d) getAdjustmentAmount( )
Answer: c

Q. 37 MouseEvent is subclass of which of the following class?


(a) ComponentEvent
(b) ContainerEvent
(c) ItemEvent
(d) InputEvent
Answer: d

Q. 38 ______is an object that is notified when an event occurs.


(a) Listener
(b) Sources
(c) Event
(d) None of the above
Answer: a

Q. 39 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 object of Button
(d) to obtain the label (caption) and object of Button
Answer: a

Q. 40. Select the missing statement in given code


import java.awt.*;
import java.applet.*;
/*<applet code="mouse" width=300 height=100>
</applet>*/
public class mouse extends Applet implements MouseListener, MouseMotionListener
{
String msg = "";
Int mouseX = 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

Q. 41. Select the proper output for following code


Import java.awt.*;
import java.applet.*;
public class list2 extends Applet
{
public void init()
{
List l= new List(2,true);
l.add("java");
l.add("c++");
l.add("kkk");
add(l);
}
}
/*<applet code=list2.class height=200 width=200>
</applet>*/
Q. 44. Select the missing statement in the program to get the following output

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/*<applet code="combodemo" width=300 height=100>
</applet> */
public class combodemo extends JApplet implements itemListener
{
JLabel jl;
Image Iconfrance, germany, italy, japan;
public void init(){
Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());
JComboBoxjc = new JComboBox();
jc.addItem("France");
jc.addItem("Germany");
jc.addItem("Italy");
jc.addItem("Japan");
jc.addItemListener(this);
contentPane.add(jc);
contentPane.add(jl);
}
public void itemStateChanged(ItemEventie)
{
String s = (String)ie.getItem();
jl.setIcon(new ImageIcon(s + ".gif"));
}
}

a) jl = new JLabel(new ImageIcon("star.gif"));


b) jl = new JLabel("star.gif");
c) jl = new JLabel( ImageIcon("star.gif"));
d) JLabel(new ImageIcon("star.gif"));

Q. 45. Select the missing statement in the program for following output

import java.awt.*;
public class MenuDemo extends Frame
{
public static void main(String args[])
{
MenuDemo m = new MenuDemo();
m.setVisible(true);
MenuBar mbr = new MenuBar();
m.setMenuBar(mbr);
Menu filemenu = new Menu("File");
Menu editmenu = new Menu("Edit");
Menu viewmenu = new Menu("View");
mbr.add(filemenu); mbr.add(editmenu);
MenuItem new1 = new MenuItem("New");
MenuItem open1 = new MenuItem("Open");
filemenu.add(new1);
filemenu.add(open1);
}
}
A. mbr.add(view);
B. mbr.add(menu);
C. mbr.add(vieweditmenu);
D. mbr.add(viewmenu);

Q.46. Consider the following output. Find the missing statement in the program.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
/*<applet code="SimpleKey1" width=300 height=100>
</applet>*/
public class SimpleKey1 extends JApplet implements KeyListener
{
String msg = "";
int X = 10, Y = 20;
public void init()
{
addKeyListener(this);
requestFocus();
}
public void keyPressed(KeyEvent ke)
{
showStatus("Key Down");
}
public void keyReleased(KeyEvent ke)
{
showStatus("Key Up");
public void keyTyped(KeyEvent ke)
{
msg +=
ke.getKeyChar();
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg, X, Y);
}
}
a) Missing Semicolon
b) }
c) {
d) ()
Q.47.For the following code select the method that can be used to handle event.
importjava.awt.event.*;
import java.awt.*;
importjava.applet.*;
public class checkbackg extends Applet implements ItemListener
{
Checkbox m1,m2,m3;
public void init()
{
m1=new Checkbox("A");
m2=new Checkbox("B");
m3=new
Checkbox("C");
add(m1);
add(m2);
add(m3);
m1.addItemListener(this);
m2.addItemListener(this);
}
public void (ItemEvent ie)
{
if(ie.getSource()==m1)
setBackground(Color.red);
if(ie.getSource()==m2)
setBackground(Color.green);
}
}
/*<applet code=checkbackg.class height=150 width=150>
</applet>*/

a) actionPerformed(ActionEvent ae)
b) itemStateChanged(ActionEvent ie)
c) itemStateChanged(ItemEvent ie)
d) adjustmentPerformed(AdjustmentEvent ae)
UNIT 4 NETWORKING
Q. 1 UDP stands for
(a) User Data Port
(b) User Datagram Protocol
(c) Used Data Provider
(d) User Data Protocol
Answer: b

Q. 2 Name the class which is used to create a port where the server will listen.
(a) Server
(b) Socket
(c) ServerSocket
(d) SocketServer
Answer: b

Q. 3 Communication using TCP protocol is and .


(a) Connection less, Iterative
(b) Collection less, concurrent
(c) Connection oriented, Iterative
(d) Connection oriented, concurrent
Answer: d

Q. 4 Which of these is a not a factory method of InetAddress class?


(a) static InetAddress getLocalHost( )
(b) static InetAddress getByName(String hostname)
(c) static InetAddress getAllName(String hostname)
(d) static InetAddress[ ] getAllByName(String hostname)
Answer: c

Q. 5 Which from the below use “Middle tier”.


(a) 3 tier
(b) 4 tier
(c) n – tier
(d) all of the above
Answer: d

Q. 6 java.net package consists of interface


(a) ContentHandlerFactory
(b) SocketImplFactory
(c) FileNameMap and URLStreamHandlerFactory
(d) All of the above
Answer: d
Q. 7 IPv6 uses .
(a) 4 groups of 8 bits each
(b) 4 group of 8 hexa‐ decimal digits
(c) 8 groups of 4 digits each
(d) 8 groups of 4 hexa‐ decimal digits each
Answer: d

Q. 8 Select full form of DNS.


(a) Data Network System
(b) Domain Name System
(c) Domain Name Server
(d) Domain Naming Service
Answer: d

Q. 9 What is the use of WriteUTF( ) method?


(a) This method writes a string into underlying output stream.
(b) This method reads a sting from underlying input stream.
(c) This method writes a byte array into underlying output stream.
(d) This method writes a character array into underlying output stream.
Answer: c

Q. 10 Which of these is a bundle of information passed


between machines?
(a) MIME
(b) Cache
(c) Datagram
(d) Socket
Answer: c

Q. 11 Port number for FTP is


(a) 21
(b) 23
(c) 25
(d) 80
Answer: a

Q. 12 The class which encapsulates both the numerical IP address and the domain name
for that address is .
(a) DatagramPacket
(b) DatagramSocket
(c) InetAddress
(d) ServerSocket
Answer: c
Q. 13 int getServerPort( ) method
(a) returns the port number on which this request was received.
(b) returns the port name on which the request was received.
(c) returns the server number on which this request was received.
(d) returns the port number on which this response/request was received.
Answer: d

Q. 14 In this constructor ServerSocket(int port, int max_queue) what is the default value
for max_queue?
(a) 100
(b) 50
(c) 75
(d) 80
Answer: b

Q. 15 The constructor of URL can throw an exception called


(a) MalformedUrlException
(b) UrlNotFoundException
(c) UrlException
(d) UrlSourceNotFoundException
Answer: a

Q. 16 Which IP address is multicast IP address?


(a) 192.168.2.32
(b) 235.55.45.2
(c) 12.22.1.2
(d) None of these
Answer: d

Q. 17 Which 5 parameters uniquely identify a connection?


(a) Local IP, Remote IP, Local MAC, Remote MAC and Protocol
(b) Local IP, Local PORT, Remote MAC, Remote PORT and Protocol
(c) Local MAC, Local PORT, Remote MAC, Remote PORT and Protocol
(d) Local IP, Local PORT, Remote IP, Remote PORT and Protocol
Answer: b

Q. 18 Select the method used to create URL connection.


(a) URL Connection
(b) open Connection
(c) URL
(d) URL Decoder

Answer: a
Q. 19 What value is returned by the readLine( ) method when it reach at End of File?
(a) EOF
(b) null
(c) 0
(d) END
Answer: b

Q. 20 The class is used to create TCP server.


(a) Server
(b) SocketServer
(c) ServerSocket
(d) Socket
Answer: c

Q. 21 Which method of ServerSocket will wait for a client to initiate communication and
then communication with the client?
(a) wait( )
(b) connect( )
(c) waitForClient( )
(d) WaitForConnect( )
Answer: b

Q. 22 method is used to retrieve file name specified in URL.


(a) getFile( )
(b) getUrl( )
(c) getFileUrl( )
(d) getLocalFile( )
Answer: a

Q. 23 is necessary to implement Datagram.


(a) DatagramPacket
(b) DatagramSocket
(c) Both A & B
(d) None of A & B
Answer: d

Q. 24 Which is the correct syntax for getLocalHost( ) method?


(a) public static InetAddress getLocalHost( ) throws UnknownHostException
(b) public static IpAddress getLocalHost( ) throws UnknownHostException
(c) public static String getLocalHost( ) throws UnknownHostException
(d) public static void getLocalHost( ) throws UnknownHostException
Answer: a
Q. 25 Which of these method of DatagramPacket class is used to find the destination
address?
(a) findAddress( )
(b) getAddress( )
(c) address( )
(d) whoIs( )
Answer: b

Q. 26 Connection oriented communication is possible using classes of Java.


(a) Socket and ServerSocket
(b) DatagramSocket and DatagramPacket
(c) Both of these
(d) None of these
Answer: a

Q. 27 A server socket can connect to clients.


(a) 1
(b) 2
(c) 10
(d) multiple
Answer: d

Q. 28 Resolver in DNS system maps .


(a) Domain name to IP address
(b) IP address to domain name
(c) Domain name to MAC address
(d) MAC address to IP address
Answer: b

Q. 29 If a program consists of three classes, then after compilation how many class files
will be created by the compiler?
(a) one
(b) three
(c) uncountable
(d) zero
Answer: b

Q. 30 Which of the following is not a method of Security class?


(a) socketPermission( )
(b) filePermission( )
(c) dataPermission( )
(d) None of above
Answer: d
Q. 31 TCP does not supports Multicasting and Broadcasting because .
(a) It supports full duplex communication.
(b) It provides error control.
(c) It provides flow control
(d) It is connection oriented protocol
Answer: d

Q. 32 Which of the following is true about TCP protocol?


(a) is reliable and connection oriented
(b) is unreliable but connection oriented
(c) is reliable and connectionless
(d) None of these
Answer: a

Q. 33 Which class defines following methods?


int getContentLength( )
long getDate( )
long getExpiration( )
(a) URLConnection
(b) Datagram
(c) Client
(d) None of these
Answer: a

Q. 34 Name the class which is used to create a port where the server will listen?
(a) Server
(b) Socket
(c) ServerSocket
(d) SocketServer
Answer: b

Q. 35 class Permission in java.security package is .


(a) static
(b) abstract
(c) final
(d) None of these
Answer: b
Q. 36 Which methods are commonly used in ServerSocket class?
(a) public OutputStream getOutputStream( )
(b) public Socket accept( )
(c) public synchronized void close( )
(d) None of the above
Answer: b

Q. 37 Which is the proper method to retrieve the host name of local machine?
(a) static InetAddress getLocalHost( ) throws UnknownHostException
(b) static InetAddress getByName(String host_name ) throws UnknownHostException
(c) static InetAddress getAllByName(String host_name ) throws UnknownHostException
(d) String getHostAddress( )
Answer: a

Q. 38 Which constructor of DatagramPacket class are used for receiving purpose?


(a) DatagramPacket(byte data[ ], int size) DatagramPacket(byte data[ ], int size, int offset, int
port)
(b) DatagramPacket(byte data[ ], int size,InetAddress ip, int port) DatagramPacket(byte data[ ],
int offset, int
size, InetAddress ip, int port)
(c) DatagramPacket(byte data[ ], int size) DatagramPacket(byte data[ ], int size,InetAddress ip,
int port)
(d) All of these
Answer: d

Q.39. What will be displayed in the output?


import java.net.*;
Class myAddress
{
public static void main (String args[])
{
try
{
InetAddress address = InetAddress.getLocalHost();
System.out.println(address);
}
catch (UnknownHostException e) {
System.out.println("Could not find this computer's address.");
}
}
}
a) The internet address of the server
b) The internet address of the client
c) The internet address of the host
d) The internet address of any other PC
Q.41. Consider the following program
What correction should be done in the program to get correct output?
import java.net.*;
import java.io.*;
public class URLTest
{
public static void main(String args[]) throws MalformedURLException
{
URL url = new URL("http://www.msbte.com/download");
System.out.println("Protocol:"+ url1.getProtocol());
System.out.println("Port:"+ url1.getPort());
System.out.println("Host:"+ url1.getHost());
System.out.println("File:"+ url1.getFile());
}
}
a) Exception type is wrong.
b) Class should not be public.
c) Creation of object is not correct.
d) Use of created object not correct
UNIT-5 JDBC OBC QUESTIONS
The package contains classes that help in connecting to a database, sending SQL
statements to the database and process the query request.
(a) connection.sql
(b) db.sql
(c) pkg.sql
(d) java.sql
Answer: a

Which of the following is not a type of JDBC driver?


(a) 100% pure Java Driver
(b) JDBC – net pure Java Driver
(c) JDBC – Native API driver
(d) JDBC – Native pure Java Driver
Answer: d

In JDBC imports all Java classes that are concern with Database connectivity.
(a) javax.sql
(b) java.mysql
(c) java.sql
(d) com.sql
Answer: c

Database programming using Java throws which of the following exception?


(a) SQLException
(b) ClassNotFoundException
(c) None of these
(d) Both of these
Answer: d

In the below statement, which type of query can be used with executeUpdate( ) method.
statement.executeUpdate(query here)
(a) Insert, Update, Delete
(b) Insert, Select, Delete
(c) Only Select
(d) Any Query
Answer: a

What is purpose of next( ) method?


(a) to retain the next element in a series.
(b) to retain next table.
(c) to retain next record in a series.
(d) None of the above
Native – protocol pure Java Driver converts into the directly.
(a) JDBC calls, network protocol
(b) ODBC class, network protocol
(c) ODBC class, user calls
(d) JDBC calls, user calls
Answer: d

Choose the correct syntax for getConnection( ) method.


(a) public static Connection getConnection(String url, String password) throws SQLException
(b) public static Connection getConnection(String name, String password) throws SQLException
(c) public static Connection getConnection(String url, String name, String password) throws
SQLException
(d) public static Connection getConnection(String url, String name) throws SQLException
Answer: c

SQL stands for .


(a) Structured Query Language
(b) Sequential Query Language
(c) Structured Question Language
(d) Sequential Question Language
Answer: a

Is a table of data which represents a data from table.


(a) MetaData
(b) ResultSetMetaData
(c) ResultSet
(d) Statement
Answer: c

Public class DriverManager extends


(a) Object
(b) String
(c) Connection
(d) Statement
Answer: a

Which of the following method is supported by Statement interface?


(a) public boolean execute(String query)
(b) public ResultSet executeQuery(String query)
(c) public int executeUpdate(String query)
(d) All of above
Answer: d
In following statement rs is an object of interface of JDBC API.
System.out.println(rs.getString(3));
(a) RowSet
(b) Statement
(c) Connection
(d) ResultSet
Answer: d

Which is main component of JDBC API?


(a) DriverManager
(b) Driver
(c) Connection
(d) All of these
Answer: d

How many steps are used to connect any java application with the database using JDBC
?
(a) 5
(b) 4
(c) 3
(d) 6
Answer: a

ODBC minimum SQL grammer contains


(a) Stored procedure
(b) Data, Time and TimeStamp only
(c) create or drop View
(d) Insert, update, delete only
Answer: d

Which class/interface is used for an SQL statement that is executed frequently?


(a) Statement
(b) CallableStatement
(c) PreparedStatement
(d) None of the above
Answer: c

What does the following code do : smt = con.createStatement( )


(a) A PreparedStatement object is created to send SQL commands to database.
(b) A Statement object is created to send SQL commands to database.
(c) A CallableStatement is created to send SQL commands to database.
(d) A Statement object is created to execute parameterized SQL commands.
Answer: b
Which kind of driver converts JDBC calls into calls on the Client API for Oracle, Sybase,
Informix, BM ,DB2, or other DBMS
(a) JDBC ODBC bridge + ODBC Driver
(b) Native API partly – Java Driver
(c) JDBC – Net pure Java Driver
(d) Native Protocol Pure Java Driver
Answer: b

Which method executes an SQL statement that may return multiple results?
(a) executeUpdate( )
(b) executeQuery( )
(c) execute( )
(d) noExecute( )
Answer: b

Identify correct syntax of executeQuery( ) of Statement interface.


(a) public static ResultSet executeQuery( )
(b) public ResultSet executeQuery(String q)
(c) public void executeQuery(String q)
(d) public int executeQuery(String q)
Answer: b

Native API converts into the used by DBMS.


(a) JDBC API, Network Protocol
(b) JDBC API, Native API calls
(c) JDBC API, use calls
(d) JDBC API, ODBC API calls
Answer: b

Which of the following function is used to find the column count of the particular
ResultSet.
(a) getMetadata( )
(b) metadata( )
(c) getColumnCount( )
(d) getCount( )
Answer: c
The JDBC‐ ODBC bridge supports how many concurrent open statements per
connection ?
(a) 1
(b) 0
(c) Does not support connection
(d) None of these
Answer: a

Select the correct method to create CallableStatement.


(a) CallableStatement prepareCall(String sql)
(b) CallableStatement prepareCall(String sql, int resultset type, int resultset_concurrency)
(c) CallableStatement prepareCall(String sql, int resultset_type, int resultset_concurrency, int
resultset_holdability)
(d) All of the aboved

Microsoft Access data in file format.


(a) .DAT
(b) .MDB
(c) .MSSQL
(d) .OBJ
Answer: b

Which of the following method is used for send SQL statements?


(a) Statement
(b) CallableStatement
(c) PreparedStatement
(d) Both B & C
Answer: d

DELETE statement of an SQL is executed by .


(a) execute( )
(b) executeQuery( )
(c) executeUpdate( )
(d) executeDelete( )
Answer: c

The interface to the database is handle by .


(a) ODBC
(b) JDBC
(c) JDBC & ODBC
(d) APIs
Answer: b
DatabaseMetadata are retrieved through
(a) getDatabaseMetadata( )
(b) getMetaData( )
(c) getDBMetaData( )
(d) getDatabaseMeta( )
Answer: a

Which method is used to retrieve the ResultSet created?


(a) executeQuery( )
(b) getResultSet( )
(c) getResultSetResult( )
(d) getResult( )
Answer: a

Which of the following is used generally for reading the content of the database?
(a) DabaseData
(b) DabaseData
(c) ResultSet
(d) DatabaseResult
Answer: c

The syntax to create a table named “Course”,should begin with .


(a) create new table course
(b) create table course
(c) table course create
(d) new table course
Answer: b

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("jdbc:odbc:ODSN"," "," ");
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("select *from StudTable");
System .out.println("Name" + " \t " + "Roll_No" + " \t " + "Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t \t"+rs.getDouble(3));
s.close();
c.close();
}
}
A. Missing semicolon
B. Missing {
C. Missing }
D. Missing statement.

Q. 35. Consider the following program.


What should be the correction done in the program to get correct output?
import java.sql.*;
class Ddemo1
{
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:ODSN"," "," ");
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("select *from StudTable");
System .out.println("Name" + " \t " + "Roll_No" + " \t " + "Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t \t"+rs.getDouble(3));
}
s.close();
c.close();
}
}
A. Missing semicolon
B. Missing {
C. Missing }
D. Missing statement.

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("jdbc:odbc:ODSN"," "," "); Statement
s=c.createStatement();
ResultSet rs=s.executeQuery("select *from StudTable");
System .out.println("Name" + " \t " + "Roll_No" + " \t " + "Avg"); while(rs.next())
{
System.out.println(rs.getString(1)+" \t "+rs.getInt(2)+" \t \t"+rs.getDouble(3));
}
s.close();
c.close();
}
}
A. Error in main()
B. Error in loop
C. Error in connection statement
D. Error in close()

Consider the following program


Select the statement that should be added to the program to get correct output.
import java.sql.*; public class db15
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c =DriverManager.getConnection("jdbc:odbc:MyDSN","",""); PreparedStatement
s=c.prepareStatement( "update db3 set Name=? where Roll_no=?"); Statement
s=c.createStatement( );
s.setString(1,args[0]);
s.setString(2,args[1]);
s.setString(3,args[2]);
ResultSet rs=s.executeQuery("select* from db3"); System.out.println("Name"+"\t"+"Roll
no"+"\t"+"Avg");
while(rs.next())
{
System.out.println(rs.getString(1)+"\t"+rs.getInt(2)+"\t"+rs.getDouble(3));
}
s.close();
c.close();
}
}
A. s.executeUpdate()
B. c.createStatement( )
C. s.close()
D. c.close()
CH-6 SERVLET MCQ
Q. 1 JSP embeds in .
(a) Servlet, HTML
(b) HTML, Java
(c) HTML, Servlet
(d) Java, HTML
Answer: d

Q. 2 Which of the following is the default HttpRequest method?


(a) doGet( )
(b) doPost( )
(c) doTrace( )
(d) doPut( )
Answer: a

Q. 3 Which are true about tag libraries in web application?


(a) packaged in the /WEB‐ INF directory or subdirectory of the WAR file
(b) If a tag is implemented as a tag file and packaged in /WEB‐ INF/tags/ or a subdirectory,a TLD
will be generated automatically by the web container, though, you can provide one if you wish
(c) packaged in the /META‐ INF/ directory or sub directoryof a tag library packaged in a jar.
(d) All of the above.
Answer: d

Q. 4 Name the http method used to send resources to the server.


(a) FTP method
(b) PUT method
(c) WRITE method
(d) COPY method
Answer: b

Q. 5 Identify the proper syntax of doGet( ).


(a) void doGet(HttpResponse res,HttpRequest req) throws IOException, ServletException
(b) void doGet(HttpRequest req,HttpResponse res) throws IOException, ServletException
(c) void doGet(HttpResponse res) throws IOException, ServletException
(d) void doGet(HttpRequest req) throws IOException, ServletException
Answer: b

Q. 6 Given an HttpServletRequest request and HttpServletResponse response instances.


Which sets a cookie “username” with the value “joe” in a servlet?
(a) request.addCookie(new Cookie(“username” ,“joe));
(b) response.addCookie(new Cookie(“username” ,“joe”))
(c) request.addCookie(“username” , “joe);
(d) request.addCookie(“username” , “joe);
Answer: b
Q. 7 Which JSP tag is used to transfer for processing another JSP page?
(a) <jsp:include>
(b) <jsp:forward>
(c) <jsp:useBean>
(d) <jsp:use:include>
Answer: b

Q. 9 The include( ) method in RequestDispatcher .


(a) sends a request to another resource like servlet, JSP or html.
(b) includes resources of file like servlet, JSP or html.
(c) appends the request and response objects to the current servlet.
(d) None of these Servlets
Answer: c

Q. 10 State true or false for following statements.


(i) JavaBeans slow‐ down software development process.
(ii) Java Servlets do not have built‐ in multithreaded feature.
(a) false, false
(b) false, true
(c) true, false
(d) true, true
Answer: a

Q. 11 is a small piece of information that is passed back & forth in HTTP request &
response.
(a) Servlet
(b) Applet
(c) Cookie
(d) Session
Answer: c

Q. 12 Which life cycle method is used to process a client’s request?


(a) start( )
(b) init( )
(c) service( )
(d) destroy( )
Answer: c

Q. 13 A user types the URL http://www.msbte.com/result.php. Which request gets


generated?
(a) GET method
(b) POST method
(c) HEAD method
(d) PUT method
Answer: b

Q. 14 Apache Tomcat is .
(a) Servlet
(b) Java Program
(c) API
(d) Web server capable of running Java programs
Answer: d

Q. 15 What the getSession( ) method with “true” parameter will do?


(a) The session is completed
(b) The session object is passed to another method
(c) Creates new session if, the session does not exist
(d) The session is exist
Answer: c

Q. 16 A JSP page consists of which tags?


(a) HTML tags
(b) JSP tags
(c) Both A & B
(d) None of the above
Answer: c

Q. 17 Life cycle of a servlet is managed by


(a) Servlet Context
(b) Servlet Container
(c) Supporting protocol
(d) All of the above
Answer: b

Q. 18 To send binary output in the response, the following method of HttpServlet


response many be used to get the appropriate Writer/Stream object.
(a) getStream( )
(b) getOutputStream( )
(c) getBianaryStream( )
(d) getWriter( )
Answer: b

Q. 19 is the first Phase of Servlet Life cycle.


(a) service( )
(b) init( )
(c) destroy( )
(d) Both B & C
Answer: b

Q. 20 How many copies of a JSP page can be in memory at a time?


(a) 1
(b) 2
(c) 3
(d) Unlimited
Answer: a

Q. 21 Which method is used to specify before any lines that used the PrintWriter?
(a) setPageType( )
(b) setContextType( )
(c) setContentType( )
(d) setResponseType( )
Answer: c

Q. 22 is used to read data from a client request.


(a) ServletResponse
(b) ServletRequest
(c) Servlet
(d) ServletConfig
Answer: b

Q. 23 The following methods belongs to the life cycle methods of the servlet.
(a) init( )
(b) service( )
(c) destroy( )
(d) All of the above
Answer: d

Q. 24 Java servlet
(i) is a key component of the server side java development.
(ii) is a small pluggable extension to a server that enhances functionality
(iii) runs only in windows OS
(iv) allows developers to customize any java enabled server
(a) i, ii and iii are true
(b) i,iii and iv are true
(c) ii,iii and iv are true
(d) i,ii and iv are true
Answer: d

Q. 25 Servlet lifecycle has states.


(a) Two
(b) Three
(c) Four
(d) Five
Answer: b

Q. 26 JSP life cycle includes number of phases.


(a) Two
(b) Three
(c) Four
(d) Five
Answer: d

Q. 27 How to send data in get method?


(a) using GET method in request
(b) using Requesting URL
(c) using Response URL
(d) using URL
Answer: a

Q. 28 JSP life cycle includes following


(a) Translation Phase
(b) Compilation Phase
(c) Request handling phase
(d) All of these
Answer: d

Q. 29 JSP stands for .


(a) Java Service Provider
(b) Java Server Path
(c) Java Server Pages
(d) Java Server Program
Answer: c

Q. 30 The authentication mechanism in the servlet specification uses a technique called ?


(a) Role Based Authentication
(b) Form Based Authentication
(c) Both a & b
(d) None of the above
Answer: c

Q. 31 Which class provides stream to read binary data such as image et(c) from the
request object?
(a) ServletInputStream
(b) ServletOutputStream
(c) Both a & b
(d) None of the above
Answer: a

Q. 32 What is the limit of data to be passed from HTML to doGet() ?


(a) 8kb
(b) 1kb
(c) 4kb
(d) 2kb
Answer: d

Q. 33 The major difference between Servlet and CGI is .


(a) Servlets are thread based and CGI is process based.
(b) Servlet executes slower than CGI.
(c) Servlet has no platform specific API whereas CGI has.
(d) All of these
Answer: d

Q. 34 Difference between doGet() and doPost() methods is . Select any of given options
A. In doGet() the parameters are appended to the URL and sent along with header information.
B. In doPost(),will send the information through a socket back to the webserver and it won't show
up in the URL bar.
C. doGet () is a request for information;
D. doPost() provides information (such as placing an order) that the server is expected to
remember
(a) All above are valid differences
(b) Only A and B
(c) Only C and D
(d) A, B, C are valid differences.

Q. 35.Choose missing statements in following code from given options.


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

Q. 36. In following Java program fill statement showing ***.Select any one option fro given
options
import javax.servlet.*; import javax.servlet.http.*;
public class AddCookieServlet extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throwsServletException,
IOException
{
String data = request.getParameter("data");
Cookie cookie = *************** response.addCookie(cookie);
response.setContentType("text/html"); PrintWriter pw = response.getWriter();
pw.println("<B>MyCookie has
been set to"); pw.println(data);
pw.close();
}
}
A. new Cookie("MyCookie", data);
B. new Cookie("MyCookie", data1);
C. new Cookie("MyCookie", data2);
D. new Cookie("MyCookie", database);

Q. 37.Consider the following program. Identify the exception that might be thrown
import java.net.*;
class URLDemo
{
public static void main(String args[]) throws
{
URL netAddress= new URL(“http://www.sun.com:8080//index.html”);
System.out.println(“Protocol:”+netAddress.getProtocol());
System.out.println(“Port :”+netAddress.getPort());
System.out.println(“Host:”+netAddress.getHost());
System.out.println(“File :”+netAddress.getFile());
}
}
A. IoException
B. MalformedURLException
C. Arithmetic Exception
D. UnknownHostException

Q. 38. Consider the following program. Identify the missing statement from the output.
import java.net.*; class URLDemo
{
public static void main(String args[]) throws MalformedURLException
{
URL netAddress= new URL(“http://www.sun.com: //index.html”);
System.out.println(“Protocol:”+netAddress.getProtocol();
System.out.println(“Port :”+netAddress.getPort());
System.out.println(“Host:”+netAddress.getHost());
System.out.println(“File :”+netAddress.getFile());
}
}
Output of the Program
Protocol :http
Host :www.sun.com File :/index.html
A. Port :8080
B. Port :1024
C. Port: -1
D. None of the above

Q. 39. Consider the following program and identify the missing statement.
class URLDemo
{
public static void main(String args[]) throws MalformedURLException
{
URL netAddress= new URL("http://www.sun.com:/index.html"); System.out.println("Protocol
:"+netAddress.getProtocol()); System.out.println("Port :"+netAddress.getPort());
System.out.println("Host
:"+netAddress.getHost()); System.out.println("File :"+netAddress.getFile());
}
}
A. Missing semicolon
B. Missing package statement
C. Missing initialization
D. None of the above

You might also like