0% found this document useful (0 votes)
42 views224 pages

Java All

This document provides a comprehensive overview of the Abstract Windowing Toolkit (AWT) in Java, covering various components, event handling, and layout managers. It includes multiple-choice questions related to AWT controls, classes, and methods, aimed at assessing knowledge of Java GUI programming. Key topics include menus, buttons, checkboxes, text fields, and event listeners, along with their respective functionalities and usage.

Uploaded by

patilalfiya1
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)
42 views224 pages

Java All

This document provides a comprehensive overview of the Abstract Windowing Toolkit (AWT) in Java, covering various components, event handling, and layout managers. It includes multiple-choice questions related to AWT controls, classes, and methods, aimed at assessing knowledge of Java GUI programming. Key topics include menus, buttons, checkboxes, text fields, and event listeners, along with their respective functionalities and usage.

Uploaded by

patilalfiya1
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/ 224

Unit :01

Abstract Windowing Toolkit (AWT)


1) The various controls supported by AWT are
a) Labels, push buttons
b) Checkboxes, choice, list
c) Scroll bars, text area, text field

d) All of these

2) The concept of the menu bar can be implemented by using three java classes—
a) MenuBar
b) Menu
c) MenuItem

d) All of these

3) The constructor which the Text Event class defines.


a) TextEvent(Object source, int event_type)
b) textevent (Object source, int event_type)
c) textevent (object Source, float event_type)
d) textevent (Object source, string event_type)

4) In Java an event is an _______which specifies the change of state in the source.


a) Class

b) Object
c) Int
d) String

5) The classes and interfaces defined in AWT are contained within the ______ package.
a) java.awt.*
b) java.sql.*
c) java.io.*
d) java.int*
6) 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)

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

8) A checkbox is a control that consists of a


a) Combination of a small box
b) A label
c) Combination of a large box and a label

d) Both a & b

9) Java applets are used to create _______________ applications


a) Graphical
b) User interactive

c) Both a & b
d) None of these

10) AWT means


a) Abstract Window Toolkit
b) Abstract Window Toollayout
c) Abstract Withdraw Tools
d) Abstract Window Title
11) An event is generated when the internal state of the event source is________
a) Not changed

b) Changed
c) Either changed or not
d) None of these

12) Positions the components into five regions:east, west, north, south, center
a) BorderLayout
b) CardLayout
c) GridLayout
d) FlowLayout

13) Arranges the components as a deck of cards such that only one component is visible at a
time
a) BorderLayout

b) CardLayout
c) GridLayout
d) FlowLayout

14) Arranges the components horizontally


a) BorderLayout
b) CardLayout
c) GridLayout

d) FlowLayout

15) Arranges the componemnts into grid


a) BorderLayout
b) CardLayout

c)GridLayout
d) FlowLayout
16) __________ creates a dropdown list of textual entries
a) Choice
b) Checkbox
c) Textbox
d) TextComponent

17) The Component class is an abstract class and so its ____________ are used to create
components.
a) Subclasses
b)Superclasses
c) Both a & b
d)None of these

18) The AWT classes can be roughly categorized into the following groups:
a) GUI Components
b) Layouts
c) Graphics Tools
d) Event Handlers

e) All of these

19) An Applet is a ________ of Panel:


a) Subclass
b) Superclass
c) Both a & b
d) None of these

20) The subclasses of Window are


a) Dialog
b) Frame
c) Both a & b
d) None of these

21) A menu bar represents


a) A list of menus which can be added to the top of a top-level window
b) A list of menus which can be deleted to the top of a top-level window
c) A list of menus which can be added to the bottom of a bottom-level window
d) None of these

22) Each menu is associated with a _________ list of menu items:


a) Checkbox

b) Drop-down
c) Choice
d) None of these

23) The two types of menus which are given as follows:


a) Pop-up menus
b) Regular menus

c) Both a & b
d) None of these

24) Regular menus are placed at the __________ of the application window within a menu
bar
a) Top
b) Bottom
c) Top-down
d) Botttom-up

25) The text field and text area controls create a _________________ area respectively
a) Single-line text
b) Multi-line text

c) Both a & b
d) None of these
26) A push button is an active control that has a _____________ appearance
a) One dimensional
b) Two dimensional

c) Three dimensional
d) None of these

27) _____________ is a superclass of TextField and TextArea classes that is used to create
single-line or multiline textfields respectively:
a)TextBox
b)CheckBox

c)TextComponent
d)Choice

28) A label is a simple control which is used to display_____________ on the window:

a) Text(non-editable)
b) Text(editable)
c) Both a & b
d) None of these

29) ______________ is an abstract class that encapsulates all of the attributes of a visual
component.
a)Component
b)Window
c)Frame
d) Panel

30) A _______ object is responsible for remembering the current foreground and
background colors
a)Window

b)Component
c)None
d)Both

31) Which class is a subclass of Component?

a) Container
b) Window
c) Frame
d) none

32)The ______ class is a concrete subclass of Container.


a) Container
b) Window

c) Panel
d ) None

33)Panel is a superclass for _____.


a) Window
b) Frame

c) Applet
d) None

34) Which is a container that does not contain a title bar, menu bar, or border?
a)Window
b)Frame

c)Panel
d)Container

35)Name the class used to represent GUI component that has a title bar, menu bar, borders,
and resizing corners.
a) Window
b) Container
c) Frame
d) Panel

36) How many Frame constructor are present?


a) 1

b) 2
c) 3
d) 4

37) Which method is used to set title for the Frame window?
a)Frame()

b)Frame(String title)
c) Frame(String title,int x,int y)
d) None

38) Which method is used to set the dimensions of the window?


a)setSize()
b)void setSize(int newWidth, int newHeight)
c)void setSize(Dimension newSize)
d)All of the above

39) The ____ method is used to obtain the current size of a window.

a) getSize()
b)setSize()
c)None
d)Both

40)Which method is used for hiding and showing a window in the frame window.
a)setVisible()
b)getVisible( )
c)both
d)None

41) To implement the windowClosing() method which interface is used?


a) ActionListener
b) ItemListener

c) WindowListener
c) None

42) Which of these packages contains all the classes and methods required for event
handling
a) java.awt.Applet;

b) java.awt.event;
c) java.awt;
d) java.event;

43) On invoking repaint() method for a Component the method invoked by AWT is:
a)draw( )
b)show( )
c)update( )

d) paint( )

44) Which of these events will be generated if we close the applet?


a)ActionListener
b)ItemListener
c)MouseListener
d)WindowListener

45) _______ encapsulates a semantics-free window.


a)Frame
b)Panel

c)Canvas
d)None

46)The class at the top of the AWT hierarchy

a)Component
b)Frame
c)Window
d)Panel

47)Which class dispatches events to multiple listener


a)AWTEvent

b)AWTEventMulticaster
c)AWTEventManager
d) All of the Above

48) Add instance of the desired control to the window by calling ____ method, defined by
____ class.

a)add() , Container
b)add() , Component
c)addTo() , Container
d)addTo(), Component

49)To remove a control from a window ___ method is used.


a)removeControl()

b)remove()
c)removeAll()
d)None of the above

50)You can remove all controls by calling method.


a)remove()
b)removeFrom()
c)Remove()

d)removeAll( )

51)Label defines the following constructors:


a)Label( )
b)Label(String str)
c)Label(String str, int how)

d)All of the above

52)In the Label(String str, int how) constructor value of how will be-

a)Label.LEFT, Label.RIGHT, or Label.CENTER


b)Label.LEFT, Label.RIGHT, or Label.DOWN
c)Label.TOP, Label.BOTTOM, or Label.CENTER
d)Label.TOP, Label.BOTTOM, or Label.DOWN

53)To set or change the text in a label __ method and to obtain the current label by calling
___ method is used.
a)setTxt() , getTxt()
b)settext() , gettext()
c)setText() , getText()
d)getText() , setText()

54)To set the alignment of the string within the label by calling ___ method ,to obtain the
current alignment ___ method is used.
a)getAlignment( ) ,setAlignment( )
b)setAlign( ) ,getAlign( )

c)setAlignment( ) ,getAlignment( )
d)getAlign( ) ,setAlign( )

55) Which packages will use for the following code:


/*
<applet code="LabelDemo" width=300 height=200>
</applet>
*/
public class LabelDemo extends Applet {
public void init() {
Label one = new Label("One");
Label two = new Label("Two");
Label three = new Label("Three");
// add labels to applet window
add(one);
add(two);
add(three);
}
}
a) import java.awt.*; import java.applet.*;
b) import javax.swing.*; import java.awt.*;
c) import javax.swing.*; import java.applet.*;
d) d)import java.applet.*; import java.awt.event.*;

56) Button defines these two constructors:


a) Button( ), Button(Boolean str)
b) Button( ) ,Button(int str)

c) Button( ), Button(String str)


d) Button( ) ,Button(String str , int name)

57) Set label of a button by calling __ method and can retrieve its label by calling __
method.
a) getLabel( ) , setLabel( )

b) setLabel( ) , getLabel( )
c) getlabel( ) , setlabel( )
d) d)setlabel( ) , getlabel( )

58) Each time a button is pressed, an ___ is generated.


a) mouse event
b) Keyboard event
c) item event

d) action event

59) For button __ interface is implemented.

a)ActionListener
b)ItemListener
c)MouseListener
d)FocusListener
60) actionPerformed() method is used in ___ interface.

a)ActionListener
b)ItemListener
c)MouseListener
d)FocusListener

61)Which class can be used to represent a checkbox with a textual label that can appear in a
menu.
a)MenuBar
b) MenuItem

c)CheckboxMenuItem
d)Menu

62) To retrieve the current state of a check box, call __ method , to set its state, call __
method.
a) setState( ) , getState( )

b) getState( ) , setState( )
c) setstate( ) , getstate( )
d) getstate( ) , setstate( )

63) Event handling in checkbox is done by __ listener and __ object is used.

a)ItemListener , ItemEvent
b)MouseListener , MouseEvent
c)ActionListener , ActionEvent
d)KeyListener , KeyEvent

64) Which method is defined by the ItemListener interface?


a)actionPerformed()
b)ActionPerformed()

c)itemStateChanged()
d)ItemstateChanged()

65) Choose the correct:


a)public class CheckboxDemo implement Applet extend ItemListener

b)public class CheckboxDemo extends Applet implements ItemListener


c)public class CheckboxDemo implements Applet extends ItemListener
d)public class CheckboxDemo extend Applet implement ItemListener

66) .It is possible to create a set of mutually exclusive check boxes in which one and only
one check box in the group can be checked at any one time by using __ component.

a) CheckboxGroup
b) Radio Button
c) Checkbox
d) Choice

67) You can determine which checkbox in a group is currently selected by calling __
method.
a)getselectedCheckbox( )
b)GetSelectedCheckbox( )

c)getSelectedCheckbox( )
d)None of the above

68)To set a checkbox which method is used-


a)setselectedCheckbox( )
b)setSelectedCheckbox( )
c)getselectedCheckbox( )
d)getSelectedCheckbox( )

69)In which of the following the only one checkbox will be selected.
a)Checkbox Win98 = new Checkbox("Windows 98/XP", cbg, false);

b)Checkbox Win98 = new Checkbox("Windows 98/XP", cbg, true);


c)Checkbox Win98 = new Checkbox("Windows 98/XP", true);
d)Checkbox Win98 = new Checkbox("Windows 98/XP", false);

70) Which class is used to create a pop-up list of items from which the user may choose.

a) Choice
b) List
c) Checkbox
d) CheckboxGroup

71) Method used to add items in a choice-


a)addItem()
b)additem()
c)Add()

d)add()

72)To determine which item is currently selected, you may call either ___ or ____ method.
a)setSelectedItem( ),setSelectedIndex( )
b)GetSelectedItem( ),GetSelectedIndex( )

c)getSelectedItem( ),getSelectedIndex( )
d)getselectedItem( ),getselectedIndex( )
73)The getItemCount( ) method is used to-
a)To obtain the value of items in the list

b)To obtain the number of items in the list


c)Both a & b
d)None of the above

74) Constuctors of scrollbar are-


a) Scrollbar( ) ,Scrollbar(int style) ,Scrollbar(int style, int initialValue, int thumbSize)
b) Scrollbar( ), Scrollbar(int style) ,Scrollbar(int style, int initialValue, int thumbSize, int
min
c) Scrollbar( ),Scrollbar(int style),Scrollbar(int style, int initialValue, int thumbSize, int
max)
d) Scrollbar( ),Scrollbar(int style),Scrollbar(int style, int initialValue, int thumbSize,
int min, int max)

75) Scrollbar uses which two constants to create horizontal and vertical scrollbar.
a)Scrollbar.Vertical , Scrollbar.Horizontal
b)Vertical.SCROLLBAR , Horizontal.SCROLLBAR

c)Scrollbar.VERTICAL , Scrollbar.HORIZONTAL
d)None of the above

76) To obtain the current value of the scroll bar, call ___, to set the current value, call __
method.
a) setvalue( ), getvalue( )
b) setValue( ) , getValue( )
c) getvalue( ). setvalue( )

d) getValue( ) , setValue( )

77) You can retrieve the minimum and maximum values of scrollbar by __ and___ method
a)getMinimum( ), getMaximum( )
b)getMax(), getMin()
c)setMinimum(), setMaximum()
d)setMax(), setMin()

78) Which interface is implemented for handling scrollbars.


a)ActionListener

b)AdjustmentListener
c)MouseMotionListener
d)ItemListener

79) The________ class implements a single-line text-entry area


a)TextArea class

b)TextField class
c)both a & b
d)none of the above

80) Which of these is not aTextField Constructor


a)TextField( )
b)TextField(intnumChars)

c)TextField(int rows)
d)TextField(Stringstr)

81) To obtain the text currently in the text field, which method is used?
a) getWord()
b) getString()
c) getText()
d) getRow()

82) Program can obtain the currently selected text by calling _________

a) getSelectedText()
b) getText()
c) getSelected()
d) getEdit()

83) Contents of a text field may be modified by the user by calling

a) setEditable( )
b) getEditable()
c) isEditable()
d) None of the above

84) The echoing of the characters as they are typed by calling


a) setPassword()

b) setEchoChar( )
c) hideText()
d) setChar()

85) The AWT includes a simple multiline editor called


a)TextField

b)TextArea
c)Editor
d)Label

86)Which of the following is not a constructor of TextArea


a)TextArea(String str)
b)TextArea(intnumLines, intnumChars)
c)TextArea(Stringstr, intnumLines, intnumChars, intsBars)

d)TextArea(Stringstr, intsrows)

87) Which methods is not supported by TextArea


a) getText()

b) setFormat()
c) setText()
d) SetEditable()

88) The________method appends the string specified by str to the end of the current text.

a)append()
b)insertText()
c)attach()
d)editText()

89) ____ method inserts the string passed in str at the specified index.
a)append()
b)attachText()

c)insert()
d)join()

90) To replace a text, which method is called?


a) replaceText()
b) changeText()
c) editText()
d) replaceRange()

91) Each ______ object has a layout manager associated with it.
a) Applet
b) Frame
c) Panel

d) Container

92) A layout manager is an instance of any class that implements the _______ interface.

a) LayoutManager
b) ActionListener
c) ItemListener
d) MouseListener

93) The layout manager is set by which method.


a) setText()
b) getText()

c) setLayout( )
d) setVisible()

94) Which method is used to determine position and shape of a component manually
a) setBounds()
b) setPosition()

c) Both a and b
d) None

95) Which of the following LayouManager is/are consulted whenever the container needs to
be resized
a) minimumLayoutSize( )
b) preferredLayoutSize( )

c) Both
d) None

96) _____ and _____ are contained by each Layout manager

a) getPrefferedSize(),getMinimumSize( )
b) getPrefferedsize(),getMinimumsize( )
c) getprefferedSize(),getminimumSize( )
d) None

97) Which of these is the default Layout Manager

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

98) Constructors of FlowLayout


a) FlowLayout( )
b) FlowLayout(int how)
c) FlowLayout(int how, int horz, int vert)

d) All of the above

99) In the constructor FlowLayout(int how, int horz, int vert) what is the value of how

a) FlowLayout.LEFT,FlowLayout.CENTER,FlowLayout.RIGHT
b) FlowLayout.TOP,FlowLayout.BOTTOM,FlowLayout.CENTE
c) FlowLayout.EAST,FlowLayout.WEST, FlowLayout.CENTER
d) None

100) Constructors of BorderLayout


a) BorderLayout( ),
b) BorderLayout(int horz, int vert)
c) BorderLayout(int how, int horz, int vert)

d) Both a and b

101) Constants of BorderLayout

a) BorderLayout.CENTER,BorderLayout.SOUTH,BorderLayout.EAST,
BorderLayout.WEST, BorderLayout.NORTH
b) BorderLayout.CENTER, BorderLayout.TOP, BorderLayout.BOTTOM,
BorderLayout.LEFT, BorderLayout.RIGHT
c) BorderLayout.CENTER, BorderLayout.LEFT, BorderLayout.RIGHT,
d) None of the above

102) GridLayout lays out components in a ______ grid.


a) One-dimensional
b) Three-dimensional
c) Multi-dimensional

d) Two-dimensional

103) Construcors of GridLayout


a) GridLayout( )
b) GridLayout(int numRow,numColumns )
c) GridLayout(int numRows, int numColumns, int horz, int vert)
d) All of the Above
104) The CardLayout class is ______ among the other layout managers in that it stores
several different _____.
a) unique,classes

b) unique,layout
c) antique,methods
d) special,packages

105) Constructors of CardLayout are:

a) CardLayout( ), CardLayout(int horz, int vert)


b) CardLayout( ),CardLayout(inthorz,intvert), CardLayout(int numRows, int numColumns,
int horz, int vert)
c)Both
d)None

106) The cards are held in an object of type ______


a) Frame
b) Applet

c) Panel
d) Container

107) Methods of CardLayout


void first(Container deck)
void last(Container deck)
void next(Container deck)
void previous(Container deck)
void show(Container deck, String cardName)
a)All
b)only first 2
c)Both
d)None

108) Dialog box maybe ______ or ______


a) Fixed,Variable
b) static,dynamic
c) manual,automated

d) modal,modeless

109) Which of these is true of modal dialog box


a) You cannot access other parts of your program until you have closed the dialog box.
b) Input focus can be directed to another window in your program.
c) Both a and b
d) None

110) Which of these is true of modeless dialog box


a) You cannot access other parts of your program until you have closed the dialog box.
b) Input focus can be directed to another window in your program.
c) Both a and b
d) None

111) Constructors of dialog box


a) Dialog(Frame parentWindow, boolean mode), Dialog(Frame parentWindow, String
title, boolean mode)
b) Dialog(Frame parentWindow, boolean mode) ,Dialog(Frame parentWindow, String title,
boolean mode, int horz, int vert)
c) Dialog(Frame parentWindow, boolean mode), Dialog(Frame parentWindow, String title,
boolean mode,int rows,int column)
d) Dialog(Frame parentWindow, boolean mode) ,Dialog(Frame parentWindow, String title)

112) To create a file dialog box, instantiate an ______ of type FileDialog.


a) Method
b) Class

c) Object
d) Package

113) Constructor of FileDialog


a) FileDialog(Frame parent, String boxName), FileDialog(Frame parent, String boxName,
int how,int horz,int vert), FileDialog(Frame parent)
b) FileDialog(Frame parent, String boxName),
c) FileDialog(Frame parent, String boxName) ,FileDialog(Frame parent, String
boxName, int how) FileDialog(Frame parent)
d)FileDialog(Frame parent, String boxName),FileDialog(Frame parent, String boxName, int
how)

114) For the file to be in reading mode which method is used


a) FileDialog.SAVE
b) FileDialog.WRITE

c) FileDialog.LOAD
d) FileDialog.READ

115) For the file to be in writing mode which method is used

a) FileDialog.SAVE
b) FileDialog.WRITE
c) FileDialog.LOAD
d) FileDialog.READ

116) Select the correct Menubar classes from the following options

a) MenuBar, Menu, MenuItem


b) menubar, menu, menuitem
c) Both
d) None of these

117) Which menu option of types will have a checkmark next to them when they are
selected?

a) CheckboxMenuItem
b) CheckedItem
c) MenuItem
d) None of these

118) You can disable or enable a menu item by using the ____________method.
a) setStatus()

b)setEnabled( )
c) setMenuStatus()
d)None of these

119) Which of these constructor throws HeadlessException?


a) CheckboxMenuItem()
b) CheckboxMenuItem(String itemName)
c) CheckboxMenuItem(String itemName, boolean on)

d) All of these

120) Which sets the command name of the action event that is fired by this menu item?
a) setActionCommand()
b) setMenuCommand()
c) Both
d) None of these

121) To check an item, pass ____ to ________.

a) true, setState()
b) check, setItemStatus()
c) check, setItemState()
d) None of these

122) Constuctors of checkbox are -


a) Checkbox( )
b) Checkbox(String str)
c) Checkbox(String str, boolean on, CheckboxGroup cbGroup)

d) All of the above

123)
import java.awt.*;
import java.applet.*;
import java.util.*;
/*
<applet code="BorderLayoutDemo" width=400 height=200>
</applet>
*/
public class BorderLayoutDemo extends Applet
{
public void init() {
add(new Button("north."),BorderLayout.NORTH);
add(new Button("south"),BorderLayout.SOUTH);
add(new Button("Right"), BorderLayout.EAST);
add(new Button("Left"), BorderLayout.WEST);
String msg = "this is in center";
add(new TextArea(msg), BorderLayout.CENTER);
}
}

a) SetLayout(new BorderLayout());
b) setLayout(new BorderLayout());
c) setLayout(new Borderlayout());
d) setLayout(new borderLayout());

124) What should be written in blank space.

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="CBGroup" width=250 height=200>
</applet>
*/
public class CBGroup extends Applet
{
String msg = "";
Checkbox Win98, winNT;
CheckboxGroup cbg;
public void init()
{
cbg = new CheckboxGroup();
Win98 = new Checkbox("Windows 98/XP", , true);
winNT = new Checkbox("Windows NT/2000", , false);
add(Win98);
add(winNT);

Win98.addItemListener(this);
winNT.addItemListener(this);
}
}

a) Win98
b) winNT
c)cbg
d)this

125) Find error in following code.

import java.awt.*;
import java.awt.event.*;
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

126) What will be the output for following code?


import java.awt.*;
import java.applet.*;
/*
<applet code="GridLayoutDemo11" width=300 height=200>
</applet>
*/
public class GridLayoutDemo11 extends Applet {
static final int n = 4;
public void init() {
setLayout(new GridLayout(n, n));
setFont(new Font("SansSerif", Font.BOLD, 24));
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
int k = i * n + j;
if(k > 0)
add(new Button("" + k));
}
}
}
}
a)

b)

c)

d)
Answer: a)

127) Consider the following program. Find the error.


immport java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code=demo width=100 height=100>
</applet> */

public class demo extends Applet


{
public void init()
{
firstlabel =new Label("Label 1");
secondlabel =new Label("Label 2");
b1=new Button("Enter");
add(l1);
add(l2);
add(b1);

}
}
a) Firstlabel object is not declared
b) Secondlabel object is not declared
c) b1 object is not declared
d) All of above

128) What will be the missing statement in java to get following output:

import java.awt.*;
import java.applet.*;
/*<applet code=fontc width=500 height=500>
</applet>
*/
public class fontc extends Applet
{
public void init()
{
Font f=new Font("Times New Roman",Font.ITALIC,30)
setFont(f);
}
public void paint(Graphics g)
{
g.setColor(Color.red);
g.drawString("SAGAR",10,50);
}
}

A. Missing {
B. Missing }
C. Missing semicolon
D. Missing ()

129) What is the code to get the following output:


a) import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code=sample width=100 height=100>
</applet>
*/
public class sample extends Applet
{
Label l1,l2;
Button b1;
String msg="";
public void init()
{
l1=new Label("Label 1");
l2=new Label("Label 2");
b1=new Button("Enter");
add(l1);
add(l2);
add(b1);
}
}

b) import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code=sample width=100 height=100>
</applet>
*/
public class sample extends Applet
{
Label l1;
Button b1;
String msg="";
public void init()
{
l1=new Label("Label 1");
b1=new Button("Enter");
add(l1);

add(b1);
}
}

c) import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code=sample width=100 height=100>
</applet>
*/
public class sample extends Applet
{
Label l1,l2;
Button b1;
String msg="";
public void init()
{
l1=new Label("Label 1");
l2=new Label("Label 2");

add(l1);
add(l2);
}
}

d) import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code=sample width=100 height=100>
</applet>
*/
public class sample extends Applet
{
Label l1,l2;
Button b1;
String msg="";
public void init()
{
l1=new Label("Label 1");
l2=new Label("Label 2");
b1=new Button("Enter");
add(l1);
add(l2);
add(b1);
}
}

130) What is the output of the following code:

import java.awt.*;
import java.applet.*;
/*
<applet code="GridLayoutDemo" width=300 height=200></applet>
*/
public class GridLayoutDemo extends Applet
{
int n = 4;
public void init()
{
setLayout(new GridLayout(n,n,10,10));

for(int i = 0; i <n; i++)


{
for(int j = 0; j <n; j++)
{
add(new Button("k"));
}
}
}
}
a)

b)
c)none of the above
d)all of these

131) What will be the output of following code

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
class MenuFrame1 extends Frame
{
String msg = "";
MenuBar mbar;
MenuItem copy,paste,selectline,selectword,selectall;
CheckboxMenuItem open,cut;
TextField t1;
Menu file,edit,select,format;
public MenuFrame1()
{
mbar =new MenuBar();
setMenuBar(mbar);
file = new Menu("File");
open = new CheckboxMenuItem("open");
file.add(open);
mbar.add(file);
edit= new Menu("edit");
cut = new CheckboxMenuItem("cut");
copy = new MenuItem("copy");
paste = new MenuItem("paste");
edit.add(cut);
edit.add(copy);
edit.add(paste);
select =new Menu("select");
selectline = new MenuItem("selectline");
selectword = new MenuItem("selectword");
selectall = new MenuItem("selectall");
selectall.setEnabled(false);
select.add(selectline);
select.add(selectword);
select.add(selectall);
edit.add(select);
mbar.add(edit);
format =new Menu("format");
format.setEnabled(false);
mbar.add(format);
addWindowListener(new MyWindowAdapter1());

}
public static void main(String[] args)
{
MenuFrame1 mf =new MenuFrame1();
mf.setTitle("MenuFrame");
mf.setSize(300,200);
mf.setVisible(true);
}

class MyWindowAdapter1 extends WindowAdapter {


public void windowClosing(WindowEvent we) {
System.exit(0);
}
}
}

a)
b)

c)

d)

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

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

134) Which method will cause a Frame to be displayed?

a) show( )

b) setVisible( )

c) display( )

d) displayFrame( )

e) both a and b

135) The Choice component allows multiple selection.

a) True

b) False

136) The List component does not generate any events.

a) True

b) False
137) Which of the following components allow multiple selections?

a) Non-exclusive Checkboxes

b) Radio buttons

c) Choice

d) List

e) Both a and d

138) Which containers use a BorderLayout as their default layout?

a) Window

b) Frame

c) Dialog

d) All of above

139) Which containers use a FlowLayout as their default layout?

a) Panel

b) Applet

c) both a and b

d) only d

140) Which method returns the preferred size of a component?

a) getPreferredSize( )

b) getPreferred( )

c) getRequiredSize( )
d) getLayout( )

141) Which layout should you use to organize the components of a container in a tabular
form?

a) CardLayout

b) BorederLayout

c) FlowLayout

d) GridLayout

142) What is the default layouts for a applet, a frame and a panel?

a)Flow layout, Border layout, Flow layout

b)Flow layout, Flow layout, Border layout

c)Border layout, Flow layout, Flow layout

d)Border layout,Border layout, Flow layout

143) An Applet has its Layout Manager set to the default of FlowLayout. What code would be
the correct to change to another Layout Manager?

a)setLayoutManager(new GridLayout());

b)setLayout(new GridLayout(2,2));

c)setGridLayout(2,2,))

d)setBorderLayout();

144) Which is a dual state menu item?

a) CheckboxMenuItem
b)Menu

c)MenuItem

d) All of above

145) Which method can be used to enable/diable a checkbox menu item?

a)setState(boolean)

b) setstate(boolean)

c)setEnabled(boolean)

d)setenabled(boolean)

146) Which of the following may a menu contain?

a)A separator

b)A check box

c)A menu

d)A button

e)both a and c

Answer Key
Unit : 03
Event Handling
1) Which of these packages contains all the classes and methods required for even handling in Java?
a) java.applet
b) java.awt
c) java.event
d) java.awt.event

2) 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.

3) Which of these methods are used to register a keyboard event listener?

a) KeyListener()
b) addKistener()
c) addKeyListener()
d) eventKeyboardListener()

4) Which of these methods are used to register a mouse motion listener?


a) addMouse()
b) addMouseListener()
c) addMouseMotionListner()
d) eventMouseMotionListener()

5) Event class is defined in which of these libraries?


a) java.io
b) java.lang
c) java.net
d) java.util

6) Which of these methods can be used to determine the type of event?


a) getID()
b) getSource()
c) getEvent()
d) getEventObject()

7) Which of these class is super class of all the events?


a) EventClass
b) EventObject
c) ActionEvent
d) ItemEvent

8) Which of these events will be notified if scroll bar is manipulated?


a) ActionEvent
b) ComponentEvent
c) AdjustmentEvent
d) WindowEvent

9) Which of these events will be generated if we close an applet’s window?


a) ActionEvent
b) ComponentEvent
c) AdjustmentEvent
d) WindowEvent

10) The Following steps are required to perform


1) Implement the Listener interface and overrides its methods
2) Register the component with the Listener

a) Exception Handling
b) String Handling
c) Event Handling
d) None of the above

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

12) Which class header would be used to create an applet that accepts a click on a button?

a)public class MyApplet extends Japplet implements Listener


b)public class MyApplet extends Japplet implements ActionListener
c)public class MyAppletextends Japplet implements ActionEvent
d)public class MyApplet extends Japplet implements Event

13) Select correct Listener from given option for ******.


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

public class JR extends JApplet implements ***********


{
Container c=getContentPane();
public void init()
{
c.setLayout(new FlowLayout());
JRadioButton b1=new JRadioButton("red");
b1.addActionListener(this);
c.add(b1);

JRadioButton b2=new JRadioButton("blue");


b2.addActionListener(this);
c.add(b2);

JRadioButton b3=new JRadioButton("green");


b3.addActionListener(this);
c.add(b3);

ButtonGroup bg=new ButtonGroup();


bg.add(b1);
bg.add(b2);
bg.add(b3);
}
public void actionPerformed(ActionEvent e)
{
String str;
str=e.getActionCommand();
if(str=="red")
c.setBackground(Color.red);
else if(str=="blue")
c.setBackground(Color.blue);
else if(str=="green")
c.setBackground(Color.green);
}
}

/*<applet code=JR width=200 height=200></applet>*/

a) ItemListener
b) ActionListener
c) MouseListener
d) WindowListener

14) Which of these methods will respond when you click any button by mouse?

a) mouseClicked()
b) mouseEntered()
c) mousePressed()
d) All of the mentioned

15) Which is the integer constants of TextEvent class?


a) TEXT_CHANGED
b) TEXT_FORMAT_CHANGED
c) TEXT_VALUE_CHANGED
d) TEXT_SIZE_CHANGED

16) MouseEvent is subclass of which of these classes?


a) ComponentEvent
b) ContainerEvent
c) ItemEvent
d) InputEvent
17) An event is generated when the internal state of the event source is_____
a) Not changed
b) Changed
c) Either changed or not
d) None of these.

18) 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) Missing {
c) Missing }
d) Missing ()

19) Which of the following are correct event handling methods?

a) mousePressed(MouseEvent e){ }
b) MousePressed(MouseClick e){}
c) functionKey(KeyPress k){}
d) Added(ContainerEvent e){}
20) Which methods are used to close the window?
a) setVisible(false)
b) windowClosing()
c) stop()
d) Both a and b

21) To process scroll bar events, you need to implement ________________ interface.
a) adjustmentlistener
b) MouseListener
c)AdjustmentListener
d) KeyListener

22) KeyEvent is subclass of which of these classes?


a) ComponentEvent
b) ContainerEvent
c) ItemEvent
d) InputEvent

23) _________ and _____________is a subclass of InputEvent.


a) MouseEvent, KeyEvent
b)WindowEvent,ItemEvent
c)MouseMotionEvent,MouseWheelEvent
d)ActionEvent,AdjustmentEvent

24) ______________ method returns a value that indicates which modifier key were pressed when the
action event is generated.
a) getModifiers()
b) setModifiers()
c) getActionCommand()
d)none of these

25) Complete the following signature:


void addTreeExpansionListener(___________________________ tel)
a) Treeexpansion listener
b) TreeExpansionListener
c) TreeListener
d) treelistener

26) Constants for AdjustmentEvent class are:


a) BLOCK_INCREMENT
b) TRACK
c) UNIT_DEVREMENT
d) all of these
27) Which of these events will be generated if we close an applet’s window?
a)ActionEvent
b)ComponentEvent
c)AdjustmentEvent
d) WindowEvent

28) Which of the following is the highest class in the event delegation model?
a)java.util.EventListener
b) java.util.EventObject
c) java.awt.AWTEvent
d) java.awt.event.AWTEvent

29) ______ is an object that describes a state change in the source.


a) event
b) Source
c) none of the above
d) all the above

30) Which of these methods can be used to change location of an event?


a)changePoint()
b)translatePoint()
c) ChangeCordinates()
d) translateCordinates()

31) Which of these methods can be used to obtain the coordinates of a mouse?
a)getPoint()
b)getCoordinates()
c)getMouseXY()
d)getMouseCordinates()

32) Which of the following method is invoked when a window is changed from a normal to a minimized
state?
a) windowIconified()
b) windowClosed()
c)windowDeactivated
d) windowOpened()

33) Which of these is a superclass of all Adapter classes?


a)Panel
b) Applet
c) Component
d) Event

34) Which of the following method does not belongs to WindowListerner interface?
a) windowActivated
b) windowReactivated
c) windowDeiconified
d) windowClosed()

35) Which event is generating when checkable menu item is selected or deselected?
a) KeyEvent
b) ListEvent
c) ItemEvent
d) MouseEvent

36) Which are two ways to create Java Anonymous inner class?
a) Class, Interface
b) Applet
c) Panel, Frame
d)Event

37) The ___________method returns a reference to the component that was added to or removed from the
container.
a)getParent()
b)getComponent( )
c)getChild( )
d)geoReferenced()

38) Inner class can access all the members of outer class including_____data members and methods.
a) public
b)Protected
c)friend
d)private

39) In case of______ we can implement only required methods of any interface.
a)adapter classes
b)Event
c)EventObject
d)Listener

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

41) Which of the following are true?


a)The event-inheritance model has replaced the event-delegation model.
b) The event-inheritance model is more efficient than the event-delegation model.
c) The event-delegation model uses event listeners to define the methods of event-handling
classes.
d) The event-delegation model uses the handleEvent( ) method to support event handling.

42) Which of the following components generate action events?


a)Buttons
b)Labels
c)Check boxes
d) Windows
43) What is the preferred way to handle an object’s events in Java 2?
a) Override the object’s handleEvent( ) method.
b) Add one or more event listeners to handle the events.
c) Have the object override its processEvent( ) methods.
d) Have the object override its dispatchEvent( ) methods.

44) If a class MyWindowAdapter extends WindowAdapter and implements the windowClosing() method.
How to register this class ?
a) this.addWindowListener(new MyWindowAdapter());
b) addWindowListener(new MyWindowAdapter());
c) this.addListener(new MyWindowAdapter());
d) addWindowListener(new MyAdapter());

45) In the following code, what is the name of the inner class?

public class Periodical


{
long ISBN;
public class Book
{
public long getISBN()
{
retrun ISBN;
}
}
}
a) Periodical
b) book
c) Book
d) ISBN

46) What is the output of following code?

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="AdapterDemo" width=300 height=100> </applet>
*/
public class AdapterDemo extends Applet
{
public void init()
{
addMouseListener(new MyMouseAdapter(this));
}
}
class MyMouseAdapter extends MouseAdapter
{
AdapterDemo adapterDemo;
public MyMouseAdapter(AdapterDemo adapterDemo)
{
this.adapterDemo = adapterDemo;
} // Handle mouse clicked.

public void mouseClicked(MouseEvent me)


{
adapterDemo.showStatus("Mouse clicked");
}
}

a) Mouse pressed
b) Mouse clicked
c) Mouse dragged
d) Mouse released

47) Consider following code segment-

public void mousePressed(MouseEvent event)


{
System.out.println(event.getPoint());
}

Following code segement output is-


a) event generated
b) Print x co-ordinates
c) Display y co-ordinates
d) Print value of x and y co-ordinates

48) A general form, event registration method-


a) void addTypeListener (TypeListener el)
b) public void addTypeListener (TypeListener el)
c) public TypeListener (TypeListener el)
d) public void addTypeListener (el)

49) Identify correct methods in the place of blank space:

public class Test extends Applet implements _______________


{
String msg="";
public void init()
{
addKeyListener(this);
}
public void keyPressed(_____________ k)
{
showStatus("KeyPressed");
}
public void keyReleased(KeyEvent k)
{
showStatus("KeyRealesed");
}
public void keyTyped(KeyEvent k)
{
msg = msg+k.getKeyChar();
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg, 20, 40);
}
}

a)KeyListener, KeyEvent
b)MouseListener, MouseEvent
c)ActionListener, ActionEvent
d)WindowListener, WindowEvent

50) In the Delegation Event Model, a user interface element is able to delegate, the processing of an
event............................
a) class
b) a separate piece of code
c) interface
d) listener

51) Listeners are created by implementing one or more of the defined by the…………….
a) interfaces
b)class
c)listener
d)handler

52) The isPopupTrigger( ) methods returns-


a)string
b)integer
c) Boolean
d)long

53) The example of user interface elements that implement the ItemSelectable
interface-
a) checkbox and checkboxgroup
b) textfield and textarea
c) radiobutton and button
d) Lists and choices

54) public void removeTypeListener(TypeListener el)


Here Type means-
a) name of the event
b) type of listener
c) name of class
d) name of object

55) The getActionCommand( ) method returns-


a)string
b)integer
c) Boolean
d)long
56) The getItem( ) method can be used...........
a) name of the method
b) type of listener
c) name of class
d) to obtain a reference to the item that changed

57) The translatePoint( ) method-


a) display x and y coordinates
b) changes the location of the event
c) name of class
d) to obtain a reference to the item that changed

58) The WindowEvent class, WINDOW_DEACTIVATED, integer constants meaning-


a) This window has lost the focus.
b) Restoring the window to its original size.
c) Reducing the window from to minimized.
d) Reducing the window from to maximized.

59) The WindowEvent class, WINDOW_ICONIFIED, integer constants meaning-


a) This window has lost the focus.
b) Restoring the window to its original size.
c) Reducing the window from to minimized.
d) Reducing the window from to maximized.

60) The WindowEvent class, WINDOW_DEICONIFIED, integer constants meaning-


a) This window has lost the focus.
b) Restoring the window to its original size.
c) Reducing the window from to minimized.
d) Reducing the window from to maximized.

61) Which are the not types of key events-


a) KEY_DOUBLE
b) KEY_PRESSED
c) KEY_RELEASED
d) KEY_TYPED

62) MOUSE_WHEEL integer constants is belong to ___________- event.


a) MouseMotionEvent
b) MouseWheelEvent
c)MouseEvent
d)all of these

63) MouseWheelEvent is a subclass of_________________.


a) KeyEvent
b) MouseMotionEvent
c) MouseEvent
d) MouseWheelEvent

64) WindowEvent is a subclass of________________.


a) ComponentEvent
b) ContainerEvent
c) ActionEvent
d) AdjustmentEvent
65) Which one is not a method belong to ComponentListener Interface?
a) void componentResized(ComponentEvent ce)
b) void componentMoved(ComponentEvent ce)
c) void componentOpened(ComponentEvent ce)
d) void componentHidden(ComponentEvent ce)

66) ComponentAdded( ) and componentRemoved( ) are the methods of …………..


a)ComponentListener
b) MouseMotionEvent
c) ContainerListener
d) MouseWheelListener

67) When a component loses ___________focus, focusLost( ) is called.


a) keyboard
b)mouse
c)window
d) panel

68) Which method not use to obtain the coordinates of the mouse-
a) string getcode()
b) int GetKEY()
c) int getKeyCode( )
d) int getCode()

69) Which method used to capture ALT, CTRL, META OR SHIFT keys-
a) getModifiers( )
b) getMod( )
c) modifiers ( )
d) getAlt( )

70) Which top-level class provides methods to add and remove keyboard and mouse event
listeners-
a) Container
b) Applet
c) Window
d) Component

71) Write the correct code at blank space:

public class ………………. extends Frame implements WindowListener


{
WindowExample()
{
addWindowListener(this);
setSize(400,400);
setLayout(null);
setVisible(true);
}
public static void main(String[] args)
{
new WindowExample();
}

a) Frame
b) Window
c) WindowExample
d)Example

72) Assuming we have a class which implements the ActionListener interface, which method
should be used to register this with a Button?
a) EnterActionListener(*);
b) addListener(*);
c) ActionListener(*);
d)addActionListener(*);

73) Which of these interfaces define a method actionPerformed()?


a) KeyListener
b) ButtonListener
c) InputListener
d) ActionListener

74) keyPressed() is method of …………………… interface.


a) KeyListener
b) ButtonListener
c) InputListener
d) ActionListener

75) keyReleased() is mehod of ………….. interface.


a) ActionListener
b) ButtonListener
c) InputListener
d) KeyListener

76) keyTyped() is method of………………..interface.


a) ActionListener
b) ButtonListener
c) InputListener
d) KeyListener

77) mouseClicked() is method of…………………interface.


a) MouseListener
b) ButtonListener
c) InputListener
d) KeyListener

78) mouseEntered() is method of…………………interface.


a) InputListener
b) ButtonListener
c) MouseListener
d) KeyListener

79) mouseExited() is method of…………………interface.


a) MouseListener
b) ButtonListener
c)InputListener
d) KeyListener

80) mousePressed() is method of…………………interface.


a) InputListener
b) ButtonListener
c) MouseListener
d) KeyListener

81) Identify correct general form of MouseClicked( ) method of Mouse Listener interface.
a) void mouseClicked(me)
b) void Clicked(MouseEvent me)
c) void mouseClicked(MouseEvent me)
d) void mouseClick(MouseEvent me)

82) Select the method of MouseMotionListener Interface.


a) void mouseClicked(MouseEvent me)
b) void mouseEntered(MouseEvent me)
c)void mouseExited(MouseEvent me)
d) void mouseMoved(MouseEvent me)

83) Select the method of MouseWheelListener Interface.


a) void mouseClicked(MouseWheelEvent me)
b) void mouseEntered(MouseWheelEvent t me)
c) void mouseWheelMoved(MouseWheelEvent mwe)
d) void mouseExited(MouseWheelEvent me)

84) Which of these are methods of TextListener Interface?


a) textValueChanged()
b) setText()
c) textChanged()
d) getText()

85) Which of these method are used to register a keyboard event Listener ?
a) addMouseListener()
b) addKeyListener()
c) KeyListener()
d) addKey()

86) Which of these methods are used to register a mouse motion listener?
a) addMouseMotionListner()
b) addMouseListner()
c) addMouseWheelListner()
d) MouseMotionListner()

87) Which of these methods are used to register a Window listener?


a) addMouseMotionListner()
b) ComponentListner()
c) WindowListener()
d) addWindowListener()

88) Which source generates adjustment events?


a) Scroll bar
b) Checkbox
c) Radio Button
d)List

89) WindowActivated() is method of……………. interface.


a) WindowListener
b) KeyListener
c) AdjustmentListener
d)ContainerListener

90) windowClosed() is method of……………. interface.


a) KeyListener
b) WindowListener
c) AdjustmentListener
d)ContainerListener

91) windowDeactivated() is method of……………. interface.


a) WindowListener
b) KeyListener
c) AdjustmentListener
d)ContainerListener

92) windowDeiconified() () is method of……………. interface.


a) WindowListener
b) KeyListener
c)AdjustmentListener
d)ContainerListener

93) windowGainedFocus() and windowLostFocus() methods are belongs to …………………interface .


a) WindowListener
b) KeyListener
c)AdjustmentListener
d) WindowFocusListener

94) windowClosed() is method of……………. interface.


a) KeyListener
b) WindowListener
c)AdjustmentListener
d)ContainerListener

95) Identify the class which is not an adapter class?


a)FocusAdapter
b)KeyAdapter
c)WindowAdapter
d)ItemAdapter

96) Following are the integer constants which does not belong to ComponentEvent class .
a) COMPONENT_HIDDEN
b) COMPONENT_MOVED
c) COMPONENT_RESIZED
d) COMPONENT_ICONIFIED

97) Identify correct adapter in following code:

import java.applet.*;
import java.awt.event.*;
/*
<applet code="AnonymousInnerClassDemo" width=200 height=100>
</applet>
*/
public class AnonymousInnerClassDemo extends Applet
{
public void init()
{
addMouseListener(new ______________()
{
public void mousePressed(MouseEvent me)
{
showStatus("Mouse Pressed");
}
});
}
}

a) MouseAdapter
b) MouseMotion Adapter
c) KeyAdapter
d)mousepressed

98) An adapter class provides an ……………..implementation of all methods in an event listener interface.
a) interface
b) abstract
c) empty
d)runnable

99) Identify correct name of event:

public void adjustmentValueChanged(……………………. e)


{
Integer i =e.getValue();
frameLabel1.setText(i.toString());
}

a) ScroolbarEvent
b) AdjustmentEvent
c) ActionEvent
d)TextAreaEvent
100) Identify correct name of event:

public void mouseExited (________________ me)


{
// save coordinates
mouseX = 0;
mouseY = 10;
msg = "Mouse exited.";
repaint();
}

a) InputEvent
b) MouseMotionEvent
c) KeyEvent
d) MouseEvent

101) Fill correct listener names:

public class MouseEvents extends Applet


implements MouseListener, MouseMotionListener
{
String msg = "";
int mouseX = 0, mouseY = 0; // coordinates of mouse
public void init()
{
_______________ (this);
_______________ (this);
}

}
a) addListener, addMouseListener
b) addMouseMotionListener, addKeyListener
c) MouseListener , MotionListener
d) addMouseListener, addMouseMotionListener

102) Listeners are created by implementing one or more of the interfaces defined by the___________
package.
a) java.awt.event
b) java.util.event
c) java.lang.event
d)java.awt.listener

103) Identify the name of method which is not belong to WindowEvent.


a) int getOldState( )
b) int getNewState( )
c) Window OppositeWindow( )
d) Window getWindow( )

104) In List event source, generates _______events when an item is double-clicked.


a) action
b) item
c)text
d)window

105) In List event source, generates ___________ events when an item is selected or deselected.
a) action
b) item
c)text
d)window

106) In Menu Item, generates ____________ events when a menu item is selected.
a) action
b) item
c) text
d)window

107) In Menu Item, generates ________ events when a checkable menu item is selected or
deselected.
a) action
b) item
c) text
d) window

108) Identify the correct class name:


import java.awt.*;
import java.awt.event.*;
public class ________________ extends KeyAdapter
{
Label l;
TextArea area;
Frame f;
KeyAdapterExample()
{
f=new Frame("Key Adapter");
l=new Label();
l.setBounds(20,50,200,20);
area=new TextArea();
area.setBounds(20,80,300, 300);
area.addKeyListener(this);

f.add(l);
f.add(area);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
public void keyReleased(KeyEvent e) {
String text=area.getText();
String words[]=text.split("\\s");
l.setText("Words: "+words.length+" Characters:"+text.length());
}

public static void main(String[] args)


{
new KeyAdapterExample();
} }

a) KeyAdapterExample
b) KeyAdapter
c) KeyExample
d) AdapterExample

109) Identify the correct class name:

import java.awt.*;
import java.awt.event.*;
public class MouseAdapterExample extends MouseAdapter
{
Frame f;
MouseAdapterExample()
{
f=new Frame("Mouse Adapter");
f.addMouseListener(this);
f.setSize(300,300);
f.setLayout(null);
f.setVisible(true);
}
public void mouseClicked(MouseEvent e) {
Graphics g=f.getGraphics();
g.setColor(Color.BLUE);
g.fillOval(e.getX(),e.getY(),30,30);
}
public static void main(String[] args) {
new _______________();
}
}

a) mousePressed
b) MouseAdapterExample
c) mouseClicked
d) MouseAdapter

110) Which of these are integer constants defined in ActionEvent class?


a) ALT_MASK
b) CTRL_MASK
c) SHIFT_MASK
d) All of the mentioned

111) When the size of component is changed, ____________ event is generated.


a) ComponentEvent
b) ContainerEvent
c) FocusEvent
d) InputEvent
112) When the component is added or removed ? Which of these events is generated ?
a) ComponentEvent
b) ContainerEvent
c) FocusEvent
d) InputEvent

113) FocusEvent is subclass of which of these classes?


a) ComponentEvent
b) ContainerEvent
c) FocusEvent
d) InputEvent

114) Match the correct pairs-


a. getSource( ) i. Determine the type of the event
b. toString ( ) ii. Returns the source of the event
c. getID( ) iii- Constructor
d. EventObject(Object src) iv- returns the string equivalent of the event.

a) a-ii b-iv c-i d-iii


b) a-i b-iv c-ii d-iii
c) a-iii b-iv c-i d-ii
d) a-iv b-ii c-i d-iii

115) Match the correct pairs-


a. getKeyLocation() i. Set the keyCode value to indicate a physical key.
b. getKeyCode() ii. Returns the character associated with the key in this event.
c. getKeyChar() iii. Returns the location of the key that originated this key event.
d. setKeyCode(int keyCode) iv. Returns the integer keyCode associated with the key in this
event.

a) a-iii b-iv c-ii d-i


b) a-i b-iv c-ii d-iii
c) a-ii b-iv c-iii d-i
d) a-iv b-iii c-ii d-I

116) Consider following three statement


1) ActionListener Interace defines one method to receive action event
2) ItemListener Interface defines one method to recognize when the state of item change..
3) MouseListener interface defines mouseMoved() method

a) Statement 1 and 2 are true


b) Statement 1 and 3 are true
c) Statement 2 and 3 are true
d) All are true

117) Which of the following are true?


A) The MouseListener interface defines methods for handling mouse clicks.
B) The MouseMotionListener interface defines methods for handling mouse clicks.
C) The MouseClickListener interface defines methods for handling mouse clicks.
D) The ActionListener interface defines methods for handling the clicking of a button.
a) Statement A and D true
b) Statement A and C true
c) Statement B and D true
d) Statement C and D true

118) Which of the following statements are false


1)windowlistener define seven method
2)mouseMotionListerne define 2 method
3) ActionListener Interace defines three method to receive action event
4)KeyListener Interface define Three method

a) Statement 2 is False
b) Statement 3 is False
c) Statement 1 is False
d) Statement 1 and 4 are False

119) Consider the following code

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

a) output :Mouse Pressed


b) Error in code
c) Syntax error
d) Error in package

120) Fill in the blanks.

import java.applet.*;
import java.awt.event.*;
/*
<applet code="InnerClassDemo" width=200 height=100>
</applet>
*/
public class InnerClassDemo extends Applet {
public void init() {
__________ (new MyMouseAdapter());
}
class MyMouseAdapter extends _________________
{
public void mousePressed(MouseEvent me) {
showStatus("Mouse Pressed");
}
}
}

a) addMouseListener, MouseAdapter
b) addmouselistener, MouseAdapter
c) addMouseListener, mouseAdapter
d) addMouseListener, mouseadapter

121) Fill the proper name of class.

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*<applet code="AdapterDemo" width=300 height=100>
</applet>
*/
public class AdapterDemo extends Applet
{
public void init()
{
addMouseListener(new MyMouseAdapter(this));
}
}
class MyMouseAdapter extends MouseAdapter
{
_________________ adapterDemo;
public MyMouseAdapter(AdapterDemo adapterDemo)
{
this.adapterDemo = adapterDemo;
}
// Handle mouse clicked.
public void mouseClicked(MouseEvent me)
{
adapterDemo.showStatus("Mouse clicked");
}
}

a) AdapterDemo
b) adapterDemo
c) adapterdemo
d) Adapterdemo

122) The following code segment shows that a class MyWindowAdapter extends WindowAdapter and
implements the windowClosing() method.
Identify the correct adapter name and event name.

class MyWindowAdapter extends ________________


{
public void windowClosing(_____________ e)
{
System.exit(0);
}
}

a) WindowAdapter, WindowEvent
b) MyWindowAdapter, WindowEvent
c) WindowAdapter, windowEvent
d) WindowEvent, WindowAdapter

123) Identify the correct adapter name and event name.

public class MyFocusListener extends _______________


{
public void focusGained(_________________ fe)
{
Button button = (Button) fe.getSource();
label.setText(button.getLabel());
}
}

a) FocusAdapter, FocusEvent
b) focusAdapter, FocusEvent
c) focusadapter, FocusEvent
d) FocusAdapter, Focusevent

124) Identify the class which is not adapter class?


a)KeyAdapter
b)FocusAdapter
c)ItemAdapter
d)MouseMotionAdapter

125) Identify the correct event class


public void componentRemoved(____________________e)
{
displayMessage(" removed from ", e);
}

a) ContainerEvent
b) ComponentEvent
c) FocusEvent
d) WindowEvent

126) Find error in given program

import java.awt.*;
import java.awt.event.*;
public class KeyListenerExample extends Frame implements KeyListener { Label MyLAbel;
TextArea area;
KeyListenerExample()
{
MyLabel=new Label();
MyLabel.setBounds(20,50,100,20);
area=new TextArea();
area.setBounds(20,80,300, 300);
area.addKeyListener(this);
add(MyLabel);add(area);
setSize(400,400);
setLayout(null);
setVisible(true);

}
public void keyPressed(KeyEvent e)
{
MyLabel.setText("Key Pressed");
}
public void keyReleased(KeyEvent e)
{
MyLabel.setText("Key Released");
}
public static void main(String[] args)
{
new KeyListenerExample();
}
}

a) All methods of Interface are not implemented


b) Package is wrong
c) Code is correct
d) Compile time error

127) What is the output of the following java program?

class Outer
{
void outerMethod() {
System.out.println("inside outerMethod");
// Inner class is local to outerMethod()
class Inner
{
void innerMethod() {
System.out.println("inside innerMethod");
}
}
Inner y = new Inner();
y.innerMethod();
}
}
class MethodDemo
{
public static void main(String[] args) {
Outer x = new Outer();
x.outerMethod();
}
}

a)
inside outerMethod
inside innerMethod
b)
inside innerMethod
inside outerMethod
c)No output
d)inside innerMethod

128) Identify the incorrect Integer constants for WindowEvent.


a)WINDOW_ACTIVATED
b)WINDOW_DEACTIVATED
c)WINDOW_LOST_FOCUS
d)WINDOW_GOT_FOCUS

129) Which source generates adjustment events?


a) Scroll bar
b) MenuItem
c) Button
d) List
130) Which of these are methods of TextListener Interface?
a) textValuechanged()
b) textvalueChanged()
c) TextValueChanged()
d) textValueChanged()

131) Generates ______________________ when the user enters a character.


a) TextEvent
b) KeyEvent
c) MouseEvent
d) ComponentEvent

132) Identify the class which is not an adapter class?


a) MouseAdapter
b) ItemAdapter
c) WindowAdapter
d) KeyAdapter

133) Can outer Java classes access inner class private members?
a) Yes
b) No
134) An _______________ class listener interface and Event class Listener interface has
same name.
a) Main class
b) Adapter Class
c) Event Class
d) Inner Class

135) An adapter class provides an __________ implementation of all methods in an event listener
interface.
a) Complete
b) Multiple
c) Empty
d) None of above

136) Adapter classes are an _________ class for receiving various events.
a) Abstract class
b) Super class
c) Derived class
d) Base class

137) Which is the abstract adapter class for receiving keyboard focus events.
a) ComponentAdapter
b) KeyAdapter
c) FocusAdapter
d) MouseAdapter

138) An adapter class provides an empty implementation of all methods in an __________


a) event listener interface
b) KeyListenerInterface
c) MouseListenerInterface
d) None of above

139) How many method define in FocusListener interface.


a) 3
b) 5
c) 4
d) 2

140) How many method define in ContainerListener interface.


a) 2
b) 1
c) 4
d) 3

141) Fill in the blank: MouseListener interface define…........methods


a) 1
b) 5
c) 4
d) 7

142) Fill in the blank: MouseMotionListener interface define…........methods


a) 3
b) 4
c) 1
d) 2

143) WindowEvent is a subclass of


a) ComponentEvent
b) ContainerEvent
c) KeyEvent
d) InputEvent

144) Which method used to capture ALT, CTRL, META OR SHIFT keys-
a) getModifiers( )
b) getmodifiers( )
c) GetModifiers( )
d) Getmodifiers( )

145) Suppose that you want to have an object eh handle the TextEvent of a TextArea object t. How should
you add eh as the event handler for t?
a) t.addTextListener(eh);
b) eh.addTextListener(t);
c) addTextListener(eh.t);
d) addTextListener(t,eh);
Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

Multiple Choice Questions

Subject: AJAVA Semester:6th


Unit 1 & 2 – Applet Programming

1. The following example shows the creation of a


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

2. From the following statements which is a drawback for Applet?


a. It works at client side so less response time

b. Secured
c. It can be executed by browsers running under many platforms, including
Linux, Windows, and Mac Os etc.
d. Plugin is required at client browser to execute applet

3. Applet works at client side so less response time


a. True

b. False

4. The APPLET tag is used to start an applet from both an HTML document and from an
applet viewer.
a. True

b. False
Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

5. What invokes immediately after the start() method and also any time the applet needs to
repaint itself in the browser?
a. stop()
b. init()

c. paint()
d. destroy()

6. Which method is called only once during the run time of your applet?
a. stop()

b. paint()
c. init()

d. destroy()

7. When an applet is terminated which of the following sequence of methods calls take
place?
a. stop(),paint(),destroy()

b. destroy(),stop(),paint()
c. destroy(),stop()

d. stop(),destroy()

8. Which is a special type of program that is embedded in the webpage to generate the
dynamic content?
a. Package

b. Applet
c. Browser

d. None of the above

9. Applet runs inside the browser and does not works at client side.
a. True
b. False

10. Java Plug-in software is not responsible to manage the lifecycle of an Applet.
a. True

b. b. False
Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

11. What is used to run an Applet?


a. An html file

b. An Applet Viewer tool(for testing purpose)


c. Both A & B

d. None of the above

12. Which is the correct order of lifecycle in an applet?


a. Applet is started,initialized,painted,destroyed,stopped
b. Applet is painted,started,stopped,initilaized,destroyed

c. Applet is initialized,started,painted,stopped,destroyed
d. None of the above

13. Which method is used to suspend threads that don’t need to run when the applet is not
visible?
a. destroy()
b. paint()

c. stop()
d. start()

14. All Applets must import java.applet and java.awt.


a. True

b. False

15. When an applet begins, in which sequence will the AWT call the methods?
a. init(),paint(),start()
b. Start(),paint(),init()

c. intit(),start(),paint()
d. paint(),start(),init()

16. Which method is first Called for any applet when it starts its execution?
a. void init()

b. void destroy()
c. boolean isActive()

d. None of the above


Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

17. java.applet defines how many interfaces?


a. 2

b. 3
c. 4

d. 5

18. Which applet java.awt.component class provides the life cycle method?
a. public void paint(Graphics g)
b. public void destroy()

c. public void stop()


d. public void init()

19. Which is invoked after the init() method or browser is maximized?


a. public void start()

b. public void paint(Graphics g)


c. Public void stop()

d. Public void init()

20. Applet runs inside the browser and works at client side
a. True
b. False

21. Which of these functions is called to display the output of an applet?


a. display()

b. paint()
c. displayApplet()

d. printApplet()

22. Which of these methods can be used to output a string in an applet?


a. display()
b. print()
c. drawString()
d. transient()
Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

23. Which of these methods is a part of Abstract Window Toolkit (AWT) ?


a. display()

b. paint()
c. drawString()

d. transient()

24. Which of these operators can be used to get run time information about an object?
a. getInfo
b. Info

c. instanceof
d. getinfoof

25. What is output of following 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. A Simple Applet
b. A Simple Applet 20 20

c. Compilation Error
d. Runtime Error

26. What does AWT stands for?

a. All Window Tools

b. All Writing Tools


c. Abstract Window Toolkit

d. Abstract Writing Toolkit


Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

27. What is the length of the application box made by this program?
import java.awt.*;
import java.applet.*;
public class myapplet extends Applet {
Graphic g;
g.drawString("A Simple Applet", 20, 20);

}
a. 20
b. Default value

c. Compilation Error
d. Runtime Error

28. Before we try to write applets, we must make sure that Java is installed properly and also ensure
that either the java is installed properly and also ensure that either the java …………….. or a
java-enabled browser is available.
a. viewer( )

b. appletviewer( )
c. appletrunner( )

d. browserviewer( )

29. We can change the text to be displayed by an applet by supplying new text to be displayed by
an applet by supplying new text to the applet through a ……………………… tag.
a. <EDIT>

b. <CHANGE>
c. <REPLACE>

d. <PARAM>

30. The ……………….. attribute of applet tag specifies the amount of horizontal blank space the
browser should leave surrounding the applet.
a. SPACE=pixels

b. HSPACE=piexls
c. HWIDTH=piexls

d. HBLANK=pixels
Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

31. Which is a required attribute that gives the name of the file containing your applet’s
compiled .class file?
a. CODE
b. CODEBASE

c. ALT
d. NAME

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

33. The class at the top of the AWT hierarchy is


a. Component

b. Window
c. Container

d. Frame

34. Which package provides many event classes and Listener interfaces for event handling?
a. java.awt
b. java.lang

c. java.io
d. java.lang

35. Name the class which is used to represent a GUI application window, and is optionally
resizable and can have a title bar, an icon. Select the correct answer in the following.

a. Window
b. Panel

c. Dialog
d. Frame
Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

36. Which class can be used to represent a checkbox with a textual label that can appear in a
menu. Select the one correct answer.
a. MenuBar
b. MenuItem

c. CheckboxMenuItem
d. Menu

37. Which is/are used to create a Frame?

i. By creating the object of Frame Class(association)

ii. By extending Frame class(inheritance)


b. Only i

c. Only ii
d. Both

e. None

38. Which of the following methods can be used to change the size of a java.awt.Component
object?
a. dimension()

b. setSize()
c. resize()

d. size()

39. Which of the following sets the frame, say frame to 300 pixels wide by 200 high?
a. fram.setSize( 300, 200 );
b. fram.setSize( 300, 200 );

c. fram.paint( 300, 200 );


d. fram.setVisible( 300, 200 );

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

import java.awt.*;
public class microGUI
{
public static void main ( String[] args )
Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

{
Frame frm = new ___________( );
frm.___________( 150, 100 );
frm.___________( true );
}
}
a. Form, setVisible, setOn
b. Frame, setSize, setVisible
c. Frame, setVisible, setSize
d. Window, setSize, paint

41. Which package provides many methods for graphics programming?


a. java.awt
b. java.Applet

c. java.Graphics
d. java.io

42. Which of the following steps are must for any kind of event handling?
a. Implement the listener method(s) to receive and process event related
notifications
b. Adding mouse listener in the init() method.

c. Register the source(s) to receive notifications about specific type of event(s).


d. Adding mouse motion listener in the main() method .

43. Which of the following is/ are not related with keyboard event?
a. ClassKeyEvent is used to notify if any key pressed occurs or not.

b. The KeyListener should be added either in init() or the main method.


c. RequestFocus should be added either in init() or the main method.

d. The class InputEvent should be imported explicitly in the program.

44. Which of the following package supports event handling routine, when we use Swing
components in GUI programs?
a. javax.swing

b. java.awt
c. java.util

d. java.applet
Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

45. Which of the following displays components row-by-row in the order in which they were
added to the JFrame?
a. CardLayout
b. FlowLayout

c. BorderLayout
d. GridLayout

46. Using a FlowLayout manager, which is the correct way to add elements to a container?
a. add (component);

b. add("Center", component);
c. add(x, y, component);

d. set(component);

47. Which layout manager places components in one of five regions: north, south, east, west,
and center?
a. CardLayout

b. FlowLayout
c. BorderLayout

d. GridLayout

48. The MouseListener interface specifies the following methods: mouseClicked,


mouseEntered, mouse-Exited, mousePressed, and mouseReleased. In order to use a
MouseListener in your code, you must provide an implementation for which of the
following?
a. None of the MouseListener methods.

b. All MouseListener methods.


c. At least the mouseClicked method

d. Any one MouseListener method

49. Which class is used to create a pop-up list of items from which the user may choose?
a. JList
b. JChoice

c. JLabels
d. JCheckbox
Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

50. Where are the following four methods commonly used?


1) public void add(Component c)
2) public void setSize(int width,int height)
3) public void setLayout(LayoutManager m)
4) public void setVisible(boolean)

a. Graphics class

b. Component class
c. Both A & B

d. None of the above

51. Which is the container that doesn't contain title bar and MenuBars but it can have other
components like button, textfield etc?
a. Window

b. Frame
c. Panel

d. Container

52. Which method is used to set the graphics current color to the specified color in the
graphics class?
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

53. 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)

54. Which object can be constructed to show any number of choices in the visible window?
a. Labels

b. Choice
Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

c. List
d. Checkbox

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

56. Which method can set or change the text in a Label?


a. setText()
b. getText()

c. All the above


d. None of the above

57. The following


a) It is lightweight.
b) It supports pluggable look and feel.
c) It follows MVC (Model View Controller) architecture
are the advantages of _____ .
a. Swing

b. AWT
c. Both A & B

d. None of the above

58. The ActionListener interface is not used for handling action events.
a. True
b. False

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


Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

60. The Following steps are required to perform

1) Implement the Listener interface and overrides its methods


2) Register the component with the Listener
a. Exception Handling
b. String Handling

c. Event Handling
d. None of the above

61. Where can the event handling code be written?


a. Same class

b. Other class
c. Anonymous class

d. All mentioned above

62. AWT is used for GUI programming in java


a. True
b. False

63. The ActionListener interface is not used for handling action events
a. True

b. False
Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

Unit-3 JDBC

64. What is JDBC?


a. JDBC is a java based protocol.
b. JDBC is a standard Java API for database-independent connectivity between the
Java programming language and a wide range of databases.
c. JDBC is a specification to tell how to connect to a database.

d. Joint Driver for Basic Connection

65. Which of the following manages a list of database drivers in JDBC?


a. DriverManager
b. JDBC driver

c. Connection
d. Statement

66. Which of the following type of JDBC driver should be used if your Java application is
accessing multiple types of databases at the same time?
a. Type 1
b. Type 2
c. Type 3

d. Type 4

67. Which of the following is correct about JDBC?


a. JDBC architecture decouples an abstraction from its implementation.
b. JDBC follows a bridge design pattern.

c. Both of the above.


d. None of the above.

68. Which of the following step establishes a connection with a database?


a. Import packages containing the JDBC classes needed for database programming.

b. Register the JDBC driver, so that you can open a communications channel with
the database.

c. Open a connection using the DriverManager.getConnection () method.


d. Execute a query using an object of type Statement.
Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

69. Which of the following is true about JDBC?


a. The JDBC API is an API to access different relational databases.

b. You use it to access relational databases without embedding a dependency on a


specific database type in your code.

c. JDBC stands for Java DataBase Connectivity.


d. All of the above.

70. Which of the following is advantage of using JDBC connection pool?


a. Slow performance

b. Using more memory


c. Using less memory

d. Better performance

71. How many Result sets available with the JDBC 2.0 core API?
a. 2
b. 3

c. 4
d. 5

72. Which method is used to establish the connection with the specified url in a Driver
Manager class?
a. public static void registerDriver(Driver driver)
b. public static void deregisterDriver(Driver driver)

c. public static Connection getConnection(String url)


d. public static Connection getConnection(String url,String userName,String
password)

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


Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

74. JDBC RowSet is the wrapper of ResultSet,It holds tabular data like ResultSet but it is
easy and flexible to use.
a. True
b. False

75. The ResultSet.next method is used to move to the next row of the ResultSet, making it the
current row.
a. True
b. False

76. Which JDBC product components does the Java software provide?
a. The JDBC driver manager

b. The JDBC driver test suite


c. The JDBC-ODBC bridge

d. All mentioned above

77. Which class has traditionally been the backbone of the JDBC architecture?
a. the JDBC driver manager
b. the JDBC driver test suite

c. the JDBC-ODBC bridge


d. All mentioned above

78. Which was the first most widely used programming interface for accessing relational
databases and it offers the ability to connect all the databases on all the platforms.?
a. JDBC API
b. ODBC API

c. Both A & B
d. None of the above

79. JDBC is a Java API that is used to connect and execute query to the database
a. True

b. False
Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

80. In the following JDBC drivers which is known as fully java driver?
a. Native-API driver

b. Network Protocol driver


c. Thin driver

d. Both B & C

81. Which JDBC drivers will run your program?


a. The JDBC-ODBC bridge
b. The JDBC driver manager

c. The JDBC driver test suite


d. None of the above

82. What is the reason that a java program cannot directly communicate with an ODBC
driver?
a. ODBC written in C# language
b. ODBC written in C language

c. ODBC written in C++ language


d. None of the above

83. A leading database connectivity vendor, worked together to produce the ____.
a. JDBC-ODBC Bridge

b. JDBC Driver Test Suite


c. Both A & B

d. None of the above

84. Which driver converts JDBC calls directly into the vendor-specific database protocol?
a. Native - API driver
b. Network Protocol driver

c. Thin driver
d. Both B & C

85. Which models do the JDBC API support for the database access?
a. Two-tier models

b. Three-tier models
Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

c. Both A & B
d. None of the above

86. Which of the following JDBC drivers is known as a partially java driver?
a. JDBC-ODBC bridge driver

b. Native-API driver
c. Network Protocol driver

d. Thin driver

87. The JDBC API is what allows access to a data source from a Java middle tier
a. True
b. False

88. Which driver uses ODBC driver to connect to the database?


a. JDBC-ODBC bridge driver

b. Native - API driver


c. Network Protocol driver

d. Thin driver

89. How many JDBC product components does the Java software provides?
a. 3
b. 2

c. 4
d. 5

90. How many types of JDBC drivers are available?


a. 3

b. 4
c. 2

d. 5
Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

Unit – 4 Servlet

91. Which type of ServletEngine is a server that includes built-in support for servlets?
a. Add-on ServletEngin
b. Embedded ServletEngine

c. Standalone ServletEngine
d. None of the above

92. What type of servlets use these methods doGet(), doPost(),doHead, doDelete(),
doTrace()?
a. Genereic Servlets
b. HttpServlets

c. All of the above


d. None of the above

93. Which cookie it is valid for single session only and it is removed each time when the user
closes the browser?
a. Persistent cookie
b. Non-persistent cookie
c. All the above

d. None of the above

94. Sessions is a part of the SessionTracking and it is for maintaining the client state at server
side.
a. True

b. False

95. Web server is used for loading the init() method of servlet.
a. True
b. False

96. Servlets handle multiple simultaneous requests by using threads.


a. True

b. False
Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

97. Which method is used to send the same request and response objects to another servlet in
RequestDispacher ?
a. forward()
b. sendRedirect()

c. Both A & B
d. None of the above

98. The sendRedirect() method of HttpServletResponse interface can be used to redirect


response to another resource, it may be servlet, jsp or html file
a. True
b. False

99. Which packages represent interfaces and classes for servlet API?
a. javax.servlet

b. javax.servlet.http
c. Both A & B

d. None of the above

100. Which class can handle any type of request so that it is protocol-independent?
a. GenericServlet
b. HttpServle

c. Both A & B
d. None of the above

101. Which HTTP Request method is non-idempotent?


a. GET

b. POST
c. Both A & B

d. None of the above

102. Which object is created by the web container at time of deploying the project?
a. ServletConfig
b. ServletContext
Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

c. Both A & B
d. None of the above

103. What is the lifecycle of a servlet?


a. Servlet class is loaded

b. Servlet instance is created


c. init,Service,destroy method is invoked

d. All mentioned above

104. Which method in session tracking is used in a bit of information that is sent by a web
server to a browser and which can later be read back from that browser?
a. HttpSession

b. URL rewriting
c. Cookies

d. Hidden form fields

105. Which are the examples of Application Server?


a. Apache
b. Tomcat

c. JBoss
d. Weblogic

106. How many techniques are used in Session Tracking?


a. 4

b. 3
c. 2

d. 5

107. In HTTP Request method Get request is secured because data is exposed in URL bar
a. True
b. False

108. In the following statements identify the disadvantages of CGI?


Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

a. If number of clients increases, it takes more time for sending response


b. For each request, it starts a process and Web server is limited to start processes

c. It uses platform dependent language e.g. C, C++, perl


d. All mentioned above

109. Servlet technology is used to create web application


a. True

b. False

110. Which method is used to specify before any lines that uses the PintWriter?
a. setPageType()
b. setContextType()

c. setContentType()
d. setResponseType()

111. What are functions of Servlet container?


a. Lifecycle management

b. Communication Support
c. Multithreading Support

d. All of the above

112. Which object of HttpSession can be used to view and manipulate information about a
session?
a. session identifier

b. creation time
c. last accessed time

d. All mentioned above

113. Which methods are used to bind the objects on HttpSession instance and get the
objects?
a. setAttribute

b. getAttribute
c. Both A & B
Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

d. None of the above

114. Which method take a string not a URL?


a. sendRedirect
b. forward

c. Both
d. None

115. Which of the following are interface? 1. ServletContext 2. Servlet 3. GenericServlet 4.


HttpServlet
a. 1,2,3,4
b. 1,2

c. 1,2,3
d. 1,4

116. The life cycle of a servlet is managed by


a. servlet context

b. servlet container
c. the supporting protocol (such as http or https)

d. All of the above

117. Which of the following code is used to get an attribute in a HTTP Session object in
servlets?
a. session.getAttribute(String name)

b. session.alterAttribute(String name)
c. session.updateAttribute(String name)

d. session.setAttribute(String name)

118. What is the difference between servlets and applets?


i. Servlets execute on Server; Applets execute on browser
ii. Servlets have no GUI; Applet has GUI
iii. Servlets creates static web pages; Applets creates dynamic web pages
iv. Servlets can handle only a single request; Applet can handle multiple requests
a. i, ii, iii are correct
Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

b. i, ii are correct
c. i, iii are correct

d. i, ii, iii, iv are correct

119. Which are the session tracking techniques?


i. URL rewriting
ii. Using session object
iii.Using response object
iv. Using hidden fields
v. Using cookies
vi. Using servlet object
a. i, ii, iii, vi
b. i, ii, iv, v

c. i, vi, iii, v
d. i, ii, iii, v

120. A deployment descriptor describes


a. Web component response settings

b. Web component setting


c. Web component request objects

d. All of the above

121. The values of <servlet-name> and <servlet-class> in web.xml file


a. must be same
b. must not be same

c. may be same
d. None of the above
Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

Unit – 5 JSP

122. Which attribute specifies a JSP page that should process any exceptions thrown but
not caught in the current page?
a. The ErrorPage Attribute

b. The IsErrorPage Attribute


c. Both A & B

d. None of the above

123. The ASP and JSP technologies are quite similar in the way they support the creation
of Dynamic pages, using HTML templates, scripting code and components for business
logic.
a. True
b. False

124. Which of the following is an advantage of the statement – Separation of business


logic from JSP ?
a. Custom Tags in JSP
b. JSP Standard Tag Library
c. All the above

d. None of the above

125. JSPs eventually are compiled into Java servlets, you can do as much with JSPs as you
can do with Java servlets.
a. True

b. False

126. JavaServer Pages often serve the same purpose as programs implemented using the
Common Gateway Interface (CGI)
a. True

b. False

127. Which technology do we mix our business logic with the presentation logic?
a. Servlet
b. JSP

c. Both A and B
Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

d. None of the above

128. Which is the Microsoft solution for providing dynamic Web content?
a. ASP
b. JSP

c. Both A and B
d. None of the above

129. Which tag is used to execute java source code in JSP?


a. Declaration Tag

b. Scriptlet tag
c. Expression tag

d. None of the above

130. A JSP page consists of which tags?


a. HTML tags
b. JSP tags

c. Both A & B
d. None of the above

131. Which packages does a JSP API consist of?


a. javax.servlet.jsp

b. java.servlet
c. javax.servlet.jsp.tagext

d. Both A & C

132. Which of the scripting of JSP not putting content into service method of the converted
servlet?
a. Declarations

b. Scriptlets
c. Expressions
d. None of the above

133. The difference between Servlets and JSP is the …………….


Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

a. translation
b. compilation

c. syntax
d. Both A and B

134. Which of the following are the valid scopes in JSP?


a. request, page, session, application

b. request, page, session, global


c. response, page, session, application

d. request, page, context, application

135. JSP includes a mechanism for defining …………………………. or custom tags.


a. static attributes
b. local attributes

c. dynamic attributes
d. global attributes

136. Why DB connections are not written directly in JSPs?


a. Response is slow

b. Not a standard J2EE architecture


c. Load Balancing is not possible

d. Both B and C

137. Which is not a directive?


a. include
b. page

c. export
d. taglib

138. Which http method send by browser that asks the server to get the page only?
a. get

b. option
c. put
Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

d. post

139. Which tag should be used to pass information from JSP to included JSP?
a. Using <%jsp:page> tag
b. Using <%jsp:param> tag

c. Using <%jsp:import> tag


d. Using <%jsp:useBean> tag

140. _jspService() method of HttpJspPage class should not be overridden.


a. True

b. False

141. Which one is the correct order of phases in JSP life cycle?
a. Initialization, Cleanup, Compilation, Execution
b. Initialization, Compilation, Cleanup, Execution

c. Compilation, Initialization, Execution, Cleanup


d. Cleanup, Compilation, Initialization, Execution

142. Which is not a directive?


a. include

b. page
c. export

d. useBean

143. Which of the following is true about servlets?


a. Servlets execute within the address space of web server
b. Servlets are platform-independent because they are written in java

c. Servlets can use the full functionality of the Java class libraries
d. Servlets execute within the address space of web server, platform independent
and uses the functionality of java class libraries

144. What do you mean by nameless objects?


Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

a. An object created by using the new keyword.


b. An object of a superclass created in the subclass.

c. An object without having any name but having a reference.


d. An object that has no reference.

145. Which of the following is an immediate subclass of the Panel class?


a. Applet class

b. Window class
c. Frame class

d. Dialog class

146. Servlet are used to program which component in a web application?


a. Client

b. Server
c. Tomcat

d. Applet

147. Which class is super class in AWT Hierarchy ?


a. Container
b. List
c. Component
d. Panel

148. Which are the common security restrictions in applets?


a. Applets can't load libraries or define native methods
b. An applet can't read every system property
c. Applets can play sounds

d. Both A & B

149. Applets cannot make network connection exception to the server host from which it
originated.
a. True

b. False
Faculty of Diploma Studies – 695
Department of Computer Engineering – 07
AJAVA IMP Questions Bank

150. For Event handling, what is not required?


a. Listener

b. Event Class
c. Inner class

d. Listener Interface method

151. Which Component class is not in java.awt package?


a. Button
b. TextArea

c. TextField
d. RadioButton
Unit :01
Abstract Windowing Toolkit (AWT)
1) The various controls supported by AWT are
a) Labels, push buttons
b) Checkboxes, choice, list
c) Scroll bars, text area, text field

d) All of these

2) The concept of the menu bar can be implemented by using three java classes—
a) MenuBar
b) Menu
c) MenuItem

d) All of these

3) The constructor which the Text Event class defines.


a) TextEvent(Object source, int event_type)
b) textevent (Object source, int event_type)
c) textevent (object Source, float event_type)
d) textevent (Object source, string event_type)

4) In Java an event is an _______which specifies the change of state in the source.


a) Class

b) Object
c) Int
d) String

5) The classes and interfaces defined in AWT are contained within the ______ package.
a) java.awt.*
b) java.sql.*
c) java.io.*
d) java.int*
6) 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)

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

8) A checkbox is a control that consists of a


a) Combination of a small box
b) A label
c) Combination of a large box and a label

d) Both a & b

9) Java applets are used to create _______________ applications


a) Graphical
b) User interactive

c) Both a & b
d) None of these

10) AWT means


a) Abstract Window Toolkit
b) Abstract Window Toollayout
c) Abstract Withdraw Tools
d) Abstract Window Title
11) An event is generated when the internal state of the event source is________
a) Not changed

b) Changed
c) Either changed or not
d) None of these

12) Positions the components into five regions:east, west, north, south, center
a) BorderLayout
b) CardLayout
c) GridLayout
d) FlowLayout

13) Arranges the components as a deck of cards such that only one component is visible at a
time
a) BorderLayout

b) CardLayout
c) GridLayout
d) FlowLayout

14) Arranges the components horizontally


a) BorderLayout
b) CardLayout
c) GridLayout

d) FlowLayout

15) Arranges the componemnts into grid


a) BorderLayout
b) CardLayout

c)GridLayout
d) FlowLayout
16) __________ creates a dropdown list of textual entries
a) Choice
b) Checkbox
c) Textbox
d) TextComponent

17) The Component class is an abstract class and so its ____________ are used to create
components.
a) Subclasses
b)Superclasses
c) Both a & b
d)None of these

18) The AWT classes can be roughly categorized into the following groups:
a) GUI Components
b) Layouts
c) Graphics Tools
d) Event Handlers

e) All of these

19) An Applet is a ________ of Panel:


a) Subclass
b) Superclass
c) Both a & b
d) None of these

20) The subclasses of Window are


a) Dialog
b) Frame
c) Both a & b
d) None of these

21) A menu bar represents


a) A list of menus which can be added to the top of a top-level window
b) A list of menus which can be deleted to the top of a top-level window
c) A list of menus which can be added to the bottom of a bottom-level window
d) None of these

22) Each menu is associated with a _________ list of menu items:


a) Checkbox

b) Drop-down
c) Choice
d) None of these

23) The two types of menus which are given as follows:


a) Pop-up menus
b) Regular menus

c) Both a & b
d) None of these

24) Regular menus are placed at the __________ of the application window within a menu
bar
a) Top
b) Bottom
c) Top-down
d) Botttom-up

25) The text field and text area controls create a _________________ area respectively
a) Single-line text
b) Multi-line text

c) Both a & b
d) None of these
26) A push button is an active control that has a _____________ appearance
a) One dimensional
b) Two dimensional

c) Three dimensional
d) None of these

27) _____________ is a superclass of TextField and TextArea classes that is used to create
single-line or multiline textfields respectively:
a)TextBox
b)CheckBox

c)TextComponent
d)Choice

28) A label is a simple control which is used to display_____________ on the window:

a) Text(non-editable)
b) Text(editable)
c) Both a & b
d) None of these

29) ______________ is an abstract class that encapsulates all of the attributes of a visual
component.
a)Component
b)Window
c)Frame
d) Panel

30) A _______ object is responsible for remembering the current foreground and
background colors
a)Window

b)Component
c)None
d)Both

31) Which class is a subclass of Component?

a) Container
b) Window
c) Frame
d) none

32)The ______ class is a concrete subclass of Container.


a) Container
b) Window

c) Panel
d ) None

33)Panel is a superclass for _____.


a) Window
b) Frame

c) Applet
d) None

34) Which is a container that does not contain a title bar, menu bar, or border?
a)Window
b)Frame

c)Panel
d)Container

35)Name the class used to represent GUI component that has a title bar, menu bar, borders,
and resizing corners.
a) Window
b) Container
c) Frame
d) Panel

36) How many Frame constructor are present?


a) 1

b) 2
c) 3
d) 4

37) Which method is used to set title for the Frame window?
a)Frame()

b)Frame(String title)
c) Frame(String title,int x,int y)
d) None

38) Which method is used to set the dimensions of the window?


a)setSize()
b)void setSize(int newWidth, int newHeight)
c)void setSize(Dimension newSize)
d)All of the above

39) The ____ method is used to obtain the current size of a window.

a) getSize()
b)setSize()
c)None
d)Both

40)Which method is used for hiding and showing a window in the frame window.
a)setVisible()
b)getVisible( )
c)both
d)None

41) To implement the windowClosing() method which interface is used?


a) ActionListener
b) ItemListener

c) WindowListener
c) None

42) Which of these packages contains all the classes and methods required for event
handling
a) java.awt.Applet;

b) java.awt.event;
c) java.awt;
d) java.event;

43) On invoking repaint() method for a Component the method invoked by AWT is:
a)draw( )
b)show( )
c)update( )

d) paint( )

44) Which of these events will be generated if we close the applet?


a)ActionListener
b)ItemListener
c)MouseListener
d)WindowListener

45) _______ encapsulates a semantics-free window.


a)Frame
b)Panel

c)Canvas
d)None

46)The class at the top of the AWT hierarchy

a)Component
b)Frame
c)Window
d)Panel

47)Which class dispatches events to multiple listener


a)AWTEvent

b)AWTEventMulticaster
c)AWTEventManager
d) All of the Above

48) Add instance of the desired control to the window by calling ____ method, defined by
____ class.

a)add() , Container
b)add() , Component
c)addTo() , Container
d)addTo(), Component

49)To remove a control from a window ___ method is used.


a)removeControl()

b)remove()
c)removeAll()
d)None of the above

50)You can remove all controls by calling method.


a)remove()
b)removeFrom()
c)Remove()

d)removeAll( )

51)Label defines the following constructors:


a)Label( )
b)Label(String str)
c)Label(String str, int how)

d)All of the above

52)In the Label(String str, int how) constructor value of how will be-

a)Label.LEFT, Label.RIGHT, or Label.CENTER


b)Label.LEFT, Label.RIGHT, or Label.DOWN
c)Label.TOP, Label.BOTTOM, or Label.CENTER
d)Label.TOP, Label.BOTTOM, or Label.DOWN

53)To set or change the text in a label __ method and to obtain the current label by calling
___ method is used.
a)setTxt() , getTxt()
b)settext() , gettext()
c)setText() , getText()
d)getText() , setText()

54)To set the alignment of the string within the label by calling ___ method ,to obtain the
current alignment ___ method is used.
a)getAlignment( ) ,setAlignment( )
b)setAlign( ) ,getAlign( )

c)setAlignment( ) ,getAlignment( )
d)getAlign( ) ,setAlign( )

55) Which packages will use for the following code:


/*
<applet code="LabelDemo" width=300 height=200>
</applet>
*/
public class LabelDemo extends Applet {
public void init() {
Label one = new Label("One");
Label two = new Label("Two");
Label three = new Label("Three");
// add labels to applet window
add(one);
add(two);
add(three);
}
}
a) import java.awt.*; import java.applet.*;
b) import javax.swing.*; import java.awt.*;
c) import javax.swing.*; import java.applet.*;
d) d)import java.applet.*; import java.awt.event.*;

56) Button defines these two constructors:


a) Button( ), Button(Boolean str)
b) Button( ) ,Button(int str)

c) Button( ), Button(String str)


d) Button( ) ,Button(String str , int name)

57) Set label of a button by calling __ method and can retrieve its label by calling __
method.
a) getLabel( ) , setLabel( )

b) setLabel( ) , getLabel( )
c) getlabel( ) , setlabel( )
d) d)setlabel( ) , getlabel( )

58) Each time a button is pressed, an ___ is generated.


a) mouse event
b) Keyboard event
c) item event

d) action event

59) For button __ interface is implemented.

a)ActionListener
b)ItemListener
c)MouseListener
d)FocusListener
60) actionPerformed() method is used in ___ interface.

a)ActionListener
b)ItemListener
c)MouseListener
d)FocusListener

61)Which class can be used to represent a checkbox with a textual label that can appear in a
menu.
a)MenuBar
b) MenuItem

c)CheckboxMenuItem
d)Menu

62) To retrieve the current state of a check box, call __ method , to set its state, call __
method.
a) setState( ) , getState( )

b) getState( ) , setState( )
c) setstate( ) , getstate( )
d) getstate( ) , setstate( )

63) Event handling in checkbox is done by __ listener and __ object is used.

a)ItemListener , ItemEvent
b)MouseListener , MouseEvent
c)ActionListener , ActionEvent
d)KeyListener , KeyEvent

64) Which method is defined by the ItemListener interface?


a)actionPerformed()
b)ActionPerformed()

c)itemStateChanged()
d)ItemstateChanged()

65) Choose the correct:


a)public class CheckboxDemo implement Applet extend ItemListener

b)public class CheckboxDemo extends Applet implements ItemListener


c)public class CheckboxDemo implements Applet extends ItemListener
d)public class CheckboxDemo extend Applet implement ItemListener

66) .It is possible to create a set of mutually exclusive check boxes in which one and only
one check box in the group can be checked at any one time by using __ component.

a) CheckboxGroup
b) Radio Button
c) Checkbox
d) Choice

67) You can determine which checkbox in a group is currently selected by calling __
method.
a)getselectedCheckbox( )
b)GetSelectedCheckbox( )

c)getSelectedCheckbox( )
d)None of the above

68)To set a checkbox which method is used-


a)setselectedCheckbox( )
b)setSelectedCheckbox( )
c)getselectedCheckbox( )
d)getSelectedCheckbox( )

69)In which of the following the only one checkbox will be selected.
a)Checkbox Win98 = new Checkbox("Windows 98/XP", cbg, false);

b)Checkbox Win98 = new Checkbox("Windows 98/XP", cbg, true);


c)Checkbox Win98 = new Checkbox("Windows 98/XP", true);
d)Checkbox Win98 = new Checkbox("Windows 98/XP", false);

70) Which class is used to create a pop-up list of items from which the user may choose.

a) Choice
b) List
c) Checkbox
d) CheckboxGroup

71) Method used to add items in a choice-


a)addItem()
b)additem()
c)Add()

d)add()

72)To determine which item is currently selected, you may call either ___ or ____ method.
a)setSelectedItem( ),setSelectedIndex( )
b)GetSelectedItem( ),GetSelectedIndex( )

c)getSelectedItem( ),getSelectedIndex( )
d)getselectedItem( ),getselectedIndex( )
73)The getItemCount( ) method is used to-
a)To obtain the value of items in the list

b)To obtain the number of items in the list


c)Both a & b
d)None of the above

74) Constuctors of scrollbar are-


a) Scrollbar( ) ,Scrollbar(int style) ,Scrollbar(int style, int initialValue, int thumbSize)
b) Scrollbar( ), Scrollbar(int style) ,Scrollbar(int style, int initialValue, int thumbSize, int
min
c) Scrollbar( ),Scrollbar(int style),Scrollbar(int style, int initialValue, int thumbSize, int
max)
d) Scrollbar( ),Scrollbar(int style),Scrollbar(int style, int initialValue, int thumbSize,
int min, int max)

75) Scrollbar uses which two constants to create horizontal and vertical scrollbar.
a)Scrollbar.Vertical , Scrollbar.Horizontal
b)Vertical.SCROLLBAR , Horizontal.SCROLLBAR

c)Scrollbar.VERTICAL , Scrollbar.HORIZONTAL
d)None of the above

76) To obtain the current value of the scroll bar, call ___, to set the current value, call __
method.
a) setvalue( ), getvalue( )
b) setValue( ) , getValue( )
c) getvalue( ). setvalue( )

d) getValue( ) , setValue( )

77) You can retrieve the minimum and maximum values of scrollbar by __ and___ method
a)getMinimum( ), getMaximum( )
b)getMax(), getMin()
c)setMinimum(), setMaximum()
d)setMax(), setMin()

78) Which interface is implemented for handling scrollbars.


a)ActionListener

b)AdjustmentListener
c)MouseMotionListener
d)ItemListener

79) The________ class implements a single-line text-entry area


a)TextArea class

b)TextField class
c)both a & b
d)none of the above

80) Which of these is not aTextField Constructor


a)TextField( )
b)TextField(intnumChars)

c)TextField(int rows)
d)TextField(Stringstr)

81) To obtain the text currently in the text field, which method is used?
a) getWord()
b) getString()
c) getText()
d) getRow()

82) Program can obtain the currently selected text by calling _________

a) getSelectedText()
b) getText()
c) getSelected()
d) getEdit()

83) Contents of a text field may be modified by the user by calling

a) setEditable( )
b) getEditable()
c) isEditable()
d) None of the above

84) The echoing of the characters as they are typed by calling


a) setPassword()

b) setEchoChar( )
c) hideText()
d) setChar()

85) The AWT includes a simple multiline editor called


a)TextField

b)TextArea
c)Editor
d)Label

86)Which of the following is not a constructor of TextArea


a)TextArea(String str)
b)TextArea(intnumLines, intnumChars)
c)TextArea(Stringstr, intnumLines, intnumChars, intsBars)

d)TextArea(Stringstr, intsrows)

87) Which methods is not supported by TextArea


a) getText()

b) setFormat()
c) setText()
d) SetEditable()

88) The________method appends the string specified by str to the end of the current text.

a)append()
b)insertText()
c)attach()
d)editText()

89) ____ method inserts the string passed in str at the specified index.
a)append()
b)attachText()

c)insert()
d)join()

90) To replace a text, which method is called?


a) replaceText()
b) changeText()
c) editText()
d) replaceRange()

91) Each ______ object has a layout manager associated with it.
a) Applet
b) Frame
c) Panel

d) Container

92) A layout manager is an instance of any class that implements the _______ interface.

a) LayoutManager
b) ActionListener
c) ItemListener
d) MouseListener

93) The layout manager is set by which method.


a) setText()
b) getText()

c) setLayout( )
d) setVisible()

94) Which method is used to determine position and shape of a component manually
a) setBounds()
b) setPosition()

c) Both a and b
d) None

95) Which of the following LayouManager is/are consulted whenever the container needs to
be resized
a) minimumLayoutSize( )
b) preferredLayoutSize( )

c) Both
d) None

96) _____ and _____ are contained by each Layout manager

a) getPrefferedSize(),getMinimumSize( )
b) getPrefferedsize(),getMinimumsize( )
c) getprefferedSize(),getminimumSize( )
d) None

97) Which of these is the default Layout Manager

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

98) Constructors of FlowLayout


a) FlowLayout( )
b) FlowLayout(int how)
c) FlowLayout(int how, int horz, int vert)

d) All of the above

99) In the constructor FlowLayout(int how, int horz, int vert) what is the value of how

a) FlowLayout.LEFT,FlowLayout.CENTER,FlowLayout.RIGHT
b) FlowLayout.TOP,FlowLayout.BOTTOM,FlowLayout.CENTE
c) FlowLayout.EAST,FlowLayout.WEST, FlowLayout.CENTER
d) None

100) Constructors of BorderLayout


a) BorderLayout( ),
b) BorderLayout(int horz, int vert)
c) BorderLayout(int how, int horz, int vert)

d) Both a and b

101) Constants of BorderLayout

a) BorderLayout.CENTER,BorderLayout.SOUTH,BorderLayout.EAST,
BorderLayout.WEST, BorderLayout.NORTH
b) BorderLayout.CENTER, BorderLayout.TOP, BorderLayout.BOTTOM,
BorderLayout.LEFT, BorderLayout.RIGHT
c) BorderLayout.CENTER, BorderLayout.LEFT, BorderLayout.RIGHT,
d) None of the above

102) GridLayout lays out components in a ______ grid.


a) One-dimensional
b) Three-dimensional
c) Multi-dimensional

d) Two-dimensional

103) Construcors of GridLayout


a) GridLayout( )
b) GridLayout(int numRow,numColumns )
c) GridLayout(int numRows, int numColumns, int horz, int vert)
d) All of the Above
104) The CardLayout class is ______ among the other layout managers in that it stores
several different _____.
a) unique,classes

b) unique,layout
c) antique,methods
d) special,packages

105) Constructors of CardLayout are:

a) CardLayout( ), CardLayout(int horz, int vert)


b) CardLayout( ),CardLayout(inthorz,intvert), CardLayout(int numRows, int numColumns,
int horz, int vert)
c)Both
d)None

106) The cards are held in an object of type ______


a) Frame
b) Applet

c) Panel
d) Container

107) Methods of CardLayout


void first(Container deck)
void last(Container deck)
void next(Container deck)
void previous(Container deck)
void show(Container deck, String cardName)
a)All
b)only first 2
c)Both
d)None

108) Dialog box maybe ______ or ______


a) Fixed,Variable
b) static,dynamic
c) manual,automated

d) modal,modeless

109) Which of these is true of modal dialog box


a) You cannot access other parts of your program until you have closed the dialog box.
b) Input focus can be directed to another window in your program.
c) Both a and b
d) None

110) Which of these is true of modeless dialog box


a) You cannot access other parts of your program until you have closed the dialog box.
b) Input focus can be directed to another window in your program.
c) Both a and b
d) None

111) Constructors of dialog box


a) Dialog(Frame parentWindow, boolean mode), Dialog(Frame parentWindow, String
title, boolean mode)
b) Dialog(Frame parentWindow, boolean mode) ,Dialog(Frame parentWindow, String title,
boolean mode, int horz, int vert)
c) Dialog(Frame parentWindow, boolean mode), Dialog(Frame parentWindow, String title,
boolean mode,int rows,int column)
d) Dialog(Frame parentWindow, boolean mode) ,Dialog(Frame parentWindow, String title)

112) To create a file dialog box, instantiate an ______ of type FileDialog.


a) Method
b) Class

c) Object
d) Package

113) Constructor of FileDialog


a) FileDialog(Frame parent, String boxName), FileDialog(Frame parent, String boxName,
int how,int horz,int vert), FileDialog(Frame parent)
b) FileDialog(Frame parent, String boxName),
c) FileDialog(Frame parent, String boxName) ,FileDialog(Frame parent, String
boxName, int how) FileDialog(Frame parent)
d)FileDialog(Frame parent, String boxName),FileDialog(Frame parent, String boxName, int
how)

114) For the file to be in reading mode which method is used


a) FileDialog.SAVE
b) FileDialog.WRITE

c) FileDialog.LOAD
d) FileDialog.READ

115) For the file to be in writing mode which method is used

a) FileDialog.SAVE
b) FileDialog.WRITE
c) FileDialog.LOAD
d) FileDialog.READ

116) Select the correct Menubar classes from the following options

a) MenuBar, Menu, MenuItem


b) menubar, menu, menuitem
c) Both
d) None of these

117) Which menu option of types will have a checkmark next to them when they are
selected?

a) CheckboxMenuItem
b) CheckedItem
c) MenuItem
d) None of these

118) You can disable or enable a menu item by using the ____________method.
a) setStatus()

b)setEnabled( )
c) setMenuStatus()
d)None of these

119) Which of these constructor throws HeadlessException?


a) CheckboxMenuItem()
b) CheckboxMenuItem(String itemName)
c) CheckboxMenuItem(String itemName, boolean on)

d) All of these

120) Which sets the command name of the action event that is fired by this menu item?
a) setActionCommand()
b) setMenuCommand()
c) Both
d) None of these

121) To check an item, pass ____ to ________.

a) true, setState()
b) check, setItemStatus()
c) check, setItemState()
d) None of these

122) Constuctors of checkbox are -


a) Checkbox( )
b) Checkbox(String str)
c) Checkbox(String str, boolean on, CheckboxGroup cbGroup)

d) All of the above

123)
import java.awt.*;
import java.applet.*;
import java.util.*;
/*
<applet code="BorderLayoutDemo" width=400 height=200>
</applet>
*/
public class BorderLayoutDemo extends Applet
{
public void init() {
add(new Button("north."),BorderLayout.NORTH);
add(new Button("south"),BorderLayout.SOUTH);
add(new Button("Right"), BorderLayout.EAST);
add(new Button("Left"), BorderLayout.WEST);
String msg = "this is in center";
add(new TextArea(msg), BorderLayout.CENTER);
}
}

a) SetLayout(new BorderLayout());
b) setLayout(new BorderLayout());
c) setLayout(new Borderlayout());
d) setLayout(new borderLayout());

124) What should be written in blank space.

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="CBGroup" width=250 height=200>
</applet>
*/
public class CBGroup extends Applet
{
String msg = "";
Checkbox Win98, winNT;
CheckboxGroup cbg;
public void init()
{
cbg = new CheckboxGroup();
Win98 = new Checkbox("Windows 98/XP", , true);
winNT = new Checkbox("Windows NT/2000", , false);
add(Win98);
add(winNT);

Win98.addItemListener(this);
winNT.addItemListener(this);
}
}

a) Win98
b) winNT
c)cbg
d)this

125) Find error in following code.

import java.awt.*;
import java.awt.event.*;
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

126) What will be the output for following code?


import java.awt.*;
import java.applet.*;
/*
<applet code="GridLayoutDemo11" width=300 height=200>
</applet>
*/
public class GridLayoutDemo11 extends Applet {
static final int n = 4;
public void init() {
setLayout(new GridLayout(n, n));
setFont(new Font("SansSerif", Font.BOLD, 24));
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
int k = i * n + j;
if(k > 0)
add(new Button("" + k));
}
}
}
}
a)

b)

c)

d)
Answer: a)

127) Consider the following program. Find the error.


immport java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code=demo width=100 height=100>
</applet> */

public class demo extends Applet


{
public void init()
{
firstlabel =new Label("Label 1");
secondlabel =new Label("Label 2");
b1=new Button("Enter");
add(l1);
add(l2);
add(b1);

}
}
a) Firstlabel object is not declared
b) Secondlabel object is not declared
c) b1 object is not declared
d) All of above

128) What will be the missing statement in java to get following output:

import java.awt.*;
import java.applet.*;
/*<applet code=fontc width=500 height=500>
</applet>
*/
public class fontc extends Applet
{
public void init()
{
Font f=new Font("Times New Roman",Font.ITALIC,30)
setFont(f);
}
public void paint(Graphics g)
{
g.setColor(Color.red);
g.drawString("SAGAR",10,50);
}
}

A. Missing {
B. Missing }
C. Missing semicolon
D. Missing ()

129) What is the code to get the following output:


a) import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code=sample width=100 height=100>
</applet>
*/
public class sample extends Applet
{
Label l1,l2;
Button b1;
String msg="";
public void init()
{
l1=new Label("Label 1");
l2=new Label("Label 2");
b1=new Button("Enter");
add(l1);
add(l2);
add(b1);
}
}

b) import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code=sample width=100 height=100>
</applet>
*/
public class sample extends Applet
{
Label l1;
Button b1;
String msg="";
public void init()
{
l1=new Label("Label 1");
b1=new Button("Enter");
add(l1);

add(b1);
}
}

c) import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code=sample width=100 height=100>
</applet>
*/
public class sample extends Applet
{
Label l1,l2;
Button b1;
String msg="";
public void init()
{
l1=new Label("Label 1");
l2=new Label("Label 2");

add(l1);
add(l2);
}
}

d) import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code=sample width=100 height=100>
</applet>
*/
public class sample extends Applet
{
Label l1,l2;
Button b1;
String msg="";
public void init()
{
l1=new Label("Label 1");
l2=new Label("Label 2");
b1=new Button("Enter");
add(l1);
add(l2);
add(b1);
}
}

130) What is the output of the following code:

import java.awt.*;
import java.applet.*;
/*
<applet code="GridLayoutDemo" width=300 height=200></applet>
*/
public class GridLayoutDemo extends Applet
{
int n = 4;
public void init()
{
setLayout(new GridLayout(n,n,10,10));

for(int i = 0; i <n; i++)


{
for(int j = 0; j <n; j++)
{
add(new Button("k"));
}
}
}
}
a)

b)
c)none of the above
d)all of these

131) What will be the output of following code

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
class MenuFrame1 extends Frame
{
String msg = "";
MenuBar mbar;
MenuItem copy,paste,selectline,selectword,selectall;
CheckboxMenuItem open,cut;
TextField t1;
Menu file,edit,select,format;
public MenuFrame1()
{
mbar =new MenuBar();
setMenuBar(mbar);
file = new Menu("File");
open = new CheckboxMenuItem("open");
file.add(open);
mbar.add(file);
edit= new Menu("edit");
cut = new CheckboxMenuItem("cut");
copy = new MenuItem("copy");
paste = new MenuItem("paste");
edit.add(cut);
edit.add(copy);
edit.add(paste);
select =new Menu("select");
selectline = new MenuItem("selectline");
selectword = new MenuItem("selectword");
selectall = new MenuItem("selectall");
selectall.setEnabled(false);
select.add(selectline);
select.add(selectword);
select.add(selectall);
edit.add(select);
mbar.add(edit);
format =new Menu("format");
format.setEnabled(false);
mbar.add(format);
addWindowListener(new MyWindowAdapter1());

}
public static void main(String[] args)
{
MenuFrame1 mf =new MenuFrame1();
mf.setTitle("MenuFrame");
mf.setSize(300,200);
mf.setVisible(true);
}

class MyWindowAdapter1 extends WindowAdapter {


public void windowClosing(WindowEvent we) {
System.exit(0);
}
}
}

a)
b)

c)

d)

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

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

134) Which method will cause a Frame to be displayed?

a) show( )

b) setVisible( )

c) display( )

d) displayFrame( )

e) both a and b

135) The Choice component allows multiple selection.

a) True

b) False

136) The List component does not generate any events.

a) True

b) False
137) Which of the following components allow multiple selections?

a) Non-exclusive Checkboxes

b) Radio buttons

c) Choice

d) List

e) Both a and d

138) Which containers use a BorderLayout as their default layout?

a) Window

b) Frame

c) Dialog

d) All of above

139) Which containers use a FlowLayout as their default layout?

a) Panel

b) Applet

c) both a and b

d) only d

140) Which method returns the preferred size of a component?

a) getPreferredSize( )

b) getPreferred( )

c) getRequiredSize( )
d) getLayout( )

141) Which layout should you use to organize the components of a container in a tabular
form?

a) CardLayout

b) BorederLayout

c) FlowLayout

d) GridLayout

142) What is the default layouts for a applet, a frame and a panel?

a)Flow layout, Border layout, Flow layout

b)Flow layout, Flow layout, Border layout

c)Border layout, Flow layout, Flow layout

d)Border layout,Border layout, Flow layout

143) An Applet has its Layout Manager set to the default of FlowLayout. What code would be
the correct to change to another Layout Manager?

a)setLayoutManager(new GridLayout());

b)setLayout(new GridLayout(2,2));

c)setGridLayout(2,2,))

d)setBorderLayout();

144) Which is a dual state menu item?

a) CheckboxMenuItem
b)Menu

c)MenuItem

d) All of above

145) Which method can be used to enable/diable a checkbox menu item?

a)setState(boolean)

b) setstate(boolean)

c)setEnabled(boolean)

d)setenabled(boolean)

146) Which of the following may a menu contain?

a)A separator

b)A check box

c)A menu

d)A button

e)both a and c

Answer Key
Unit : 03
Event Handling
1) Which of these packages contains all the classes and methods required for even handling in Java?
a) java.applet
b) java.awt
c) java.event
d) java.awt.event

2) 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.

3) Which of these methods are used to register a keyboard event listener?

a) KeyListener()
b) addKistener()
c) addKeyListener()
d) eventKeyboardListener()

4) Which of these methods are used to register a mouse motion listener?


a) addMouse()
b) addMouseListener()
c) addMouseMotionListner()
d) eventMouseMotionListener()

5) Event class is defined in which of these libraries?


a) java.io
b) java.lang
c) java.net
d) java.util

6) Which of these methods can be used to determine the type of event?


a) getID()
b) getSource()
c) getEvent()
d) getEventObject()

7) Which of these class is super class of all the events?


a) EventClass
b) EventObject
c) ActionEvent
d) ItemEvent

8) Which of these events will be notified if scroll bar is manipulated?


a) ActionEvent
b) ComponentEvent
c) AdjustmentEvent
d) WindowEvent

9) Which of these events will be generated if we close an applet’s window?


a) ActionEvent
b) ComponentEvent
c) AdjustmentEvent
d) WindowEvent

10) The Following steps are required to perform


1) Implement the Listener interface and overrides its methods
2) Register the component with the Listener

a) Exception Handling
b) String Handling
c) Event Handling
d) None of the above

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

12) Which class header would be used to create an applet that accepts a click on a button?

a)public class MyApplet extends Japplet implements Listener


b)public class MyApplet extends Japplet implements ActionListener
c)public class MyAppletextends Japplet implements ActionEvent
d)public class MyApplet extends Japplet implements Event

13) Select correct Listener from given option for ******.


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

public class JR extends JApplet implements ***********


{
Container c=getContentPane();
public void init()
{
c.setLayout(new FlowLayout());
JRadioButton b1=new JRadioButton("red");
b1.addActionListener(this);
c.add(b1);

JRadioButton b2=new JRadioButton("blue");


b2.addActionListener(this);
c.add(b2);

JRadioButton b3=new JRadioButton("green");


b3.addActionListener(this);
c.add(b3);

ButtonGroup bg=new ButtonGroup();


bg.add(b1);
bg.add(b2);
bg.add(b3);
}
public void actionPerformed(ActionEvent e)
{
String str;
str=e.getActionCommand();
if(str=="red")
c.setBackground(Color.red);
else if(str=="blue")
c.setBackground(Color.blue);
else if(str=="green")
c.setBackground(Color.green);
}
}

/*<applet code=JR width=200 height=200></applet>*/

a) ItemListener
b) ActionListener
c) MouseListener
d) WindowListener

14) Which of these methods will respond when you click any button by mouse?

a) mouseClicked()
b) mouseEntered()
c) mousePressed()
d) All of the mentioned

15) Which is the integer constants of TextEvent class?


a) TEXT_CHANGED
b) TEXT_FORMAT_CHANGED
c) TEXT_VALUE_CHANGED
d) TEXT_SIZE_CHANGED

16) MouseEvent is subclass of which of these classes?


a) ComponentEvent
b) ContainerEvent
c) ItemEvent
d) InputEvent
17) An event is generated when the internal state of the event source is_____
a) Not changed
b) Changed
c) Either changed or not
d) None of these.

18) 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) Missing {
c) Missing }
d) Missing ()

19) Which of the following are correct event handling methods?

a) mousePressed(MouseEvent e){ }
b) MousePressed(MouseClick e){}
c) functionKey(KeyPress k){}
d) Added(ContainerEvent e){}
20) Which methods are used to close the window?
a) setVisible(false)
b) windowClosing()
c) stop()
d) Both a and b

21) To process scroll bar events, you need to implement ________________ interface.
a) adjustmentlistener
b) MouseListener
c)AdjustmentListener
d) KeyListener

22) KeyEvent is subclass of which of these classes?


a) ComponentEvent
b) ContainerEvent
c) ItemEvent
d) InputEvent

23) _________ and _____________is a subclass of InputEvent.


a) MouseEvent, KeyEvent
b)WindowEvent,ItemEvent
c)MouseMotionEvent,MouseWheelEvent
d)ActionEvent,AdjustmentEvent

24) ______________ method returns a value that indicates which modifier key were pressed when the
action event is generated.
a) getModifiers()
b) setModifiers()
c) getActionCommand()
d)none of these

25) Complete the following signature:


void addTreeExpansionListener(___________________________ tel)
a) Treeexpansion listener
b) TreeExpansionListener
c) TreeListener
d) treelistener

26) Constants for AdjustmentEvent class are:


a) BLOCK_INCREMENT
b) TRACK
c) UNIT_DEVREMENT
d) all of these
27) Which of these events will be generated if we close an applet’s window?
a)ActionEvent
b)ComponentEvent
c)AdjustmentEvent
d) WindowEvent

28) Which of the following is the highest class in the event delegation model?
a)java.util.EventListener
b) java.util.EventObject
c) java.awt.AWTEvent
d) java.awt.event.AWTEvent

29) ______ is an object that describes a state change in the source.


a) event
b) Source
c) none of the above
d) all the above

30) Which of these methods can be used to change location of an event?


a)changePoint()
b)translatePoint()
c) ChangeCordinates()
d) translateCordinates()

31) Which of these methods can be used to obtain the coordinates of a mouse?
a)getPoint()
b)getCoordinates()
c)getMouseXY()
d)getMouseCordinates()

32) Which of the following method is invoked when a window is changed from a normal to a minimized
state?
a) windowIconified()
b) windowClosed()
c)windowDeactivated
d) windowOpened()

33) Which of these is a superclass of all Adapter classes?


a)Panel
b) Applet
c) Component
d) Event

34) Which of the following method does not belongs to WindowListerner interface?
a) windowActivated
b) windowReactivated
c) windowDeiconified
d) windowClosed()

35) Which event is generating when checkable menu item is selected or deselected?
a) KeyEvent
b) ListEvent
c) ItemEvent
d) MouseEvent

36) Which are two ways to create Java Anonymous inner class?
a) Class, Interface
b) Applet
c) Panel, Frame
d)Event

37) The ___________method returns a reference to the component that was added to or removed from the
container.
a)getParent()
b)getComponent( )
c)getChild( )
d)geoReferenced()

38) Inner class can access all the members of outer class including_____data members and methods.
a) public
b)Protected
c)friend
d)private

39) In case of______ we can implement only required methods of any interface.
a)adapter classes
b)Event
c)EventObject
d)Listener

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

41) Which of the following are true?


a)The event-inheritance model has replaced the event-delegation model.
b) The event-inheritance model is more efficient than the event-delegation model.
c) The event-delegation model uses event listeners to define the methods of event-handling
classes.
d) The event-delegation model uses the handleEvent( ) method to support event handling.

42) Which of the following components generate action events?


a)Buttons
b)Labels
c)Check boxes
d) Windows
43) What is the preferred way to handle an object’s events in Java 2?
a) Override the object’s handleEvent( ) method.
b) Add one or more event listeners to handle the events.
c) Have the object override its processEvent( ) methods.
d) Have the object override its dispatchEvent( ) methods.

44) If a class MyWindowAdapter extends WindowAdapter and implements the windowClosing() method.
How to register this class ?
a) this.addWindowListener(new MyWindowAdapter());
b) addWindowListener(new MyWindowAdapter());
c) this.addListener(new MyWindowAdapter());
d) addWindowListener(new MyAdapter());

45) In the following code, what is the name of the inner class?

public class Periodical


{
long ISBN;
public class Book
{
public long getISBN()
{
retrun ISBN;
}
}
}
a) Periodical
b) book
c) Book
d) ISBN

46) What is the output of following code?

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="AdapterDemo" width=300 height=100> </applet>
*/
public class AdapterDemo extends Applet
{
public void init()
{
addMouseListener(new MyMouseAdapter(this));
}
}
class MyMouseAdapter extends MouseAdapter
{
AdapterDemo adapterDemo;
public MyMouseAdapter(AdapterDemo adapterDemo)
{
this.adapterDemo = adapterDemo;
} // Handle mouse clicked.

public void mouseClicked(MouseEvent me)


{
adapterDemo.showStatus("Mouse clicked");
}
}

a) Mouse pressed
b) Mouse clicked
c) Mouse dragged
d) Mouse released

47) Consider following code segment-

public void mousePressed(MouseEvent event)


{
System.out.println(event.getPoint());
}

Following code segement output is-


a) event generated
b) Print x co-ordinates
c) Display y co-ordinates
d) Print value of x and y co-ordinates

48) A general form, event registration method-


a) void addTypeListener (TypeListener el)
b) public void addTypeListener (TypeListener el)
c) public TypeListener (TypeListener el)
d) public void addTypeListener (el)

49) Identify correct methods in the place of blank space:

public class Test extends Applet implements _______________


{
String msg="";
public void init()
{
addKeyListener(this);
}
public void keyPressed(_____________ k)
{
showStatus("KeyPressed");
}
public void keyReleased(KeyEvent k)
{
showStatus("KeyRealesed");
}
public void keyTyped(KeyEvent k)
{
msg = msg+k.getKeyChar();
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg, 20, 40);
}
}

a)KeyListener, KeyEvent
b)MouseListener, MouseEvent
c)ActionListener, ActionEvent
d)WindowListener, WindowEvent

50) In the Delegation Event Model, a user interface element is able to delegate, the processing of an
event............................
a) class
b) a separate piece of code
c) interface
d) listener

51) Listeners are created by implementing one or more of the defined by the…………….
a) interfaces
b)class
c)listener
d)handler

52) The isPopupTrigger( ) methods returns-


a)string
b)integer
c) Boolean
d)long

53) The example of user interface elements that implement the ItemSelectable
interface-
a) checkbox and checkboxgroup
b) textfield and textarea
c) radiobutton and button
d) Lists and choices

54) public void removeTypeListener(TypeListener el)


Here Type means-
a) name of the event
b) type of listener
c) name of class
d) name of object

55) The getActionCommand( ) method returns-


a)string
b)integer
c) Boolean
d)long
56) The getItem( ) method can be used...........
a) name of the method
b) type of listener
c) name of class
d) to obtain a reference to the item that changed

57) The translatePoint( ) method-


a) display x and y coordinates
b) changes the location of the event
c) name of class
d) to obtain a reference to the item that changed

58) The WindowEvent class, WINDOW_DEACTIVATED, integer constants meaning-


a) This window has lost the focus.
b) Restoring the window to its original size.
c) Reducing the window from to minimized.
d) Reducing the window from to maximized.

59) The WindowEvent class, WINDOW_ICONIFIED, integer constants meaning-


a) This window has lost the focus.
b) Restoring the window to its original size.
c) Reducing the window from to minimized.
d) Reducing the window from to maximized.

60) The WindowEvent class, WINDOW_DEICONIFIED, integer constants meaning-


a) This window has lost the focus.
b) Restoring the window to its original size.
c) Reducing the window from to minimized.
d) Reducing the window from to maximized.

61) Which are the not types of key events-


a) KEY_DOUBLE
b) KEY_PRESSED
c) KEY_RELEASED
d) KEY_TYPED

62) MOUSE_WHEEL integer constants is belong to ___________- event.


a) MouseMotionEvent
b) MouseWheelEvent
c)MouseEvent
d)all of these

63) MouseWheelEvent is a subclass of_________________.


a) KeyEvent
b) MouseMotionEvent
c) MouseEvent
d) MouseWheelEvent

64) WindowEvent is a subclass of________________.


a) ComponentEvent
b) ContainerEvent
c) ActionEvent
d) AdjustmentEvent
65) Which one is not a method belong to ComponentListener Interface?
a) void componentResized(ComponentEvent ce)
b) void componentMoved(ComponentEvent ce)
c) void componentOpened(ComponentEvent ce)
d) void componentHidden(ComponentEvent ce)

66) ComponentAdded( ) and componentRemoved( ) are the methods of …………..


a)ComponentListener
b) MouseMotionEvent
c) ContainerListener
d) MouseWheelListener

67) When a component loses ___________focus, focusLost( ) is called.


a) keyboard
b)mouse
c)window
d) panel

68) Which method not use to obtain the coordinates of the mouse-
a) string getcode()
b) int GetKEY()
c) int getKeyCode( )
d) int getCode()

69) Which method used to capture ALT, CTRL, META OR SHIFT keys-
a) getModifiers( )
b) getMod( )
c) modifiers ( )
d) getAlt( )

70) Which top-level class provides methods to add and remove keyboard and mouse event
listeners-
a) Container
b) Applet
c) Window
d) Component

71) Write the correct code at blank space:

public class ………………. extends Frame implements WindowListener


{
WindowExample()
{
addWindowListener(this);
setSize(400,400);
setLayout(null);
setVisible(true);
}
public static void main(String[] args)
{
new WindowExample();
}

a) Frame
b) Window
c) WindowExample
d)Example

72) Assuming we have a class which implements the ActionListener interface, which method
should be used to register this with a Button?
a) EnterActionListener(*);
b) addListener(*);
c) ActionListener(*);
d)addActionListener(*);

73) Which of these interfaces define a method actionPerformed()?


a) KeyListener
b) ButtonListener
c) InputListener
d) ActionListener

74) keyPressed() is method of …………………… interface.


a) KeyListener
b) ButtonListener
c) InputListener
d) ActionListener

75) keyReleased() is mehod of ………….. interface.


a) ActionListener
b) ButtonListener
c) InputListener
d) KeyListener

76) keyTyped() is method of………………..interface.


a) ActionListener
b) ButtonListener
c) InputListener
d) KeyListener

77) mouseClicked() is method of…………………interface.


a) MouseListener
b) ButtonListener
c) InputListener
d) KeyListener

78) mouseEntered() is method of…………………interface.


a) InputListener
b) ButtonListener
c) MouseListener
d) KeyListener

79) mouseExited() is method of…………………interface.


a) MouseListener
b) ButtonListener
c)InputListener
d) KeyListener

80) mousePressed() is method of…………………interface.


a) InputListener
b) ButtonListener
c) MouseListener
d) KeyListener

81) Identify correct general form of MouseClicked( ) method of Mouse Listener interface.
a) void mouseClicked(me)
b) void Clicked(MouseEvent me)
c) void mouseClicked(MouseEvent me)
d) void mouseClick(MouseEvent me)

82) Select the method of MouseMotionListener Interface.


a) void mouseClicked(MouseEvent me)
b) void mouseEntered(MouseEvent me)
c)void mouseExited(MouseEvent me)
d) void mouseMoved(MouseEvent me)

83) Select the method of MouseWheelListener Interface.


a) void mouseClicked(MouseWheelEvent me)
b) void mouseEntered(MouseWheelEvent t me)
c) void mouseWheelMoved(MouseWheelEvent mwe)
d) void mouseExited(MouseWheelEvent me)

84) Which of these are methods of TextListener Interface?


a) textValueChanged()
b) setText()
c) textChanged()
d) getText()

85) Which of these method are used to register a keyboard event Listener ?
a) addMouseListener()
b) addKeyListener()
c) KeyListener()
d) addKey()

86) Which of these methods are used to register a mouse motion listener?
a) addMouseMotionListner()
b) addMouseListner()
c) addMouseWheelListner()
d) MouseMotionListner()

87) Which of these methods are used to register a Window listener?


a) addMouseMotionListner()
b) ComponentListner()
c) WindowListener()
d) addWindowListener()

88) Which source generates adjustment events?


a) Scroll bar
b) Checkbox
c) Radio Button
d)List

89) WindowActivated() is method of……………. interface.


a) WindowListener
b) KeyListener
c) AdjustmentListener
d)ContainerListener

90) windowClosed() is method of……………. interface.


a) KeyListener
b) WindowListener
c) AdjustmentListener
d)ContainerListener

91) windowDeactivated() is method of……………. interface.


a) WindowListener
b) KeyListener
c) AdjustmentListener
d)ContainerListener

92) windowDeiconified() () is method of……………. interface.


a) WindowListener
b) KeyListener
c)AdjustmentListener
d)ContainerListener

93) windowGainedFocus() and windowLostFocus() methods are belongs to …………………interface .


a) WindowListener
b) KeyListener
c)AdjustmentListener
d) WindowFocusListener

94) windowClosed() is method of……………. interface.


a) KeyListener
b) WindowListener
c)AdjustmentListener
d)ContainerListener

95) Identify the class which is not an adapter class?


a)FocusAdapter
b)KeyAdapter
c)WindowAdapter
d)ItemAdapter

96) Following are the integer constants which does not belong to ComponentEvent class .
a) COMPONENT_HIDDEN
b) COMPONENT_MOVED
c) COMPONENT_RESIZED
d) COMPONENT_ICONIFIED

97) Identify correct adapter in following code:

import java.applet.*;
import java.awt.event.*;
/*
<applet code="AnonymousInnerClassDemo" width=200 height=100>
</applet>
*/
public class AnonymousInnerClassDemo extends Applet
{
public void init()
{
addMouseListener(new ______________()
{
public void mousePressed(MouseEvent me)
{
showStatus("Mouse Pressed");
}
});
}
}

a) MouseAdapter
b) MouseMotion Adapter
c) KeyAdapter
d)mousepressed

98) An adapter class provides an ……………..implementation of all methods in an event listener interface.
a) interface
b) abstract
c) empty
d)runnable

99) Identify correct name of event:

public void adjustmentValueChanged(……………………. e)


{
Integer i =e.getValue();
frameLabel1.setText(i.toString());
}

a) ScroolbarEvent
b) AdjustmentEvent
c) ActionEvent
d)TextAreaEvent
100) Identify correct name of event:

public void mouseExited (________________ me)


{
// save coordinates
mouseX = 0;
mouseY = 10;
msg = "Mouse exited.";
repaint();
}

a) InputEvent
b) MouseMotionEvent
c) KeyEvent
d) MouseEvent

101) Fill correct listener names:

public class MouseEvents extends Applet


implements MouseListener, MouseMotionListener
{
String msg = "";
int mouseX = 0, mouseY = 0; // coordinates of mouse
public void init()
{
_______________ (this);
_______________ (this);
}

}
a) addListener, addMouseListener
b) addMouseMotionListener, addKeyListener
c) MouseListener , MotionListener
d) addMouseListener, addMouseMotionListener

102) Listeners are created by implementing one or more of the interfaces defined by the___________
package.
a) java.awt.event
b) java.util.event
c) java.lang.event
d)java.awt.listener

103) Identify the name of method which is not belong to WindowEvent.


a) int getOldState( )
b) int getNewState( )
c) Window OppositeWindow( )
d) Window getWindow( )

104) In List event source, generates _______events when an item is double-clicked.


a) action
b) item
c)text
d)window

105) In List event source, generates ___________ events when an item is selected or deselected.
a) action
b) item
c)text
d)window

106) In Menu Item, generates ____________ events when a menu item is selected.
a) action
b) item
c) text
d)window

107) In Menu Item, generates ________ events when a checkable menu item is selected or
deselected.
a) action
b) item
c) text
d) window

108) Identify the correct class name:


import java.awt.*;
import java.awt.event.*;
public class ________________ extends KeyAdapter
{
Label l;
TextArea area;
Frame f;
KeyAdapterExample()
{
f=new Frame("Key Adapter");
l=new Label();
l.setBounds(20,50,200,20);
area=new TextArea();
area.setBounds(20,80,300, 300);
area.addKeyListener(this);

f.add(l);
f.add(area);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
public void keyReleased(KeyEvent e) {
String text=area.getText();
String words[]=text.split("\\s");
l.setText("Words: "+words.length+" Characters:"+text.length());
}

public static void main(String[] args)


{
new KeyAdapterExample();
} }

a) KeyAdapterExample
b) KeyAdapter
c) KeyExample
d) AdapterExample

109) Identify the correct class name:

import java.awt.*;
import java.awt.event.*;
public class MouseAdapterExample extends MouseAdapter
{
Frame f;
MouseAdapterExample()
{
f=new Frame("Mouse Adapter");
f.addMouseListener(this);
f.setSize(300,300);
f.setLayout(null);
f.setVisible(true);
}
public void mouseClicked(MouseEvent e) {
Graphics g=f.getGraphics();
g.setColor(Color.BLUE);
g.fillOval(e.getX(),e.getY(),30,30);
}
public static void main(String[] args) {
new _______________();
}
}

a) mousePressed
b) MouseAdapterExample
c) mouseClicked
d) MouseAdapter

110) Which of these are integer constants defined in ActionEvent class?


a) ALT_MASK
b) CTRL_MASK
c) SHIFT_MASK
d) All of the mentioned

111) When the size of component is changed, ____________ event is generated.


a) ComponentEvent
b) ContainerEvent
c) FocusEvent
d) InputEvent
112) When the component is added or removed ? Which of these events is generated ?
a) ComponentEvent
b) ContainerEvent
c) FocusEvent
d) InputEvent

113) FocusEvent is subclass of which of these classes?


a) ComponentEvent
b) ContainerEvent
c) FocusEvent
d) InputEvent

114) Match the correct pairs-


a. getSource( ) i. Determine the type of the event
b. toString ( ) ii. Returns the source of the event
c. getID( ) iii- Constructor
d. EventObject(Object src) iv- returns the string equivalent of the event.

a) a-ii b-iv c-i d-iii


b) a-i b-iv c-ii d-iii
c) a-iii b-iv c-i d-ii
d) a-iv b-ii c-i d-iii

115) Match the correct pairs-


a. getKeyLocation() i. Set the keyCode value to indicate a physical key.
b. getKeyCode() ii. Returns the character associated with the key in this event.
c. getKeyChar() iii. Returns the location of the key that originated this key event.
d. setKeyCode(int keyCode) iv. Returns the integer keyCode associated with the key in this
event.

a) a-iii b-iv c-ii d-i


b) a-i b-iv c-ii d-iii
c) a-ii b-iv c-iii d-i
d) a-iv b-iii c-ii d-I

116) Consider following three statement


1) ActionListener Interace defines one method to receive action event
2) ItemListener Interface defines one method to recognize when the state of item change..
3) MouseListener interface defines mouseMoved() method

a) Statement 1 and 2 are true


b) Statement 1 and 3 are true
c) Statement 2 and 3 are true
d) All are true

117) Which of the following are true?


A) The MouseListener interface defines methods for handling mouse clicks.
B) The MouseMotionListener interface defines methods for handling mouse clicks.
C) The MouseClickListener interface defines methods for handling mouse clicks.
D) The ActionListener interface defines methods for handling the clicking of a button.
a) Statement A and D true
b) Statement A and C true
c) Statement B and D true
d) Statement C and D true

118) Which of the following statements are false


1)windowlistener define seven method
2)mouseMotionListerne define 2 method
3) ActionListener Interace defines three method to receive action event
4)KeyListener Interface define Three method

a) Statement 2 is False
b) Statement 3 is False
c) Statement 1 is False
d) Statement 1 and 4 are False

119) Consider the following code

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

a) output :Mouse Pressed


b) Error in code
c) Syntax error
d) Error in package

120) Fill in the blanks.

import java.applet.*;
import java.awt.event.*;
/*
<applet code="InnerClassDemo" width=200 height=100>
</applet>
*/
public class InnerClassDemo extends Applet {
public void init() {
__________ (new MyMouseAdapter());
}
class MyMouseAdapter extends _________________
{
public void mousePressed(MouseEvent me) {
showStatus("Mouse Pressed");
}
}
}

a) addMouseListener, MouseAdapter
b) addmouselistener, MouseAdapter
c) addMouseListener, mouseAdapter
d) addMouseListener, mouseadapter

121) Fill the proper name of class.

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*<applet code="AdapterDemo" width=300 height=100>
</applet>
*/
public class AdapterDemo extends Applet
{
public void init()
{
addMouseListener(new MyMouseAdapter(this));
}
}
class MyMouseAdapter extends MouseAdapter
{
_________________ adapterDemo;
public MyMouseAdapter(AdapterDemo adapterDemo)
{
this.adapterDemo = adapterDemo;
}
// Handle mouse clicked.
public void mouseClicked(MouseEvent me)
{
adapterDemo.showStatus("Mouse clicked");
}
}

a) AdapterDemo
b) adapterDemo
c) adapterdemo
d) Adapterdemo

122) The following code segment shows that a class MyWindowAdapter extends WindowAdapter and
implements the windowClosing() method.
Identify the correct adapter name and event name.

class MyWindowAdapter extends ________________


{
public void windowClosing(_____________ e)
{
System.exit(0);
}
}

a) WindowAdapter, WindowEvent
b) MyWindowAdapter, WindowEvent
c) WindowAdapter, windowEvent
d) WindowEvent, WindowAdapter

123) Identify the correct adapter name and event name.

public class MyFocusListener extends _______________


{
public void focusGained(_________________ fe)
{
Button button = (Button) fe.getSource();
label.setText(button.getLabel());
}
}

a) FocusAdapter, FocusEvent
b) focusAdapter, FocusEvent
c) focusadapter, FocusEvent
d) FocusAdapter, Focusevent

124) Identify the class which is not adapter class?


a)KeyAdapter
b)FocusAdapter
c)ItemAdapter
d)MouseMotionAdapter

125) Identify the correct event class


public void componentRemoved(____________________e)
{
displayMessage(" removed from ", e);
}

a) ContainerEvent
b) ComponentEvent
c) FocusEvent
d) WindowEvent

126) Find error in given program

import java.awt.*;
import java.awt.event.*;
public class KeyListenerExample extends Frame implements KeyListener { Label MyLAbel;
TextArea area;
KeyListenerExample()
{
MyLabel=new Label();
MyLabel.setBounds(20,50,100,20);
area=new TextArea();
area.setBounds(20,80,300, 300);
area.addKeyListener(this);
add(MyLabel);add(area);
setSize(400,400);
setLayout(null);
setVisible(true);

}
public void keyPressed(KeyEvent e)
{
MyLabel.setText("Key Pressed");
}
public void keyReleased(KeyEvent e)
{
MyLabel.setText("Key Released");
}
public static void main(String[] args)
{
new KeyListenerExample();
}
}

a) All methods of Interface are not implemented


b) Package is wrong
c) Code is correct
d) Compile time error

127) What is the output of the following java program?

class Outer
{
void outerMethod() {
System.out.println("inside outerMethod");
// Inner class is local to outerMethod()
class Inner
{
void innerMethod() {
System.out.println("inside innerMethod");
}
}
Inner y = new Inner();
y.innerMethod();
}
}
class MethodDemo
{
public static void main(String[] args) {
Outer x = new Outer();
x.outerMethod();
}
}

a)
inside outerMethod
inside innerMethod
b)
inside innerMethod
inside outerMethod
c)No output
d)inside innerMethod

128) Identify the incorrect Integer constants for WindowEvent.


a)WINDOW_ACTIVATED
b)WINDOW_DEACTIVATED
c)WINDOW_LOST_FOCUS
d)WINDOW_GOT_FOCUS

129) Which source generates adjustment events?


a) Scroll bar
b) MenuItem
c) Button
d) List
130) Which of these are methods of TextListener Interface?
a) textValuechanged()
b) textvalueChanged()
c) TextValueChanged()
d) textValueChanged()

131) Generates ______________________ when the user enters a character.


a) TextEvent
b) KeyEvent
c) MouseEvent
d) ComponentEvent

132) Identify the class which is not an adapter class?


a) MouseAdapter
b) ItemAdapter
c) WindowAdapter
d) KeyAdapter

133) Can outer Java classes access inner class private members?
a) Yes
b) No
134) An _______________ class listener interface and Event class Listener interface has
same name.
a) Main class
b) Adapter Class
c) Event Class
d) Inner Class

135) An adapter class provides an __________ implementation of all methods in an event listener
interface.
a) Complete
b) Multiple
c) Empty
d) None of above

136) Adapter classes are an _________ class for receiving various events.
a) Abstract class
b) Super class
c) Derived class
d) Base class

137) Which is the abstract adapter class for receiving keyboard focus events.
a) ComponentAdapter
b) KeyAdapter
c) FocusAdapter
d) MouseAdapter

138) An adapter class provides an empty implementation of all methods in an __________


a) event listener interface
b) KeyListenerInterface
c) MouseListenerInterface
d) None of above

139) How many method define in FocusListener interface.


a) 3
b) 5
c) 4
d) 2

140) How many method define in ContainerListener interface.


a) 2
b) 1
c) 4
d) 3

141) Fill in the blank: MouseListener interface define…........methods


a) 1
b) 5
c) 4
d) 7

142) Fill in the blank: MouseMotionListener interface define…........methods


a) 3
b) 4
c) 1
d) 2

143) WindowEvent is a subclass of


a) ComponentEvent
b) ContainerEvent
c) KeyEvent
d) InputEvent

144) Which method used to capture ALT, CTRL, META OR SHIFT keys-
a) getModifiers( )
b) getmodifiers( )
c) GetModifiers( )
d) Getmodifiers( )

145) Suppose that you want to have an object eh handle the TextEvent of a TextArea object t. How should
you add eh as the event handler for t?
a) t.addTextListener(eh);
b) eh.addTextListener(t);
c) addTextListener(eh.t);
d) addTextListener(t,eh);
Unit : 05
Interacting with database

1) The following classes belong to which package: Connection management, Database


Access, Data Types, Database Metadata, Exceptions Warnings:
a) javax.sql
b) java.sql
c) javax.swing
d) None of the above

2) Which of the following classes/interface allows you to establish a connection to database:


a) java.sql.Driver
b) java.sql.DriverManager
c) java.sql.connection
d) All of the above

3) Which of the following classes/interface allows you to send SQL statement to database for
execution and read the result:
a) java.sql.Statement
b) java.sql.PreparedStatement
c) java.sql.ResultSet
d) All of the above

4) What is the description of java.sql.DriverManager?


a) This class provides the functionality necessary for managing one or more
database drivers.
b) This is an interface that abstracts the vendor specific connection protoco
c) This class is used to discover properties required to obtain the connection
d) This interface abstracts most of the interaction with the database.

5) What is the description of java.sql.Driver?

a)This class provides the functionality necessary for managing one or more database
drivers.
b)This is an interface that abstracts the vendor specific connection protocol
c)This class is used to discover properties required to obtain the connection
d)This interface abstracts most of the interaction with the database

6) What is the description of java.sql.DriverPropertyInfo?


a) This class provides the functionality necessary for managing one or more database
drivers.
b) This is an interface that abstracts the vendor specific connection protocol
c) This class is used to discover properties required to obtain the connection
d)This interface abstracts most of the interaction with the database.

7) What is the description of java.sql.Connection?


a) This class provides the functionality necessary for managing one or more database
drivers.
b) This is an interface that abstracts the vendor specific connection protocol
c) This class is used to discover properties required to obtain the connection
d) This interface abstracts most of the interaction with the database.

8) Which interface lets you execute SQL statements over the underlying connection and
access the results?
a) java.sql.Statement
b) java.sql.PreparedStatement
c) java.sql.ResultSet
d)java.sql.CallableStatement

9) This interface lets you execute stored procedures.


a) java.sql.Statement
b) java.sql.PreparedStatement
c) java.sql.ResultSet
d) java.sql.CallableStatement

10) The java.sql package provides several Java _______ class that correspond to some of the
SQL types.
a)Connection Management
b)Database Access
c)Data Types
d)Both (a) and (b)

11) Which interface is included in Data Types


a) java.sql.Types
b) java.sql.Date
c) java.sql.Blob
d) All of the above

12) Which interface comes under DatabaseMetadata?


a) java.sql.DatabaseMetadata
b) java.sql.ResultSetMetaData
c) Java.sql.ParameterMetadata
d) All of the above

13) Which of the following comes under SQL Exception and Warnings?
a) java.sql.SQLexception
b) java.sql.SQLWarning
c) java.sql.DataTruncation
d) Both (b) and (c)

14) Which of the following is/are charecteristics of JDBC


(1) Supports a wide level of portability.
(2) Provides Java Interfaces that are compatible with Java Applications . These providers
are also responsible for providing the driver services.
(3) Provides higher level APIs for application programmers. The JDBC API
specification is used as an interface for the applications and DBMS.
(4)The JDBC call to a Java application is made by the SQL Statements. These statements
are resposible for entire communication with the database.

a)All of the above


b) None of the above
c) Only 2,3 and 4
d) Only 1,2 and 3

15) Following is/are the packages for JDBC


a) java.sql
b) javax.sql

c) Both a and b
d) None of the above

16) Which of the following is not a function of JDBC


a) Allows Java programs to execute SQL Statements
b) Allows Java programs to retrive the results of the SQL Statements

c) Allows Java programs to manipulate the design of the application


d) Allows Java programs to send user defined requests to the database
17) JDBC-ODBC Bridge can be availed by importing __________ package.
a) java.sql

b) sun.jdbc.odbc
c) java.jdbcodbc
d) None of the above

18) Which of the following is JDBC version was released with Java EE 6
a) JDBC 2.0
b) JDBC 3.0
c) JDBC 4.0

d) JDBC 4.1

19) JDBC API provides __________ and ___________ to handle database specific call from
users.
a) methods, functions
b) classes, interfaces
c) packages, classes
d) interfaces, packages

20) _____________ has an important role in JDBC Architechtrue


a) Driver
b) SqlData

c) DriverManager
d) ResultSet
21) _____________ refers to the bridge driver (JDBC-ODBC Bridge)

a. Type-1 Driver
b. Type-2 Driver
c. Type-3 Driver
d. Type-4 Driver

22) _____________ refers to a partly java and partly native code driver
a. Type-1 Driver
b. Type-2 Driver

c. Type-3 Driver
d. Type-4 Driver

23) _____________ refers to pure Java Driver that uses a middleware driver to connect to a
database
a. Type-1 Driver
b. Type-2 Driver

c. Type-3 Driver
d. Type-4 Driver

24) _____________ refers to pure Java Driver which is directly connected to a database
a. Type-1 Driver
b. Type-2 Driver
c. Type-3 Driver

d. Type-4 Driver

25) OCI stands for _____________


a. Order Command Interface

b. Oracle Call Interface


c. Operation Command Interface
d. Open Command Interface

26) Which of the following is not the component of 3-tier architecture of JDBC

a. DataSource Object
b. Java Application
c. Java API
d. Database

27) The javax.sql provides ................................ implementations which are used in building
server-side applications.
a. JNDI-based lookup to access databases via logical names
b. Connection Pooling
c. Distributed transaction
d. The RowSet

e. all of the above

28) The javax.sql package is used to develop the client/server sided applications and provide
server sided extension facilities. State the statement is true or false.

a. True
b. False

29) Using which classes and interfaces of javax.sql package we can establish and manage
connection with the data source?
a. Only DataSource
b. DataSource and DataManager

c. DataSource and DriverManager


d. Only DriverManager
30) The ............... package provides a transparent meaning of connection pooling.
a. javax.swing
b. javax.servlet

c. javax.sql
d. java.io.sql

31) ............................. implementation are provided by the driver vendor.

a. DataSource
b. DataManager
c. DriverManager.
d. None

32) The ............................. Naming service is used to provide a logical name for the
DataSource to make a connection.
a. Java Database Connectivity (JDBC)

b. Java Naming anfd Directory Interface (JNDI)


c. Open Database Connectivity (ODBC)
d. Domain Name Server

33) DataSource object can be impeemnted to work with..............


a. three tier infrastructure
b. two tier infrastructure

c. middle tier infrastructure


d. none

34) State true or false


“ Connection Pooling means that the connection is reused rather than created each
time when it is requested.”

a True
b. false

35) ............................... Sub class of statement interface.


a. Statement Interface

b. PreparedStatement Interface
c. CallableStatement Interface
d. PreparedStatement Class

36) Which method is invoked on the statement object by p-assing the SQL statements as
parameter.
a. getXXX()
b. setXXX()

c. executeXXX()
d. All of the Above

37) ......................... can be used to represent a precompiled query , which can be executed
multiple times.
a. Statement Interface

b. PreparedStatement Interface
c. CallableStatement Interface
d. PreparedStatement Class

38) The excute method ....................... while using the PreparedStatement objects.
a. takes nth number of parameters.
b. takes only one parameters.

c. do no takes any parametrs.


d. none of the above.
39) Which method is of the connection object is used to get the object of the
PreparedStatement interface?
a. executeStatement()
b. updateStatement()

c. preparedStatement()
d. getStatement()

40) Which method is of the PreparedStatement object are used to set the parametrs of the
SQL statements.
a. getXXX()
b. setParameter()
c.setPath()

d. setXXX()

41) We can execute the precompiled SQL statements by using


a. execute()
b. executeUpdate()
c. executeQuery()

d. all of the above

42) javax.sql package is also called as ______.


a.JDBC extension API
b. API
c.JDBC extension
d. none of the above

43) The javax.sql.DataSource interface represents _____________ related to java application


a. data sources
b. data packets
c. socket
d. all of the above
44) The javax.sql.CommonDataSource provides the methods that are common between
______________ interfaces

a) DataSource,XADataSource,ConnectionPoolDataSource
b) Data.XAData,ConnectionPoolData
c) Source.XASource,ConnectionPoolSource
d) source.xadatasource,connectionpoll

45) Connections made by using __________ objects are implemented on the middle-tier
connection pool.

a) DataSource
b) datasopurce
c) datasorce
d )none of the above

46) _________ provides a factory for PooledConnection objects.

a) javax.sql.ConnectionPoolDataSource
b) java.sql.ConnectionPoolDataSource
c) javax.sqlConnectionPoolDataSource
d) javax.sql,ConnectionPoolDataSource

47) __________ provides an object to manage connection pools.


a) javax.sql.ConnectionPoolDataSource

b) javax.sql.PooledConnectionInterface
c) javax.sqlConnectionPoolDataSource
d) javax.sql,ConnectionPoolDataSource

48) DriverManager is a …….. class in JDBC API.


a) Abstract

b) Non-Abstract

c) main

d) none of the above

49) How many constructor are in the DriverManager Class?

a) One

b) two

c) three

d) four

50) What is the Driver Interface used for?

a) To create Database Object that provide and entry point for database connectivity

b) to contains the results of executing an SQL query.

c) To create Connection Object that provide an entry point for database


connectivity.

d) none

51) What is connection interface?

a) It is a standard type that defines an abstraction to access the session


established with database server.

b) It is used to create Connection Object that provides an entry point for database
connectivity.

c) both a and b

d) none of the above

52) The Connection interface provides methods to handle

a) ResultSet Object
b) Connection Object

c) PreparedStatement Object

d) none of the above.

53) What does the Statement interface return?

a) ResultSet Object

b) Connection Object

c) PreparedStatement Object

d) None of the above

54) How many times the query is compiled when used PreparedStatement?

a) once

b) twice

c) thrice

d) quadriple

55) How to create an object and execute a query in PreparedStatement?

a)PreparedStatement stmt=new PreparedStatement("insert into Emp values(a,b)");

b) PreparedStatement stmt=con.prepareStatement("insert into Emp


values(a,b)");

c)PreparedStatement stmt=con.prepareStatement("insert into Emp values(a,b)");

d)none of the above

56) Syntax for ResultSet:

a) ResultSet rs=new ResultSet(“Query-to-be-executed");

b)resultset rs=stmt.executequery(“Query-to-be-executed");

c)ResultSet rs=stmt.executeQuery(“Query-to-be-executed");
d) None of the above

57) What is "jdbc:mysql://localhost:3306/sonoo","root","root"

a)path to the database

b)driver location

c)both a and b

d)None of the above

58) Steps for jdbc:

(i) Closing the connection

(ii) Executing SQL statements

(iii) Obtaining a connection

(iv) Creating a JDBC Statement object

a) i, ii, iii, iv

b) ii, iii,iv,i

c) iii, iv , ii , i

d) iii, ii, iv, i

59) Path for Data Sources(ODBC):

a)start->control panel -> system and security -> data sources

b)start ->control panel->system and security->administrative tools->data sources

c)start->control panel->data sources

d)start->accessories->data sources

60) Which driver is required for ODBC connectivity

a)MicrosoftODBCForOracle
b) MicrosoftODBCforOracle

c) MicrosoftOdbcForOracle

d) MicrosoftOdbcforOracle

61) A Java program cannot directly communicate with an ODBC driver because .......

a) ODBC written in C language


b) ODBC written in C# language
c) ODBC written in C++ language
d) ODBC written in Basic language

62) The JDBC-ODBC Bridge driver translates the JDBC API to the ODBC API and used
with ________

a) JDBC drivers
b) ODBC drivers
c) Both A and B
d) None of the above

63) The ............................. package contains classes that help in connecting to a database,
sending SQL statements to the database, and processing the query results.

a) connection.sql
b) db.sql
c) pkg.sql
d) java.sql

64) The ................................ method executes a simple query and returns a singleResult Set
object.
a) executeUpdate()

b) executeQuery()
c) execute()
d) noexecute()
65) The ......................... method executes an SQL statement that may return multiple results.
a) executeUpdate()
b) executeQuery()
c) execute()
d) noexecute()

66) The ........................ object allows you to execute parametrized queries.


a) ResultSet
b) Parametrized
c) PreparedStatement
d) Condition

67) The .................. object provides you with methods to access data from the table.
a) ResultSet
b) Parametrized
c) TableStatement
d) Condition

68) The parameters of the PreparedStatement object are ...................... when the user clicks
on the Query button.
a) initialized
b) started
c) paused
d) stopped

69) The ...................... method sets the query parameters of the PreparedStatement Object.
a) putString()
b) insertString()
c) setString()
d) setToString()

70) Connection object can be initialized using the ............................ method of the Driver
Manager class.
a) putConnection()
b) setConnection()
c) Connection()
d) getConnetion()
71) Which of the following statements is false as different type of statements is concern in
JDBC?

a)Regular Statement

b)Prepared Statement

c)Callable Statement

d)Interim Statement

72) JDBC-ODBC bridge supports multiple concurrent open statements per connection?

a)True

b)False

73) Which driver is efficient and always preferable for using JDBC application:

a)Type – 4
b)Type – 1
c)Type – 3
d)Type – 2

74) A Java program cannot directly communicate with an ODBC driver because
a) Statement is wrong
b) ODBC written in C language
c) ODBC written in high level language
d) None of above

75) Abbreviate the term DSN


a) Data Source Name
b) Data Server name
c) Database Server Name
d) Data String Name

76) API stands for


a)Applet Program Interface
b)Application Program Interface
c)Application procedure Interface
d) None of above

77) API which controls access to the row result of a given Statement and holds data retrieved
from a database after you execute an SQL query using Statement objects.
a)java.Sql

b)java.ResultSet

c)Java.sql

d)java.sql.ResultSet

78) Application Server used in ____________________.


a) Three-Tier Mode
b) Two-Tier Mode
c) Milti-Tier Mode
d) Single-Tier Mode

79) Backbone of JDBC Architecture is ________________


a) Driver Manager
b) Database Manager
c) Statement Interface
d) Resultset Interface

80) Which method is used to modify stored data

a)execute()
b)executeQuery()
c)executeUpdate()
d)executeResult()

81) How many transaction isolation levels are defined in sql.connection interface?

a)4
b)3
c)5
d)2

82) Which of the following is false as type 4 driver is concern

a)Type 4 driver is “native protocol, pure java” driver


b)Type 4 drivers are 100% Java compatible
c)Type 4 drivers uses Socket class to connect to the database
d)Type 4 drivers can not be used with Netscape
83) All raw data types should be read and uploaded to the database as an array of :

a)byte
b)int
c)boolean
d)char

84) Which method is used to perform DML statements in JDBC

a)execute()

b)executeQuery()

c)executeUpdate()

d)None of above

85) JDBC stands for:

a)Java Database Connectivity

b)Java Database Components

c)Java Database Control

d)None of the above is correct.

86) The ................................ method executes a simple query and returns a single Result Set
object.

a)executeUpdate()

b)executeQuery()

c) execute()

d) noexecute()

87) The ........................ object allows you to execute parametarized queries.

a)ResultSet

b)Parametrized
c)PreparedStatement

d)Condition

88) Three methods are central to the life cycle of a servlet ___________, __________ and
________ .

a)init(), main(), run()

b)init(), service(), destroy()

c)init(), run(), stop()

d)init(), start(), stop()

89) What is data in following program.


import java.sql.*;
public class Selectdbase
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:data");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from emp");
while(rs.next())
{
System.out.println("id:"+rs.getInt("id"));
System.out.println("salary:"+rs.getString("salary"));
System.out.println("name:"+rs.getString("name1"));
}
con.close();
}
catch(SQLException e)
{}
catch(Exception e)
{
}
}}

a)Driver name
b)database name
c)table name
d)data source name
90) What is output of following program.

import java.sql.*;
public class jdbc1
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:data");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from student");
while(rs.next())
{
System.out.println("id:"+rs.getInt("id"));
System.out.println("name:"+rs.getString("name1"));
}
con.close();
}
catch(SQLException e)
{}
catch(Exception e)
{
}
}}

a) "id:"+rs.getInt("id"
b)name:"+rs.getString("name1
c) both a and b
d)values of id and name will be displayed from table.

91) Which is the correct method ********for updating table rows from given option.

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:data");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from emp");

St.********("Update emp set name1='jack' where id=2");


System.out.println("\n\nafter change");
rs=st.executeQuery("select * from emp");
while(rs.next())
{
System.out.println("id:"+rs.getInt("id"));
System.out.println("salary:"+rs.getString("salary"));
}
con.close();
}
catch(SQLException e){}
catch(Exception e)
{
}
}}

a)executeUpdate()
b)executeQuery()
c)execute()
d)ExecuteUpdate()

92) 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)Error in resultSet statement.


b)Error in while loop
c)both a and b
d)Error in catch()
93) Find out error in following program.

import java.sql.*;
public class Selectdbase
{
public static void main(string args[])
{
try
{
Class.forname("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:data");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from emp");
while(rs.next())
{
System.out.println("id:"+rs.getInt("id"));
System.out.println("salary:"+rs.getString("salary"));
System.out.println("name:"+rs.getString("name1"));
}
con.close();
}
catch(SQLException e)
{}
catch(Exception e)
{
}
}}

a)Error in main()
b)Error in try block
c)both a and b
d)Error in catch block

94) Find the error in following code:

import java.sql.*;

class MysqlCon

public static void main(String args[])

try{

Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection (
"jdbc:mysql://localhost:3306/sonoo","root","root");

//here sonoo is database name, root is username and password

Statement stmt=con.createStatement();

ResultSet rs=stmt.executeQuery("select * from emp");

while(rs.next())

System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));

catch(Exception e)

System.out.println(e);

a.missing semicolon

b.Connection is not terminated.(con.close())

c.missing brackets

d. both a and c

e. all of the above

95) Find the error in following code:

import java.sql.*;
class MysqlCon{
public static void main(String args[]){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/sonoo","root","root");
//here sonoo is database name, root is username and password
Statement stmt=con.createStatement();
ResultSet rs=executeQuery("select * from emp");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
con.close(); }
catch(Exception e){
System.out.println(e);}
}}

a)missing semicolon
b)incorrect syntax of Statement
c)incorrect syntax of ResultSet
d)both a and c
e)all of the above

96) Find the error in following code:

import java.sql.*;

class MysqlCon{

public static void main(String args[]){

try{

Class.forName("com.mysql.jdbc.Driver");

Connection con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/sonoo","root","root");

//here sonoo is database name, root is username and password

Statement stmt=createStatement();

ResultSet rs=executeQuery("select * from emp");

while(rs.next())

System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));

con.close(); }

catch(Exception e){
System.out.println(e)}

}}

a.missing semicolon

b.incorrect syntax of Statement

c.incorrect syntax of ResultSet

d. both a and c

e. all of the above

97) Find the error in following code:

import java.awt.*;

class JdbcDemo {

public static void main(String a[]) {

try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

System.out.println("Driver Loaded");

String url="jdbc:odbc:StudInfo";

Connection con=DriverManager.getConnection(url);

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

Statement stmt = con.createStatement();

String query = "select * from StudTable";

ResultSet rs = stmt.executeQuery(query);

while(rs.next()){

System.out.println(" ID : "+ rs.getInt(1));

System.out.println(" Name : "+ rs.getString(2));


System.out.println(" Marks : "+ rs.getInt(3));
System.out.println();

}}

catch(ClassNotFoundException e)

e.printStackTrace();

catch(SQLException e)

e.printStackTrace();

}}}

a)missing semicolon

b)missing bracket

c)incorrect syntax of resultset

d) None of the above

98) What will be the output of the code considering the database is created:

import java.sql.*;

class JdbcDemo {

public static void main(String a[]) {

try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

System.out.println("Driver Loaded");

String url="jdbc:odbc:StudInfo";

Connection con=DriverManager.getConnection(url);
System.out.println(" Connection to DataBase created");

Statement stmt = con.createStatement();

String query = "select * from StudTable";

ResultSet rs = stmt.executeQuery(query);

while(rs.next()){

System.out.println(" ID : "+ rs.getInt(1));

System.out.println(" Name : "+ rs.getString(2));

System.out.println(" Marks : "+ rs.getInt(3));


System.out.println();

}}

catch(ClassNotFoundException e)

e.printStackTrace();

catch(SQLException e)

e.printStackTrace();

}}}
a.

b.it contains error

c.none of the above

99) Find the error in following code:

import java.awt.*;

class JdbcDemo {

public static void main(String a[]) {

try {

Class.forName("sun.jdbc.odbc");

System.out.println("Driver Loaded");

String url="jdbc:odbc:StudInfo";

Connection con=DriverManager.getConnection(url);

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

Statement stmt = con.createStatement();

String query = "select * from StudTable";


ResultSet rs = stmt.executeQuery(query);

while(rs.next()){

System.out.println(" ID : "+ rs.getInt(1));

System.out.println(" Name : "+ rs.getString(2));

System.out.println(" Marks : "+ rs.getInt(3));


System.out.println();

}}

catch(ClassNotFoundException e)

e.printStackTrace();

catch(SQLException e)

e.printStackTrace();

a.missing semicolon

b.missing bracket

c.driver is not suitable

d. None of the above

100) boolean isLast() method defines _______


a) Determines whether the ResultSet cursor points to the second last row
b) Determines whether the ResultSet cursor points to the last statement
c) Determines whether the ResultSet cursor points to the last Column
d) Determines whether the ResultSet cursor points to the last row

101) Callable statement object in JDBC is used to execute a call to


a) stored procedure
b) Statement
c) Prepared Statement
d) Procedure

102) CallableStatement is used to execute_________________


a) stored procedure
b) Statement
c) Prepared Statement
d) Procedure

103) Class.forName("_________________________")
a) sun.jdbc.JdbcOdbcDriver
b) jdbc.odbc.JdbcOdbcDriver
c) sun.jdbc.odbc.JdbcOdbcDriver
d) sun.jdbc.odbc.JdbcOdbc

104) class.forName() method throws


a) NotFoundException
b) ClassNotFoundException
c) SQLException
d) Cant Throws any exception

105) Connection object can be initialized using the _______ method of the DriverManager
Class.
a) getConnection()
b) getManager()
c) getconnection()
d) Getmanager()

106) createStatement() method without any parameter is used to create a statement with

forward only and read only ResultSet Database meta data are retrieved through
________.

a) PreparedStatement object

b) Statement object

c) Connection object
d) CollableStatement object

107) DELETE statement of an SQL is executed by ______________.

a) executeUpdate()

b) executeQuery()

c) Execute()

d) executeStatement()

108) DriverManager.getConnection(_______ , ______ , ______) What are the two


parameters that are included ?

a) User ID,URL or machine name where server runs, Password

b) URL or machine name where server runs, Password, User ID,

c) URL or machine name where server runs, User ID, Password

d) Database name, User ID, Password

109) Every driver must provide a class that should implement the __________________

a) Driver interface

b) Connection Interface

c) Statement Interface

d) Database Interface

110) Following is return type of executeUpdate( ):

a) String

b) Array

c) byte

d) Int
111) execution of delete SQL query in JDBC, ............. method must be used.

a) execute()

b) executeQuery()

c) executeUpdate()

d) executeStatement()

112) For execution of INSERT SQL query in JDBC, ............. method must be used.

a) executeUpdate()

b) executeStatement()

c) executeQuery()

d) Execute()

113) For execution of SELECT SQL query in JDBC, ___________________ method must
be used.

a) executeQuery()

b) Execute()

c) executeUpdate()

d) executeAll()

114) forName is a_______________________type method

a) Static

b) Dynamic

115) getConnection() method of which class

a) DriverManager

b) Statement
c) Connection

d) None of above

116) How many JDBC driver types are available by sun Microsystem?

a) 6

b) 4

c) 5

d) 3

117) If a PreparedStatement is a SQL SELECT statement, you execute the statement using

________.

a) PreparedStatement.execute();

b) Statement.executeQuery();

c) PreparedStatement.executeQuery();

d) PreparedStatement.executeUpdate();

118) If you need to use a stored procedure with output parameters, which of the following

statement type should be used to call the procedure?

a) CallableStatement

b) PreparedStatement

c) Statement

d) ProcedureStatement

119) In 2-tier architecture , the first tier is generally_________________________

a) GUI

b) Server

c) Client
d) database

120) In the following JDBC drivers which is known as partly java driver?

a) Pure-Java Driver

b) JDBC-net Pure Java

c) JDBC driver

d) Native-API driver

121) In the three tier model the middle tier of the services acts as a mediator between

________________________ and _________________.

a) Java application and databases

b) Client and Server

c) Java application and client

d) Java application and server

122) JDBC is a --------------------- interface, which means that it is used to invoke SQL
commands directly.

a) high level

b) low level

c) middle level

d) top level

123) JDBC Stands for

a) Java Database Connection

b) Java Database Connectivity

124) JDBC-ODBC bridge product provide _________ access via ____________.


a) JDBC driver, JDBC drivers

b) ODBC drivers, JDBC driver

c) JDBC driver, ODBC drivers

d) None

125) Methods of ResultSet() throws ____________

a) IOException

b) Exception

c) DatabaseException

d) SQLException

126) Name the type number of driver belongs to JDBC ODBC Bridge driver?

a) Type 1

b) Type 2

c) Type 3

d) Type 4

127) Native API converts ___________into the __________ used by DBMS.

a) Native API calls,JDBC API

b) JDBC API, Native API calls

c) JDBC API, pure API calls

d) JDBC API, pure Java

128) Native – protocol pure Java converts ……….. in to the ………… used by DBMSs
directly.

a) JDBC calls, network protocol

b) Native API calls,JDBC API


c) JDBC API, pure API call

d) JDBC API, Native API calls

129) ODBC Drivers are platform _______________

a) Dependent

b) Independent

c) Both a and b

d) None

130) ODBC requires configuring _______ which represents the target database.

a) Data String Name

b) Data Source Name

c) Domain Name

d) Database name

131) The PreparedStatement__________symbol is placeholder that is replaced by the input

parameter at seen time.

a) ?

b) *

c) &

d) #

132) The ResultSet __________________provides methods for retrieving and manipulating


the results of executed queries.

a) Statement

b) Package

c) Class
d) Interface

133) The Type 3 architecture is _______________________

a) JDBC-Net pure Java

b) JDBC-ODBC Bridge Driver

c) Native API partly Java driver

d) Native Protocol Pure-Java Driver

134) The_____________________ is the language for interacting with Database.

a) Structured Query Language

b) Data Manipulation Language

c) Data Definition Language

d) Stored Query Language

135) Type 1 driver is also known as

a) Native API partly Java driver

b) Native Protocol Pure-Java Driver

c) JDBC-ODBC Bridge Driver

d) JDBC-Net pure Java

136) Type 3 driver is also known as_________________

a) JDBC-net Pure Java

b) JDBC-Net pure Java

c) Native API partly Java driver

d) Native Protocol Pure-Java Driver


137) Type II JDBC driver is also known as __________________

a) JDBC-net Pure Java

b) JDBC-Net pure Java

c) Native API partly Java driver

d) Native Protocol Pure-Java Driver

138) Type IV JDBC driver is also known as __________________

a) DBC-net Pure Java

b) JDBC-Net pure Java

c) Native API partly Java driver

d) Native Protocol Pure-Java Driver

139) Type4 driver is also known as:

a) 100% Pure Java

b) DBC-net Pure Java

c) JDBC-Net pure Java

d) Native API partly Java driver

140) Where the object of ResultSet maintains a cursor?

a) Second Row

b) First Row

c) Last Row

d) Middle Row

141) Which class is used to connect java application to JDBC driver

a) DriverManager

b) Connection
c) Statement

d) ResultSet

142) Which driver is called as a thin driver in JDBC?

a) Type-2 Driver

b) Type-3 Driver

c) Type-1 Driver

d) Type-4 Driver

143) Which interface provides methods to execute queries with the database?

a) Statement interface

b) Connection

c) Resultset

d) DriverManager

144) Which Interface is used to execute dynamic SQL statements?

a) PreparedStatement

b) Statement

c) CallableStatement

d) Procedurestatement

145) Which is default ResultSet type

a) TYPE_SCROLL_SENSITIVE

b) TYPE_SCROLL_INSENSITIVE

c) TYPE_FORWARD_ONLY

d) TYPE_SCROLL_FIRST
146) Which JDBC driver Type (s) can be used in either applet or servelt code?

a) Type 2

b) Type 3

c) Type 4

d) Both Type 3 and Type 4

147) Which JDBC driver Type(s) can you use in a three-tier architecture and if the Web
server and the DBMS are running on the same machine?

a) Type 3

b) Type 2

c) Type 4

d) Both Type 3 and 4

148) Which JDBC driver Types are used for over communications networks?

a) Type 2

b) Type 3

c) Type 4

d) Both Type 3 and Type 4

149) Which method is used to obtain count of total rows of ResultSet

a) getRow()

b) getrow()

c) GetRow()

d) Row()

150) Which method is used to perform DML statements in JDBC?

a) executeQuery()
b) execute()

c) executeUpdate()

d) executeAll()

151) Which method of class is used to register & dynamically load the driver class?

a) forName()

b) DeviceManager

c) Statement

d) Resultset

152) which of the following function is used to find the column count of the particular
ResultSet ?

a) getColumnCount()

b) getRow

c) getcolumnCount()

d) getcolumncount()

153) Which of the following invokes functions in sql ?

a) Callable statements

b) Prepared Statement

c) Procedure Statement

d) Statement

154) Which type of driver converts JDBC calls into the network protocol used by the
database management system directely

a) Type 4

b) Type 3

c) Type 2
d) Type 1

155) Which type of driver is unqiue in JDBC?

a) Native Protocol Pure-Java Driver

b) JDBC-Native API

c) Native API partly Java driver

d) JDBC-ODBC Bridge Driver

156) _______ calls get converted into native C or C++ API calls.

a) Native Protocol Pure-Java Driver

b) JDBC-Native API

c) Native API partly Java driver

d) JDBC-ODBC Bridge Driver

157) ___________ interface allows storing results of query?

a) ResultSet

b) Connection

c) Statement

d) DriverManager

158) All raw data types including binary documents or images should be read and uploaded
to the database as an array of ….

a) Byte

b) Int
c) String

d) Array

159) Analyse the following code and fill the appropriate statement in the blanks

import java.sql.*;

class DB

public static void main(String args[])throws Exception

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection con=DriverManager.getConnection("jdbc:odbc:mydsn");

Statement stmt=con.createStatement();

ResultSet rs=stmt.________________("select * from empwhere id=101");


System.out.println("EmpName\tDesignation\tSalary");

where(rs.next())

System.out.println(rs.getString(2)+"\t"+rs.getString(3)+"\t"+rs.getInt(4));

con.close();

Ans: executeQuery()

160) Choose missing statements in following code from given options.


import java.sql.*;

Class DemoFetch

public static void main(String args[])

Connection con;

Statement stmt;

ResultSet rs; String qry, url;

try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

url="Jdbc:Odbc:studdsn";

con=DriverManager.getConnection(url,"","");

stmt=con.createStatement();

qry="select * from stud"; rs=_______________;

System.out.println("Roll No\tName\tPercentage");

while(rs.next())

int rno=rs.getInt("roll");

String nm=rs.getString("sname");

double per=rs.getDouble("per");

System.out.println(rno+"\t"+nm+"\t"+per);

con.close();

catch(Exception e){}

}
Answer: stmt.executeQuery(qry)

161) Choose missing statements in following code from given options.

import java.sql.*;

Class DemoFetch1

public static void main(String args[])

Connection con;

PreparedStatement pstmt;

ResultSet rs;

String qry,url;

try

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

url="Jdbc:Odbc:studdsn";

con=DriverManager.getConnection(url,"","");

qry="select * from stud";

pstmt=con.prepareStatement(qry);

rs=___________________;

System.out.println("Roll No\tName\tPercentage");

while(rs.next())

int rno=rs.getInt("roll");

String nm=rs.getString("sname");
double per=rs.getDouble("per");

System.out.println(rno+"\t"+nm+"\t"+per);

con.close();

catch(Exception e)

System.out.println(e.toString());

Answer: pstmt.executeQuery(qry)

162)

Connection con = DriverManager.getConnection ("jdbc:odbc:wombat", "login", "password");

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM Table1");

while (rs.next())

Integer x = rs.getInt("c");

String s = rs.getString("a");

Float f = rs.getFloat("b");

What is WRONG with the code above?

Answer: Retrieval of the fields is in the wrong order.


163) Connection object can be initialized using the ............................ method of the Driver
Manager class.

a) getConnection()

b) Getconnection()

c) getStatement()

d) Getstatement()

164) Consider following code and state missing code ?

import java.sql.*;

class exp2

public static void main(String args[])throws Exception

try

Class.forName("_________________________________________");

Connection con=DriverManager.getConnection("Jdbc:Odbc:demo1dsn");

Statement st=con.createStatement();

ResultSet rs=st.executeQuery("select * from Table1");

System.out.println("After insertion of new record");

while(rs.next())

System.out.println(rs.getString(1));

System.out.println(rs.getString(2));

System.out.println(rs.getString(3));

}
st.executeUpdate("insert into Table1 values('jasmine',10,'banglore')");

ResultSet rs1=st.executeQuery("select * from Table1 ");

while(rs1.next())

System.out.println(rs1.getString(1));

System.out.println(rs1.getString(2));

System.out.println(rs1.getString(3));

catch(Exception e) {}

Answer: sun.jdbc.odbc.JdbcOdbcDriver

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

Statement s = conn.createStatement();
String s1="update Table1 set name1='akash' where rollno='1'";

s.executeQuery(s1); s.close();

conn.close();

Answer: s.executeUpdate(s1)

166) Consider the following program. What should be the method used in following 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.get***********("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();

}
}

Answer: Connection()

167) Consider the following program. Select the statement that should be added to get correct

output.

import java.sql.*;

class DBEx

public static void main(String args[])

Try

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection c =DriverManager.getConnection("jdbc:odbc:mydsn","","");

ResultSet rs = s.executeQuery("select * from StudTable");

while(rs.next())

System.out.println("Roll No.: "+rs.getInt(1));

System.out.println("Name : "+rs.getString(2));

System.out.println("Branch :"+rs.getString("Branch")+"\n");

s.close();

c.close();
}

catch(Exception e)

System.out.println("Caught: "+e);

Answer: Statement s = c.createStatement();

168) Consider the following program. Which two exceptions are thrown?

Package javaapplication21;

import java.sql.*;

public class db15 { public static void main(String args[])

throws _____________________, __________________

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection c=DriverManager.getConnection("jdbc:odbc:MyDSN","","");
System.out.println("Connection Established");

Answer: ClassNotFoundException, SQLException

169) Invoking Class.forName(mydriver) throws ___________.


a) ClassNotFoundException

b) IOException

c) SQLException

d) Both a and c

170) Permission class is part of_________package

a) java.security.permission

b) java.security

c) java.permission

d) None of above

171) PreparedStatement updateemp = con.prepareStatement("insert into emp values(?,?,?)");


How many values are need to insert for prepareStatement paprameter?

a) 3

b) 4

c) 2

d) 1

172) Set XXX() method binds values to the parameters. Where XXX represents

a) Data Type

b) Method

c) Interface

d) Class

173) The JDBC-ODBC bridge is:

a)Three tiered
b)Multithreaded
c)Best for any platform
d)All of the above

You might also like