Java All
Java All
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
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
d) Both a & b
c) Both a & b
d) None of these
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
d) FlowLayout
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
b) Drop-down
c) Choice
d) None of these
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
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
a) Container
b) Window
c) Frame
d) none
c) Panel
d ) None
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
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
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
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( )
c)Canvas
d)None
a)Component
b)Frame
c)Window
d)Panel
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
b)remove()
c)removeAll()
d)None of the above
d)removeAll( )
52)In the Label(String str, int how) constructor value of how will be-
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( )
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( )
d) action event
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( )
a)ItemListener , ItemEvent
b)MouseListener , MouseEvent
c)ActionListener , ActionEvent
d)KeyListener , KeyEvent
c)itemStateChanged()
d)ItemstateChanged()
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
69)In which of the following the only one checkbox will be selected.
a)Checkbox Win98 = new Checkbox("Windows 98/XP", cbg, 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
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
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()
b)AdjustmentListener
c)MouseMotionListener
d)ItemListener
b)TextField class
c)both a & b
d)none of the above
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()
a) setEditable( )
b) getEditable()
c) isEditable()
d) None of the above
b) setEchoChar( )
c) hideText()
d) setChar()
b)TextArea
c)Editor
d)Label
d)TextArea(Stringstr, intsrows)
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()
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
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
a) getPrefferedSize(),getMinimumSize( )
b) getPrefferedsize(),getMinimumsize( )
c) getprefferedSize(),getminimumSize( )
d) None
a) FlowLayout()
b) BorderLayout()
c) GridLayout()
d) CardLayout()
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
d) Both a and b
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
d) Two-dimensional
b) unique,layout
c) antique,methods
d) special,packages
c) Panel
d) Container
d) modal,modeless
c) Object
d) Package
c) FileDialog.LOAD
d) FileDialog.READ
a) FileDialog.SAVE
b) FileDialog.WRITE
c) FileDialog.LOAD
d) FileDialog.READ
116) Select the correct Menubar classes from the following options
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
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
a) true, setState()
b) check, setItemStatus()
c) check, setItemState()
d) None of these
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());
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
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(os);
}
a)Listener missing
b)applet code is missing
c)package missing
d)All
b)
c)
d)
Answer: a)
}
}
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 ()
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);
}
}
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));
b)
c)none of the above
d)all of these
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);
}
a)
b)
c)
d)
d) new TextArea(200)
133) Which of the following creates a List with 5 visible items and multiple selection
enabled?
b) new List(true, 5)
d) new List(false,5)
a) show( )
b) setVisible( )
c) display( )
d) displayFrame( )
e) both a and b
a) True
b) False
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
a) Window
b) Frame
c) Dialog
d) All of above
a) Panel
b) Applet
c) both a and b
d) only d
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?
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();
a) CheckboxMenuItem
b)Menu
c)MenuItem
d) All of above
a)setState(boolean)
b) setstate(boolean)
c)setEnabled(boolean)
d)setenabled(boolean)
a)A separator
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
a) KeyListener()
b) addKistener()
c) addKeyListener()
d) eventKeyboardListener()
a) Exception Handling
b) String Handling
c) Event Handling
d) None of the above
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) 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
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 ()
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
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
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
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()
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
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?
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.
a) Mouse pressed
b) Mouse clicked
c) Mouse dragged
d) Mouse released
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
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
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
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(*);
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)
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()
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
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
a) ScroolbarEvent
b) AdjustmentEvent
c) ActionEvent
d)TextAreaEvent
100) Identify correct name of event:
a) InputEvent
b) MouseMotionEvent
c) KeyEvent
d) MouseEvent
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
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
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());
}
a) KeyAdapterExample
b) KeyAdapter
c) KeyExample
d) AdapterExample
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
a) Statement 2 is False
b) Statement 3 is False
c) Statement 1 is False
d) Statement 1 and 4 are False
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");
}
}
}
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
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.
a) WindowAdapter, WindowEvent
b) MyWindowAdapter, WindowEvent
c) WindowAdapter, windowEvent
d) WindowEvent, WindowAdapter
a) FocusAdapter, FocusEvent
b) focusAdapter, FocusEvent
c) focusadapter, FocusEvent
d) FocusAdapter, Focusevent
a) ContainerEvent
b) ComponentEvent
c) FocusEvent
d) WindowEvent
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();
}
}
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
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
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
c. Display clock
d. None of the above
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
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
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
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()
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()
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()
20. Applet runs inside the browser and works at client side
a. True
b. False
b. paint()
c. displayApplet()
d. printApplet()
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
c. Compilation Error
d. Runtime Error
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>
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
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 );
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
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.
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.
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
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
a. Graphics class
b. Component class
c. Both A & B
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)
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)
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
b. Button,Checkbox,Choice
c. Scrollbar,Component,Button
b. AWT
c. Both A & B
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
c. Event Handling
d. None of the above
b. Other class
c. Anonymous class
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
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
b. Register the JDBC driver, so that you can open a communications channel with
the database.
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)
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
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
77. Which class has traditionally been the backbone of the JDBC architecture?
a. the JDBC driver manager
b. the JDBC driver test suite
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
d. Both B & C
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
83. A leading database connectivity vendor, worked together to produce the ____.
a. JDBC-ODBC Bridge
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
d. Thin driver
89. How many JDBC product components does the Java software provides?
a. 3
b. 2
c. 4
d. 5
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
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
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
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
99. Which packages represent interfaces and classes for servlet API?
a. javax.servlet
b. javax.servlet.http
c. Both A & B
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
b. POST
c. Both A & B
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
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
c. JBoss
d. Weblogic
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
b. False
110. Which method is used to specify before any lines that uses the PintWriter?
a. setPageType()
b. setContextType()
c. setContentType()
d. setResponseType()
b. Communication Support
c. Multithreading Support
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
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
c. Both
d. None
c. 1,2,3
d. 1,4
b. servlet container
c. the supporting protocol (such as http or https)
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)
b. i, ii are correct
c. i, iii are correct
c. i, vi, iii, v
d. i, ii, iii, v
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
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
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
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
b. Scriptlet tag
c. Expression tag
c. Both A & B
d. None of the above
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
a. translation
b. compilation
c. syntax
d. Both A and B
c. dynamic attributes
d. global attributes
d. Both B and C
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
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
b. page
c. export
d. useBean
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
b. Window class
c. Frame class
d. Dialog class
b. Server
c. Tomcat
d. Applet
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
b. Event Class
c. Inner class
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
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
d) Both a & b
c) Both a & b
d) None of these
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
d) FlowLayout
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
b) Drop-down
c) Choice
d) None of these
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
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
a) Container
b) Window
c) Frame
d) none
c) Panel
d ) None
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
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
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
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( )
c)Canvas
d)None
a)Component
b)Frame
c)Window
d)Panel
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
b)remove()
c)removeAll()
d)None of the above
d)removeAll( )
52)In the Label(String str, int how) constructor value of how will be-
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( )
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( )
d) action event
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( )
a)ItemListener , ItemEvent
b)MouseListener , MouseEvent
c)ActionListener , ActionEvent
d)KeyListener , KeyEvent
c)itemStateChanged()
d)ItemstateChanged()
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
69)In which of the following the only one checkbox will be selected.
a)Checkbox Win98 = new Checkbox("Windows 98/XP", cbg, 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
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
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()
b)AdjustmentListener
c)MouseMotionListener
d)ItemListener
b)TextField class
c)both a & b
d)none of the above
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()
a) setEditable( )
b) getEditable()
c) isEditable()
d) None of the above
b) setEchoChar( )
c) hideText()
d) setChar()
b)TextArea
c)Editor
d)Label
d)TextArea(Stringstr, intsrows)
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()
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
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
a) getPrefferedSize(),getMinimumSize( )
b) getPrefferedsize(),getMinimumsize( )
c) getprefferedSize(),getminimumSize( )
d) None
a) FlowLayout()
b) BorderLayout()
c) GridLayout()
d) CardLayout()
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
d) Both a and b
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
d) Two-dimensional
b) unique,layout
c) antique,methods
d) special,packages
c) Panel
d) Container
d) modal,modeless
c) Object
d) Package
c) FileDialog.LOAD
d) FileDialog.READ
a) FileDialog.SAVE
b) FileDialog.WRITE
c) FileDialog.LOAD
d) FileDialog.READ
116) Select the correct Menubar classes from the following options
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
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
a) true, setState()
b) check, setItemStatus()
c) check, setItemState()
d) None of these
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());
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
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(os);
}
a)Listener missing
b)applet code is missing
c)package missing
d)All
b)
c)
d)
Answer: a)
}
}
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 ()
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);
}
}
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));
b)
c)none of the above
d)all of these
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);
}
a)
b)
c)
d)
d) new TextArea(200)
133) Which of the following creates a List with 5 visible items and multiple selection
enabled?
b) new List(true, 5)
d) new List(false,5)
a) show( )
b) setVisible( )
c) display( )
d) displayFrame( )
e) both a and b
a) True
b) False
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
a) Window
b) Frame
c) Dialog
d) All of above
a) Panel
b) Applet
c) both a and b
d) only d
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?
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();
a) CheckboxMenuItem
b)Menu
c)MenuItem
d) All of above
a)setState(boolean)
b) setstate(boolean)
c)setEnabled(boolean)
d)setenabled(boolean)
a)A separator
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
a) KeyListener()
b) addKistener()
c) addKeyListener()
d) eventKeyboardListener()
a) Exception Handling
b) String Handling
c) Event Handling
d) None of the above
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) 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
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 ()
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
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
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
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()
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
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?
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.
a) Mouse pressed
b) Mouse clicked
c) Mouse dragged
d) Mouse released
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
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
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
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(*);
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)
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()
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
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
a) ScroolbarEvent
b) AdjustmentEvent
c) ActionEvent
d)TextAreaEvent
100) Identify correct name of event:
a) InputEvent
b) MouseMotionEvent
c) KeyEvent
d) MouseEvent
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
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
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());
}
a) KeyAdapterExample
b) KeyAdapter
c) KeyExample
d) AdapterExample
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
a) Statement 2 is False
b) Statement 3 is False
c) Statement 1 is False
d) Statement 1 and 4 are False
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");
}
}
}
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
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.
a) WindowAdapter, WindowEvent
b) MyWindowAdapter, WindowEvent
c) WindowAdapter, windowEvent
d) WindowEvent, WindowAdapter
a) FocusAdapter, FocusEvent
b) focusAdapter, FocusEvent
c) focusadapter, FocusEvent
d) FocusAdapter, Focusevent
a) ContainerEvent
b) ComponentEvent
c) FocusEvent
d) WindowEvent
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();
}
}
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
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
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
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
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
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)
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)
c) Both a and b
d) None of the above
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
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
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
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. javax.sql
d. java.io.sql
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)
a True
b. false
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. 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()
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
a) javax.sql.ConnectionPoolDataSource
b) java.sql.ConnectionPoolDataSource
c) javax.sqlConnectionPoolDataSource
d) javax.sql,ConnectionPoolDataSource
b) javax.sql.PooledConnectionInterface
c) javax.sqlConnectionPoolDataSource
d) javax.sql,ConnectionPoolDataSource
b) Non-Abstract
c) main
a) One
b) two
c) three
d) four
a) To create Database Object that provide and entry point for database connectivity
d) none
b) It is used to create Connection Object that provides an entry point for database
connectivity.
c) both a and b
a) ResultSet Object
b) Connection Object
c) PreparedStatement Object
a) ResultSet Object
b) Connection Object
c) PreparedStatement Object
54) How many times the query is compiled when used PreparedStatement?
a) once
b) twice
c) thrice
d) quadriple
b)resultset rs=stmt.executequery(“Query-to-be-executed");
c)ResultSet rs=stmt.executeQuery(“Query-to-be-executed");
d) None of the above
b)driver location
c)both a and b
a) i, ii, iii, iv
b) ii, iii,iv,i
c) iii, iv , ii , i
d)start->accessories->data sources
a)MicrosoftODBCForOracle
b) MicrosoftODBCforOracle
c) MicrosoftOdbcForOracle
d) MicrosoftOdbcforOracle
61) A Java program cannot directly communicate with an ODBC driver because .......
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()
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
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
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
a)byte
b)int
c)boolean
d)char
a)execute()
b)executeQuery()
c)executeUpdate()
d)None of above
86) The ................................ method executes a simple query and returns a single Result Set
object.
a)executeUpdate()
b)executeQuery()
c) execute()
d) noexecute()
a)ResultSet
b)Parametrized
c)PreparedStatement
d)Condition
88) Three methods are central to the life cycle of a servlet ___________, __________ and
________ .
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");
a)executeUpdate()
b)executeQuery()
c)execute()
d)ExecuteUpdate()
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)
{
}
}}
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
import java.sql.*;
class MysqlCon
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection (
"jdbc:mysql://localhost:3306/sonoo","root","root");
Statement stmt=con.createStatement();
while(rs.next())
catch(Exception e)
System.out.println(e);
a.missing semicolon
c.missing brackets
d. both a and c
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
import java.sql.*;
class MysqlCon{
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/sonoo","root","root");
Statement stmt=createStatement();
while(rs.next())
con.close(); }
catch(Exception e){
System.out.println(e)}
}}
a.missing semicolon
d. both a and c
import java.awt.*;
class JdbcDemo {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver Loaded");
String url="jdbc:odbc:StudInfo";
Connection con=DriverManager.getConnection(url);
ResultSet rs = stmt.executeQuery(query);
while(rs.next()){
}}
catch(ClassNotFoundException e)
e.printStackTrace();
catch(SQLException e)
e.printStackTrace();
}}}
a)missing semicolon
b)missing bracket
98) What will be the output of the code considering the database is created:
import java.sql.*;
class JdbcDemo {
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");
ResultSet rs = stmt.executeQuery(query);
while(rs.next()){
}}
catch(ClassNotFoundException e)
e.printStackTrace();
catch(SQLException e)
e.printStackTrace();
}}}
a.
import java.awt.*;
class JdbcDemo {
try {
Class.forName("sun.jdbc.odbc");
System.out.println("Driver Loaded");
String url="jdbc:odbc:StudInfo";
Connection con=DriverManager.getConnection(url);
while(rs.next()){
}}
catch(ClassNotFoundException e)
e.printStackTrace();
catch(SQLException e)
e.printStackTrace();
a.missing semicolon
b.missing bracket
103) Class.forName("_________________________")
a) sun.jdbc.JdbcOdbcDriver
b) jdbc.odbc.JdbcOdbcDriver
c) sun.jdbc.odbc.JdbcOdbcDriver
d) sun.jdbc.odbc.JdbcOdbc
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
a) executeUpdate()
b) executeQuery()
c) Execute()
d) executeStatement()
109) Every driver must provide a class that should implement the __________________
a) Driver interface
b) Connection Interface
c) Statement Interface
d) Database Interface
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()
a) Static
b) Dynamic
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
a) CallableStatement
b) PreparedStatement
c) Statement
d) ProcedureStatement
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
c) JDBC driver
d) Native-API driver
121) In the three tier model the middle tier of the services acts as a mediator between
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
d) None
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
128) Native – protocol pure Java converts ……….. in to the ………… used by DBMSs
directly.
a) Dependent
b) Independent
c) Both a and b
d) None
130) ODBC requires configuring _______ which represents the target database.
c) Domain Name
d) Database name
a) ?
b) *
c) &
d) #
a) Statement
b) Package
c) Class
d) Interface
a) Second Row
b) First Row
c) Last Row
d) Middle Row
a) DriverManager
b) Connection
c) Statement
d) ResultSet
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
a) PreparedStatement
b) Statement
c) CallableStatement
d) Procedurestatement
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
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
148) Which JDBC driver Types are used for over communications networks?
a) Type 2
b) Type 3
c) Type 4
a) getRow()
b) getrow()
c) GetRow()
d) Row()
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()
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
b) JDBC-Native API
156) _______ calls get converted into native C or C++ API calls.
b) JDBC-Native API
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
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mydsn");
Statement stmt=con.createStatement();
where(rs.next())
System.out.println(rs.getString(2)+"\t"+rs.getString(3)+"\t"+rs.getInt(4));
con.close();
Ans: executeQuery()
Class DemoFetch
Connection con;
Statement stmt;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
url="Jdbc:Odbc:studdsn";
con=DriverManager.getConnection(url,"","");
stmt=con.createStatement();
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)
import java.sql.*;
Class DemoFetch1
Connection con;
PreparedStatement pstmt;
ResultSet rs;
String qry,url;
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
url="Jdbc:Odbc:studdsn";
con=DriverManager.getConnection(url,"","");
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)
while (rs.next())
Integer x = rs.getInt("c");
String s = rs.getString("a");
Float f = rs.getFloat("b");
a) getConnection()
b) Getconnection()
c) getStatement()
d) Getstatement()
import java.sql.*;
class exp2
try
Class.forName("_________________________________________");
Connection con=DriverManager.getConnection("Jdbc:Odbc:demo1dsn");
Statement st=con.createStatement();
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')");
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.*;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
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
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Statement s=c.createStatement();
while(rs.next())
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
Try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c =DriverManager.getConnection("jdbc:odbc:mydsn","","");
while(rs.next())
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);
168) Consider the following program. Which two exceptions are thrown?
Package javaapplication21;
import java.sql.*;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:MyDSN","","");
System.out.println("Connection Established");
b) IOException
c) SQLException
d) Both a and c
a) java.security.permission
b) java.security
c) java.permission
d) None of above
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
a)Three tiered
b)Multithreaded
c)Best for any platform
d)All of the above