0% found this document useful (0 votes)
47 views88 pages

Ajp Imp

Uploaded by

Vighnesh Pote
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views88 pages

Ajp Imp

Uploaded by

Vighnesh Pote
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 88

IMP SET 1

Program : - Computer Engineering Group Program Code:- CM/IF


Course Title: -Advanced Java Programming Semester: - Fifth
Course Abbr &Code:-AJP (22517) Scheme: I

--------------------------------------------------------------------------------------------------
CHAPTER-1 (Abstract Windowing Toolkit (AWT)) (CO1 And CO2)

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

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

2. Which of these operators can be used to get run time information about an object?

a) getInfo
b) Info

PRACTICALKIDA.COM
c) instanceof
d) getinfoof

3. Which of these package is used for handling security related issues in a program?

a) java.security
b) java.lang.security
c) java.awt.image
d) java.io.security

4. The order of the three top level elements of the java source file are___.

a. Import, Package, Class


b. Class, Import, Package
c. Package, Import, Class
d. Random order

5. Which one is not supported by OOP?

a. Abstraction
b. Polymorphism
c. Encapsulation
d. Global variables

6. Java programs are_____.

a. Platform-dependent
b. Interpreter-dependent
c. Platform-independent
d. Interpreter-independent

7. The new operator_____.

a. returns a pointer to a variable


b. creates a variable called new
c. obtains memory for a new variable
d. tells how much memory is available

8. Java language has support for which of the following types of comment?

a. block, line and javadoc


b. javadoc, literal and string
c. javadoc, char and string

PRACTICALKIDA.COM
d. single, multiple and quote

9. Command to execute a compiled java program is :

a. javac
b. java
c. run
d. execute

10. ______ is a mechanism for naming and visibility control of a class and its content.

a. Object
b. Packages
c. Interfaces
d. None of the Mentioned

11. The java compiler____.

a. creates executable
b. translates java source code to byte code
c. creates classes
d. produces java Interpreter
12. Where are the following four methods commonly used?
1) public void add(Component c)
2) public void setSize(int width,int height)
3) public void setLayout(LayoutManager m)
4) public void setVisible(boolean)

a. Graphics class
b. Component class
c. Both A & B
d. None of the above

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

14. Which is used to store data and partial results, as well as to perform dynamic linking, return
values for methods, and dispatch exceptions?

PRACTICALKIDA.COM
a. Window
b. Panel
c. Frame
d. Container

15. AWT has more powerful components like tables, lists, scroll panes, color chooser, tabbed
pane etc.
a. True
b. False
16. Which are passive controls that do not support any interaction with the user?

a. Choice
b. List
c. Labels
d. Checkbox

17. For windows, the default layout manager is ________.

a) BorderLayout
b)FlowLayout
c)GridLayout
d)GridBagLayout

18. The SecurityManager object is responsible for implementing the security policies for applets.
a)True
b)False
19. Applets loaded from the same computer where they are executing have the same restrictions
as applets loaded from the network.

a)True
b)False

20. One of the popular uses of applets involves making connections to the host they came from.

a)True
b)False

21. An applet may not create frames (instances of java.awt.Frame class).

a)True
b)False
22. Which of the following methods can be used to remove a java.awt.Component object from
the display?

a)hide()

PRACTICALKIDA.COM
b)delete()
c)disappear()
d)move()

23. The setBackground() method is part of the following class in java.awt package:

a)Graphics
b)Container
c)Component
d)Applet

24. Panel and Dialog boxes can have menubar.

a)True
b)False

25. In the following statements which is a drawback for Applet?

a) It works at client side so less response time


b) Secured
c) It can be executed by browsers running under many platforms, including Linux, Windows,
and Mac Os etc.
d)Plugin is required at client browser to execute applet
26. The java.applet.Applet class 4 life cycle methods and java.awt.Component class provides
how many
life cycle methods for an applet?

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

27. Which life cycle method of an applet java.awt.Component class provides?

a) public void paint(Graphics g)


b) public void destroy()
c) public void stop()
d) public void init()

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

a) public void start()


b) public void paint(Graphics g)
c) Public void stop()

PRACTICALKIDA.COM
d) Public void init()

29. Which is the correct order for lifecycle of an applet?

a) Applet is intialized,started,painted,destroyed,stopped
b) Applet is painted,started,stopped,initilaized,destroyed
c) Applet is initialized,started,painted,stopped,destroyed
d) None of the above

30. To run an Applet which of these used?

a) By html file
b) By AppletViewer tool(for testing purpose)
c) Both A & B
d) None of the above

31. Java Plug-in software is not responsible to manage the lifecycle of an Applet?

a) True
b) False

32. Which Called when an applet begins execution, It is the first method called for any applet?

A) void init()
B) void destroy()
C) boolean isActive()
D) None of the above

33. When an applet begins, the AWT calls the following methods, in this sequence?

a) init(),paint(),start()
b) Start(),paint(),init()
c) intit(),start(),paint()
d) paint(),start(),init()

34. when an applet is terminated the following sequence of methods calls takes place?

a) stop(),paint(),destroy()
b) destroy(),stop(),paint()
c) destroy(),stop()
d) stop(),destroy()

35. This method is used to suspend threads that don’t need to run when the applet is not visible?

a) destroy()
b) paint()

PRACTICALKIDA.COM
c) stop()
d) start()

36. Which method is called only once during the run time of your applet?

a) stop()
b) paint()
c) init()
d) destroy()

37) The APPLET tag is used to start an applet from both an HTML document and from an applet
viewer?

A) True
B) False

38) 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
39) Applet works at client side so less response time?

a) True
b) False

40) Applet runs inside the browser and does not works at client side?

a) True
b) False

41) In Applet which are common security restrictions?

a) Applets can't load libraries or define native methods


b) An applet can't read every system property
c) Applets can play sounds
d) Both A & B

42) Which Invoked immediately after the start() method, and also any time the applet needs to
repaint itself in the browser?

PRACTICALKIDA.COM
a) stop()
b) init()
c) paint()
d) destroy()

43) An applet can play an audio file represented by the AudioClip interface in the java.applet
package. The AudioClip interface has how many methods?

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

44) An applet can play an audio file represented by the AudioClip interface in the java,applet
package Causes the audio clip to replay continually in which method?

a) public void play()


b) public void loop()
c) public void stop()
d) None of the above

45. Applets cannot make network connection exception to the server host from which it
originated?
a) True
b) False

46. The following way is used to create a frame is by creating the object of Frame class?

a) inheritance
b) association
c) Both A & B
d) None of the above
Ans : b
47. The Java Foundation Classes (JFC) is a set of GUI components which simplify the
development of desktop applications?

a) True
b) False

48. Which inheritance is not supported in java?

a) Single inheritance
b) Hybrid inheritance
c) Multilevel inheritance

PRACTICALKIDA.COM
d) Java supports all of the above

49. Which is a mechanism in which one object acquires all the properties and behaviors of parent
object?

a) Inheritance
b) Encapsulation
c) Polymorphism
d) None of the above

50. Which inheritance is not supported in java?

A) Single inheritance
B) Hybrid inheritance
C) Multilevel inheritance
D) Java supports all of the above

51. Which is a mechanism in which one object acquires all the properties and behaviors of parent
object?

a) Inheritance
b) Encapsulation
c) Polymorphism
d) None of the above
52. The following Syntax is used for?

class Subclass-name extends Superclass-name


{
//methods and fields
}

a) Polymorphism
b) Encapsulation
c) Inheritance
d) None of the above

53. If subclass (child class) has the same method as declared in the parent class, it is known as?

a) Method overriding
b) Method overloading
c) Constructor overloading
d) None of the above

54. In Method overriding a subclass in a different package can only override the non-final
methods declared public or protected?

PRACTICALKIDA.COM
a) True
b) False

55. Which allows you define one interface and have multiple implementations?

a) Encapsulation
b) Inheritance
c) Polymorphism
d) None of the above

56. Which type of polymorphism is nothing but the method overloading in java?

a) Compile time polymorphism


b) Runtime polymorphism
c) Static polymorphism
d) Both A & C

57) Which is a perfect example of runtime polymorphism?

a) Method overloading
b) Method overriding
c) Constructor overloading
d) None of the above
58) The following two rules are defined by?
1. The parameters may differ in their type or number, or in both.
2. They may have the same or different return types.

a) Method overloading
b) Method overriding
c) Constructor overloading
d) None of the above

59. Which method cannot be overridden?

a) Final Method
b) Final class
c) Final Variable
d) Both A & C

60. A final class not to be inherited?

a) True
b) False

PRACTICALKIDA.COM
61. A class which cannot be instantiated is known as?

a) Abstract Class
b) Abstract Method
c) Both A & B
d) None of the above

62. An abstract class has no use until unless it is extended by some other class?

a) True
b) False

63. Multiple inheritances is not supported in case of class but it is supported in case of interface?

a) True
b) False

64. By interface, we cannot support the functionality of multiple inheritances?

a) True
b) False

65. Which keyword is used by classes to implement an interface?


a) import
b) implements
c) instance of
d) None of the above

66. An interface is a blueprint of a class. It has static constants and abstract methods?

a) True
b) False

67. Which is a superclass of all exception classes?

a) Throwable
b) Exception
c) RuntimeException
d) IOException

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

a) Void setLayout(Layoutmanager Im)


b) void setLayout(layoutManager Im)
c) Void setLayout(LayoutManager lm)

PRACTICALKIDA.COM
d) voidsetLayout(LayoutManager Im)

69. getSelectedCheckbox() method of which class.

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

70.Which method is use to check the status of check box?

a) setState()
b) getState()
c) setLabel()
d) getLabel()

71._________arranges the component in rows and coloumn.

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

72.What is the return type of getItem()?


a)Object
b)int
c)String
d)All of these

73. Container class is subclass of Component class.

a)True
b)False

74. Container class is mainly responsible for positioning components on a window.

a)True
b)False

75. Window class is base class for two window classes 1)_____2)____.

a)Panel and Frame


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

PRACTICALKIDA.COM
76. We cannot place any component object into Window

a)True
b)False

77.For a TextArea that is 80 character-widths wide and 10 character-heights tall,which is the


correct code?

a)new TextArea(80,10)
b)new TextArea(10,80)
c)New TextArea(10,80)
d)new Textarea(80,10)

78. The CheckboxGroup class is the subclass of the Component class.

a)True
b)False

79. A Scrollbar is a ____.

a)Component
b)Container
c)Object
d)None of the above

80. A ScrollPane is a _____.

a)Component
b)object
c) Container
d) None of the above

81. Which component subclass is used for drawing and painting?

a)Repaint
b)Graphic
c)Paint
d)Canvas

82. Which method is used to set text of a Label object?


a)setText()
b)setLabel
c)setTextLabel()
d)setLabelText()

PRACTICALKIDA.COM
83. Which of the following creates a List with 5 visible items and multiple selection enabled?
a)new List(5,true)
b) new List(true,5)
c) new List(5,false)
d) new List(false,5)

84. Which method will cause Frame to be displayed?

a)show()
b)display()
c)displayFrame()
d)setVisible()

85. The Choice Component alows multiple selection.

a)True
b)False

86. The List component does not generate any events.

a)True
b)False

87. Which is the Default Layout Manager for Window and window subclasses(Frame,Dialog)?
a) CardLayout
b)FlowLayout
c)BorderLayout
d)GridLayout

89. Which method is the method to set the Layout of the Container?

a)startLayout()
b)intLayout()
c)layoutContainer()
d)setLayout()

90. Which Layout is for organizing the componets in the tabular form?

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

91. Which is the dual state MenuItem?

a)CheckboxMenuItem

PRACTICALKIDA.COM
b)MenuItem
c)MenuItemCheckbox
d)None of the above

92. CheckboxMenuItem class extends MenuItem class.

a)True
b)False

93. Window is the Container that have no borders and manu bars.

a)True
b)False

94. Java Plug-in software is responsible to manage the life cycle of an applet ?

a)True
b)False

95. The classes which directly inherit Throwable class except RuntimeException and Error are
known as checked exceptions .

a)True
b)False
96. The classes which inherit RuntimeException are known as unchecked exceptions.

a)True
b)False

97. The ____ keyword is used to declare exceptions.

a)catch
b) throws
c) throw
d)finally

98. _______is used to place important code, it will be executed whether exception is handled or
not.

a) Finalize
b) Final
c) Finally
d)None of the above

99. Java throw keyword is used to explicitly throw an exception.

PRACTICALKIDA.COM
a)True
b)False

99. JVM (Java Virtual Machine) is an abstract machine.

a)True
b)False

100. JVM is called a virtual machine because it doesn't physically exist.

a)True
b)False
101. The Java Runtime Environment is a set of software tools which are used for developing
Java applications.

a)True
b)False

102. The Java Development Kit (JDK) is a software development environment which is used to
develop Java applications and applets.

a)True
b)False
103.JDK contains JRE + development tools.

a)True
b)False

104. A local variable can be defined with "static" keyword.

a)True
b)False

105. Memory allocation for static variable happens only once when the class is loaded in the
memory.

a)True
b)False

106. If there is no constructor in a class, compiler automatically creates a default constructor.

a)True
b)False

PRACTICALKIDA.COM
107. A constructor must have a return type.

a)True
b)False

108. A method must have a return type.

a)True
b)False

109. “ this” keyword is a ______ variable that refers to the current object.

a)Private
b)Local
c) reference
d)Static

110. Interface cannot be instantiated just like the abstract class.

a)True
b)False

111. The _____ class is the parent class of all the classes in java by default.
a) Object
b) Container
c)Component
d)None of the above

112. _____package provides for system input and output through data streams, serialization and
the file system.
a) java.swing
b) java.awt
c) java.lang
d)java.io

113. Java.lang package in Java Provides classes that are fundamental to the design of the Java
programming language.

a) True
b) False

114. The _____class implements a growable array of objects.

a) Vector

PRACTICALKIDA.COM
b) Array
c)Both a) and b)
d)None of the above

115. Threads can be created by using mechanism:

a) Extending the Thread class


b) Implementing the Runnable Interface
c)Both a) and b)
d) None of the above

116.The Frame is by default invisible.

a) True
b) False

117. The TextField used for taking passwords, should be defined by calling_____.

a)setEchoChar()
b) EchoCharset()
c)setPassword()
d) passwordSet()
118.TextArea is a multiline TextField.

a)True
b)False

119.Only a Frame class can have menubar.

a)True
b)False

CHAPTER-2 (Swings) (CO1 And CO2)

Q.1 Pluggable look and feel and lightweight components are the features supported by ____.
a) Swing b) AWT
c) Core Java d) None of these
Q.2 Swing is based on ________ architecture.
a) Client server b) model view controller
c) Layered d) None of these
Q.3 Swing is not a part of JFC (Java Foundation Classes) that is used to create GUI application.

PRACTICALKIDA.COM
a) True b) False
Q.4 The Java Foundation Classes (JFC) is a set of GUI components which simplify the
development
of desktop applications
a) True b) False
Q.5 Following letter used as a prefix to swing component.
a) A b) S
c) G d) J
Q.6 _______ is one of the features of object oriented programming that allows creation of
hierarchical classifications.
a) Polymorphism b) Class
c) Inheritance d) Object
Q.7 In swing JButton class is derived from ______.
a) Abstract Button b) JToggleButton
c) JComponent d) None of these

Q.8 The JTextComponent derives two components JTextField and _______.


a) JComboBox b) JTextArea
c) JSlider d) All of the above
Q.9 In swing class hierarchy the class present at the root is ______.
a) Component b) Window
c) Container d) Object
Q.10 ________ pane can be used to add component to container.
a) Glass b) Content
c) Container d) All of above
Q.11 Select the correct source code using swing for generating following output.

PRACTICALKIDA.COM
a) b)
public class AppletDemo extends public class AppletDemo extends
JApplet JApplet
{ {
public void paint(Graphics g) public void paint(Graphics g)
{ {
g.string(“WELCOME TO SWING g.drawString(“WELCOME TO
PROGRAM ”,20,40); SWING PROGRAM ”,20,40);
} }
} }
c) d)
public class AppletDemo public class AppletDemo extends
{ JApplet
public void paint(Graphics g) {
{ public void paint(Graphics g)
g.drawString(“WELCOME TO {
SWING PROGRAM ”,20,40); g.display(“WELCOME TO
} SWING PROGRAM ”,20,40);
} }
}

Q.12 The component used to display following image are _______.


PRACTICALKIDA.COM
a) two circle, two arcs
b) three circle, one arc and one rectangle
c) Four circles
d) three circles and one arc
Q.13 To represent Icon file in swing label we use
a) setimg b) setIcon
c) setLabelIcon d) None of these
Q.14 Which of the following component allows multiple selection?
a) JList b) JComboBox
c) JLabel d) All of the above
Q.15 To generate above output we need _______.
a) List, choice,Button, ImageIcon
b) ComboBox, ImageIcon, Label
c) List and Image Icon
d) ComboBox and ImageIcon
Q.16 To generate following output the components that are used are _______.

PRACTICALKIDA.COM

a) Checkbox, Textbox b) Radiobutton, Textbox


c) Checkbox, Button d) List, Textbox

Q.17 The subclass of JToggleButton is ______.


a) JButton b) JCheckBox
c) JRadioButton d) Both b and c
Q.18 The swing component classes that are used in Encapsulates a mutually exclusive set of
buttons?
a) AbstractButton b) ButtonGroup
c) JButton d) ImageIcon
Q.19 Select the correct output generated by following code
import java.awt.*;
import java,applet.*;
/*<applet code=Test.class height=200 width=200>
</applet>*/Public class Test extends Applet
{
Public void init()
{
List l=new List(2,true);
l.add(“Java”);
l.add(“C++”);
l.add(“Python”);
add(l);
}
}

a) b)

PRACTICALKIDA.COM
c) d)

Q.20 Which method of the component class is used to set the position and size of a component.
a) setPosition b) setBounds
c) setSize d) None of these
Q.21 Select the correct option
I. Canvas is a component

PRACTICALKIDA.COM
II. ScrollPane is a container
a) I is true and II is false
c) I and II both are false
b) I is false and II is true
d) I and II both are true
Q.22 The difference between Scrollbar and Scrollpane is
a) Scrollbar is component and Scrollpane is container
b) Scrollbar is container and Scrollpane is component
c) Scrollbar and Scrollpane both are components and not containers
d) Scrollbar and Scrollpane both are containers and not components

Q.23 Frame class Extends Window.


a) True b) False
Q.24 Which is the container class?
a) Window b) Frame
c) Dialog d) All of the above
Q.25 Following is uneditable control
a) Button b) TextField
c) Label d) List

Q.26 Debug following program


import javax.swing.*;
import java.awt.*;
import javax.swing.tree.*;
/*<applet code=”TableDemo” width=300 height=100>
</applet>*/
public class TableDemo extends JApplet
{
public void init ()
{
Container contentPane=getContentPane();
contentPane.setLayout(new BorderLayout());
final String[] th={“Name”,”City”,”Salary”,”Designation”};
final Object[][] mytable={
{“Arun”,”Pune”,”5000”,”Accountant”},
{“Archana”,”Mumbai”,”7000”,”Executive”},
{“Shivani”,”Bangalore”,”10000”,”Manager”},
{“Priyanka”,”Chennai”,”8000”,”Programmer”},
{“Monika”,”Hyderabad”,”10000”,”Designer”},
{“Shilpa”,”Hyderabad”,”12000”,”Director”},
{“Anuja”,”Delhi”,”17000”,”Director”},
{“Kumar”,”Pune”,”10000”,”Manager”},
};
JTable table=new JTable(mytable);
int vscrollbar=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int hscrollbar= ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane mypane=new JScrollPane(table,vscrollbar,hscrollbar);
contentPane.add(mypane,BorderLayout.CENTER);

PRACTICALKIDA.COM
}
}
a) Error in statement in which JTable is created.
b) Error in statement in which JScrollPane is created
c) Error in statement in which applet tag is declared
d) None of these
Q.27 JPanel and Applet use _______ as their Default Layout.
a) FlowLayout b) GridLayout
c) BorderLayout d) GridBagLayout
Q.28 Which components are used to generate following output?

a) Panel, Tabbed Pane, Radio Button


b) Tabbed Pane, List
c) Tabbed Pane, Panel
d) Label, Tabbed Pane, Checkbox
Q.29 MVC stands for _______.
a) Model Version Control
b) Model View Controller
c) Mini View Controller
d) Major View Controller
Q.30 MVC architecture is used by Swing
a) True b) False
Q.31 In Swing ______ gives the visual representation of the component
a) Model b) View
c) Controller d) None of these

Q.32 In swing the event handling task is carried out by ______.


a) Model b) View
c) Controller d) None of these
Q.33 ______ represents enterprise data and the business rules that gives access to enterprise data.
a) Model b) View
c) Controller d) None of these
Q.34 A _____ is component that represents a hierarchical view of data .
a) JTable b) JTree

PRACTICALKIDA.COM
c) JMenuBar d) None of these
Q.35 We can use ______ pane to add component to container
a) contentpane b) rootpane
c) glasspane d) all
Q.36 In swing, the content pane can be obtained via method ______.
a) getContentPane b) addContentPane
c) both a&b d) None of these
Q.37 In a swing ____ is a component that display rows and columns of data.
a) table b) card
c) both a&b d) None of these
Q.38 In a swing, tables are implemented by the ______ class.
a) JPanel b) JTable
c) JTree d) None of these
Q.39 To use the swing components _____ package is imported.
a) java.awt b) java.swing
c) javax.swing d) None of these
Q.40 _____ is base class for all swing components.
a) Object b) JComponent
c) Container d) None of these
Q.41 The ______ is a fundamental swing class.
a) JApplet b)JFrame
c) JPanel d) None of these
Q.42 The JTextField is extended from _____ class.
a) JApplet b) JComponent
c) JFrame d) All of these
Q.43 JTextField has ____number of constructors.
a) 5 b) 4
c) 3 d) 2
Q.44 JCheckBox is implementation of _____ class.
a) JButton b) AbstractButton
c) JCheckBox d) None of these
Q.45 JCheckBox has _____ number of constructors.
a) 5 b) 2
c) 4 d) 3
Q.46 ______ is a component which contains group of folders.
a) TabbedPane b) JTabbedPane
c) both a&b d) None of these
Q.47 JTabbedPane class is extended by ______ class.
a) JComponent b) JApplet
c) JFrame d) None of these
Q.48 Which constructor is JComboBox class?
a) JComboBox() b) JcomboBox()
c) Both a&b d) JCombobox()
Q.49 Which method is used for add items in JComboBox?
a) add() b) addItem()
c) Both a&b d) None of these

PRACTICALKIDA.COM
Q.50 Which component is used for creating a GUI for downloading or transferring of file.
a) JLable b) JButton
c) JProgressBar d) JProgressbar
Q.51 Which panes are support to JApplet ?
a) Root Panes b) Glass Panes
c) Content Panes d) All of these
Q.52 All Swing components names start with J.
a) True b) False
Q.53 JProgressBar has _______ numbers of methods.
a) 3 b) 2
c) 4 d) 1
Q.54 You can create a tool tip for _________with setToolTipText() method.
a) JProgressBar b) JApplet
c) any JComponent d) None of these
Q.55 Which class is provide a general purpose component for implementing divider lines?
a) JProgressBar b) JComponent
c) JTable d) JSeparator
Q.56 Swing components are platform dependent.
a) False b) True
Q.57 Features of Java Foundation Classes (JFC) is:
a) Swing GUI components b) Look and Feel support
c) Java 2D d) All of these
Q.58 How many methods for ImageIcon?
a) 5 b) 1
c) 3 d) 2
Q.59 JTree has a 'root node' at the top most which is a parent for all nodes in the tree.
a) True b) False
Q.60 How many constructor for JTable?
a) 2 b) 1
c) 4 d) 5

CHAPTER-3 (Event Handling) (CO2 And CO3)

Q1. Which of these events generated when a button is pressed?


a) WindowEvent
b) ActionEvent
c) KeyEvent
d) ActionEvent

PRACTICALKIDA.COM
Q2. Method use to change the location of event?
a) getPoint()
b) translatePoint()
c) getClickCount()
d) isPopupTrigger()

Q3. Which method will be invoked if a character is entered?


a) KeyPressed()
b) KeyReleased()
c) KeyTyped()
d) KeyEntered()

Q4. Which of these is a super class of all adapter class?


a) Applet
b) Event
c) ComponentEvent
d) InputEvent

Q5. Which method used to obtain co-ordinates of a mouse?


a) getPoint()
b) GetCoordinates()
c) GetMouseXY()
d) GetMouseCoordinates()
Q6. Which of these is a super class of all ContainerEvent class?
a) WindowEvent
b) ComponentEvent
c) ItemEvent
d) InputEvent

Q7. Which of these class is super class of all events?


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

Q8. ____is a superclass of windowEvent class


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

Q9. Which of these package contains all the event handling interfaces?
a) Java.lang
b) Java.awt

PRACTICALKIDA.COM
c) Java.awt.event
d) Java.event

Q10. Name of event classes?


a) ActionEvent,ComponentEvent
b) ContainerEvent,FocusEvent
c) ItemEvent,KeyEvent
d) All of these

Q11. Event object class belongs to


a) Java.util
b) Java.awt
c) Java.lang
d) Java.sql

Q12. _____method is defined in mousemotionAdapter class


a) MouseDragged()
b) MousePressed()
c) MouseReleased()
d) MouseClicked()

Q13. Which of these constant value will change when the button at the end of scrollbar was
clicked to increase its value?
a) BLOCK_DECREMENT
b) BLOCK_INCREMENT
c) UNIT_DECREMENT
d) UNIT_INCREMENT

Q14. Which constant of window Event class makes a request for closing window?
a) WINDOW_CLOSED
b) WINDOW_CLOSING
c) WINDOW_ACTIVATED
d) WINDOW_DEACTIVATED

Q15. ScrollBar implements____


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

Q16. For which Interface method belongs to void adjustmentValueChanged(AdjustmentEvent


e)?
a) ObjectListener
b) AdjustmentListener

PRACTICALKIDA.COM
c) ActionListener
d) ComponentListener

Q17. For which class this constant belongs to BLOCK_DECREMENT and


BLOCK_INCREMENT?
a) Scrollbar
b) Menubar
c) Filedialog
d) Actionevent

Q19. Which of these events is generated when the size of component is changed?
a) ComponentEvent
b) ContainerEvent
c) FocusEvent
d) InputEvent

Q20. Which of these events is generated when the component is added or removed?
a) ComponentEvent
b) ContainerEvent
c) FocusEvent
d) InputEvent
Q21. Which of these are integer constants of ComponentEvent class?
a) COMPONENT_HIDDEN
b) COMPONENT_MOVED
c) COMPONENT_RESIZE
d) All of These

Q22. Which of these events is generated when computer gains or losses input focus?
a) ComponentEvent
b) ContainerEvent
c) FocusEvent
d) InputEvent

Q23. Base class of all AWT Event class is


a) AwtEvent
b) KeyEvent
c) ActionEvent
d) AdjustmentEvent

Q24. Which of these event generated when a button is Pressed?


a) window Event
b) ActionEvent

PRACTICALKIDA.COM
c) KeyEvent
d) MouseEvent

Q25. Which is the class responsible for handling key press activity?
a) KeyEvent
b) WindowEvent
c) ActionEvent
d) mouseEvent

Q26. Event class library is define in following package


a) java.io
b) java.util
c) java.event
d) java.object

Q27. ComponentEvent is a super class of __________


a) Container Event
b) FocusEvent
c) both a and b
d) None of these

Q28. TextEvent defines integer constant


a) TEXT_VALUE_CHANGED
b) TEXT_VALUE
c) both a and b
d) None of these

Q29. ____ is the abstract super class of all component input event class
a) KeyEvent
b) ItemEvent
c) ActionEvent
d) InputEvent

Q30. Event is called as


a) change in the state of object
b) change in the state of variable
c) ActionEvent
d) InputEvent

Q31. What is listener in context to event handling?


a) is a variable that is notified when an event occurs
b) is an object that is notified when an event occurs
c) A listener is a method that is notified when an event occurs
d) None of these

PRACTICALKIDA.COM
Q32. Event class is defined in which of these libraries
a) java.io
b) java.lang
c) java.net
d) java.util

Q33. Which of these method are used to register a keyboard event listener?
a) KeyListener()
b) ADDKeyListener()
c) addKeyListener()
d) eventKeyboardListener()

Q34. Which of these method can be used to obtain the command name for invoking actionEvent
object?
a) getCommand()
b) getActionCommand()
c) getActionEvent()
d) getActionEventCommand()

Q35. Which of these events will be generated if we close an applet's window?


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

Q36. Which of these integer constants defines in ActionEvent class?


a) ALT_MASK
b) CTRL_MASK
c) SHIFT_MASK
d) All of these

Q37. Which of these method can be used to determine the type of event?
a) getID()
b) getSource()
c) getEvent()
d) getEventObject()

Q38. Which of these class is super class of all the events?


a) EventObject
b) EventClass
c) ActionEvent

PRACTICALKIDA.COM
d) ItemEvent

Q39. Which of these method can be used to know the degree of adjustment made by the user?
a) getValue()
b) getAdjustmentType()
c) getAdjustmentValue()
d) getAdjustmentAmount()

Q40. Which of these methods can be used to determine the type of adjustment event?
a) getType()
b) getEventType()
c) getAdjustmentType()
d) getObjectEventType()

Q41. Which of these methods can be used to obtain the reference to the container that generated
a containerEvent?
a) getContainer()
b) getContainerCommand()
c) getActionEvent()
d) getContainerEvent()

Q42. Which of these constant value will change when the button at the end of scrollbar was
clicked to increase its value?
a) BLOCK_DECREMENT
b) BLOCK_INCREMENT
c) UNIT_DECREMENT
d) UNIT_INCREMENT

Q43. Which of these methods can be used to know which key is pressed?
a) getKey()
b) getModifier()
c) getActionKey()
d) getActionEvent()

Q44. Which of these methods can be used to obtain the coordinates of a mouse?
a) getPoint()
b) getCoordinates()
c) GetMouseXY()
d) getMouseCoordinates()

Q45. Which of these is superclass of container Event class?


a) windowEvent
b) ComponentEvent

PRACTICALKIDA.COM
c) ItemEvent
d) InputEvent

Q46. Which of these events is generated when computer gains or loses input focus?
a) ComponentEvent
b) ContainerEvent
c) FocusEvent
d) InputEvent

Q47. Which of these methods will respond when you click any button by mouse?
a) mouseClicked()
b) mouseReleased()
c) mousePressed()
d) All of these

Q48. Which of these interfaces defines a method actionPerformed()?


a) ComponentListener
b) ContainerListener
c) ActionListener
d) InputListener

Q49. Which of these is superclass of all adapter classes?


a) Applet
b) ComponentEvent
c) Event
d) InputEvent

Q50. Which of these methods will beinvoked if a character is entered?


a) keyPressed()
b) keyReleased()
c) keyTyped()
d) keyEntered()

Q51. ____method are used to register a mousemotion listener


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

Q52. ___is super class of all the events.


a) EventObject
b) EventClass
c) ActionEvent

PRACTICALKIDA.COM
d) ItemEvent

Q53. If scrollbar is manipulated ____ event will be notified.


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

Q54. which of these events is generated when a button is pressed?


a) ActionEvent
b) KeyEvent
c) windowEvent
d) Adjustmentevent

Q55. ____method can be used to determine the type of adjustment event.


a) getType()
b) getEventType()
c) getAdjustmentType()
d) getEventObjectType()

Q56. When the size of component is changed, ____ event is generated.


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

Q57. When the component is added or removed, which of these events is generated.
a) ComponentEvent
b) containerEvent
c) FocusEvent
d) InputEvent

Q58. ____method can be used to obtain the reference to the container that generated a container.
a) getContainer()
b) getcontainerCommand()
c) getActionEvent()
d) getContainerEvent()

Q58. which of the following method can be used to get reference to a component that was
affected by the container?
a) getcomponent()
b) getChild()

PRACTICALKIDA.COM
c) getcontainercomponent()
d) getcomponentChild()

Q59. ____event is generated when computer gains or losses input focus.


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

Q60. FocusEvent is a subclass of _____ classes.


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

Q61. ___can be used to know the type of focus change.


a) typeFocus()
b) typeEventFocus()
c) isTemporary()
d) isPermanent()

Q62. ___method can be used to change location of an event.


a) ChangePoint()
b) translatePoint()
c) ChangeCoordinates()
d) TranslateCoordinates()

Q63. Which of the following is integer constant of TextEvent class?


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

Q64. ___is used to obtain the object that generated a windowEvent.


a) getMethod()
b) getWindow()
c) getWindowEvent()
d) getWindowObject()

Q65. MouseEvent is subclass of___classes.


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

PRACTICALKIDA.COM
Q66. ___method is used to get X coordinates of the mouse.
a) getX()
b) getXCoordinate()
c) getCoordinateX()
d) getPointX()

Q67. which of these are constants defined in windowEvent class?


a) WINDOW_ACTIVATED
b) WINDOW_CLOSED
c) WINDOW_DEICONIFIED
d) All of these

Q68. ___is superclass of windowEvent class.


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

Q69. Which of the following interface define 4 Methods?


a) ComponentListener
b) ContainerListener
c) ActionListener
d) InputListener

Q70. Which methods will respond when you click any button by mouse?
a) mouseClicked()
b) mouseEntered()
c) mousePressed()
d) All of these

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

Q72. Which of these methods can be used to determine the type of event?
a) getID()
b) getSource()
c) getEvent()

PRACTICALKIDA.COM
d) getEventObject()

Ans:A
Q73. Which of these events will be notified if scroll bar is manipulated?
a) ActionEvent
b) ComponentEvent
c) AdjustmentEvent
d) WindowEvent

Q74. Which of these event is generated when a button is pressed?


a) ActionEvent
b) keyEvent
c) windowEvent
d) AdjustmentEvent

Q75. What is an event delegation model used by Java programming languages?


a) An event is an object that describe a state change in a source.
b) An event is an object that describe a state change in a processing.
c) An event is an object that describe a any changes by the user and system
d) An event is a class used for defining object, to create events.

Q76. Which of these methods can be used to obtain the command name for invoking
ActionEvent object?
a) getCommand()
b) getActionCommand()
c) getActionEvent()
d) getActionEventCommand()

Q77. Which of these event is generated by scroll bar?


a) ActionEvent
b) keyEvent
c) windowEvent
d) AdjustmentEvent

Q78. Which of these packages contains all the event handling interfaces?
a) java.lang
b) java.awt
c) java.awt.event
d) java.event

Q79. Which of these interfaces handles the event when a component is added to a container?
a) ComponentListener
b) containerListener
c) FocusListener

PRACTICALKIDA.COM
d) InputListener

Q80. Which of these interfaces defines four methods?


a) ComponentListener
b) containerListener
c) FocusListener
d) InputListener

Q81. Which of these interfaces defines a method itemStateChanged()?


a) ComponentListener
b) containerListener
c) FocusListener
d) InputListener

Q82. Which of these methods is defined in MouseMotionAdapter class?


a) mouseDragged()
b) mousePressed()
c) mouseReleased()
d) mouseClicked()

Q83. Which of these are integer constants defined in ActionEvent class?


a) ALT_MASK
b) CTRL_MASK
c) SHIFT_MASK
d) All of these

Q84. Which of these methods can be used to know the degree of adjustment made by the user?

a) getValue()
b) getAdjustmentType()
c) getAdjustmentValue()
d) getAdjustmentAmount()

Q85. Which of these events is generated when the size of an event is changed?
a) ComponentEvent
b) ContainerEvent
c) FocusEvent
d) InputEvent

Q86. Which of these events is generated when the component is added or removed?
a) ComponentEvent
b) ContainerEvent
c) FocusEvent

PRACTICALKIDA.COM
d) InputEvent

Q87. Which of these methods can be used to get reference to a component that was removed
from a container?
a) getcomponent()
b) getChild()
c) getcontainercomponent()
d) getcomponentChild()

Q88. Which of these are integer constants of ComponentEvent class?


a) COMPONENT_HIDDEN
b) COMPONENT_MOVED
c) COMPONENT_RESIZE
d) All of these

Q89. Which of these events is generatd when computer gains or losses input focus?
a) ComponentEvent
b) ContainerEvent
c) FocusEvent
d) InputEvent

Q90. Which of these event is generated when window is closed?


a) TextEvent
b) MouseEvent
c) FocusEvent
d) WindowEvent

Q91. which of these methods can be used to change location of an event?


a) ChangePoint()
b) translatePoint()
c) ChangeCoordinates()
d) TranslateCoordinates()

Q92. Interface used to handle menu event is


a) ActionListener
b) ItemListener
c) ComponentListener
d) ContainerListener

Q93. The Key Event class doen not define _______ integer constant
a) KEY_RELEASED
b) KEY_PRESSED
c) KEY_TYPED
d) KEY_ENTERED

PRACTICALKIDA.COM
Q94. _____ is the abstract super class of all component input event class.
a) FocusEvent
b) InputEvent
c) ComponentEvent
d) Containerevent

Q95. FocusEvent are fired whenever a component _____ the focus


a) add or remove
b) gain or loses
c) both a and b
d) none of these

Q96. If a class extends ActionListener interface, it must contain a method called ______
a) actionPerformed
b) itemStateChanged
c) both a and b
d) None of these

Q97. Which of these Listener handles all List related Events?


a) ComponentListener
b) ContainerListener
c) ItemListener
d) ActionListener

Q98. Which of the following statements registers a panel object p as a listener for a button
variable jbt?
a) addActionListener(p)
b) jbt.addActionListener(p)
c) jbt.addEventActionListener(p)
d) jbt.EventListener(p)

Q99. Action event is applied on


a) Button, textFiel, text , menu
b) Button,TextField,Label
c) Button, Menu
d) TextField,Menu

Q100. Which method is used to processes mouse click?


a) Mouse_CLICKED()
b) Mouse_Dragged()
c) Mouse_Moved()

PRACTICALKIDA.COM
d) All of these

Q101. Which of these methods can be used to determine the type of event?
a) getID()
b) getSource()
c) getEvent()
d) getEventObject()

Q102. Which of the following is not one of the seven methods for handling window events?
a) windowOpening
b) WindowActivated
c) WindowIconified
d) WindowClosed

Q103. Which of these method will respond when you click any button by mouse?
a) mouseDragged()
b) mousePressed()
c) mouseEntered()
d) All of these

Q104. Adapter classes are similar to EventListener interfaces.


a) True
b) False

Q105.Where can the event handling code be written?


a) Same class
b) Other class
c) Anonymous class
d) All mentioned above

Q106. Complete the following code


Public class Button1 extends Applet
Implements…………..
{
Button button=new Button(‘Change the color’);
Boolean flag=true;
Public void init()
{
add(button);
button.addActionListener(this);
}
Public void paint(Graphics g)
{
If(flag)

PRACTICALKIDA.COM
setBackground(Color.yellow);
else
setBackground(Color.red);
}
Public void actionPerformed(ActionEvent e)
{
String str=e.getActionCommand();
If(str.equals(“change the color”))
{
Flag=flag;
//toggle the flag values on every click of button
Repaint();
}
}
}

a) ActionListener
b) ItemListener
c) MouseListener
d) None of these

Q107. What method is used to distinguish b/w single, double, triple mouse clicks?
a) getButton( )
b) getPoint( )
c) getClickCount( )
d) getX( )
Q108. The getNewState( ) method belongs to______.
a) TextEvent Class
b) MouseEvent Class
c) WindowEvent Class
d) KeyEvent Class

Q109. Which of the following is the highest class in the event-delegation model?
a) Java.until.EventListener
b) Java.until.EventObject
c) Java.awt.AWTEvent
d) Java.awt.event.AWTEvent

Q110. When two or moreobjects are added as listeners for the same event, which listener is first
invoked to handle the event?
a) The first object that was added as listener
b) The last object that was added as listener
c) There is no way to determine which listener will be invoked first
d) It is impossible to have more than one listener for a given event.

/* PRACTICALKIDA.COM
Q111. Consider following code and fill up the correct event listener method

<applet code=”checkgroup” width=300 height=300>


</applet>
*/
Public class checkgroup extends Applet implements ItemListener
{
String msg=” “;
CheckboxGroup gr=new CheckboxGroup();
Checkbox box1=new Checkbox(“Candy”,gr,true);
Checkbox box2=new Checkbox(“Ice-cream”,gr,false);
Checkbox box3=new Checkbox(“Juice”,gr,false);
Public void init()
{
Add(box1);
Add(box2);
Add(box3);
Box1.addItemListener(this);
Box2.addItemListener(this);
Box3.addItemListener(this);
}
Public void________
{
Repaint();
}
Public void paint(Graphics g)
{
Msg=”I like”;
Msg+ =gr.getSelectedCheckbox().getLable();
g.drawString(msg,10,100);
}
}
a) actionPerformed(ActionEvent e)
b) itemStateChanged(ItemEvent e)
c) action(Event e,Object o)
d) textValueChanged(TextEvent e);

PRACTICALKIDA.COM
.

PRACTICALKIDA.COM
IMP SET 2
Program : - Computer Engineering Group Program Code:- CM/IF
Course Title: -Advanced Java Programming Semester: - Fifth

Course Abbr &Code:-AJP (22517) Scheme : I

-----------------------------------------------------------------------------------------------

CHAPTER-4:( Networking Basics) (CO4)

Q. 1 A set of rules that governs data communication:


(a) Protocols (b) Standards
(c) RFCs (d) Functions
Q. 2 Which of this class is used to create servers that listen for either local or remote client
programs?
(a) HttpServer (b) MimeHeader
(c) HttpResponse (d) ServerSockets

PRACTICALKIDA.COM
Q. 3 A _______is a program providing services to the _____ program.
(a) Server, Client (b) Client, Server
(d) Host, Client (c) Server, Server
Q. 4 _................server can process multiple requests at a time.
(a) An iterative
(b) A concurrent
(c) A concurrent or an iterative
(d) None of these

Q.5 Network programming needs information to be in the form of ---------_byte order.


(a) host (b) network
(c) client (d) server

Q. 6 Communication using TCP protodcol is ------

(a) connectionless, iterative


(b) connectionless, concurrent
(c) connection-oriented, iterative
(d) connection-oriented, concurrent

Q. 7 Communication using UDP protocol is -------and---------.


(a) connectionless, iterative
(b) connectionless, concurrent
(c) connection-oriented, iterative
(d) connection-oriented, concurrent
Q. 8 -------- is a server that is mediator between real web server
and client application.
(a) Host (b) H'ITP
(c) Proxy (d) Web
Q. 9 SOCK_STREAM sockets are used by --------- processes.
(a) TCP (b) UDP
(c) SCTP (d) FTP
Q. 10 SOCK_DGRAM sockets are used by ---------- processes.
(a) TCP (b) UDP
(c) SCTP (d) FTP
Q. 11 Which package contains classes and interfaces for
networking?
(a) java.io (b) java.util
(c) java.net (d) java.network
Q. 12 Port number of Telnet is __ .
(a) 21 (b) 23

PRACTICALKIDA.COM
(d) 79 (c) 25
Q. 13 java.net package consist of interface __ .
(a) ContentHandler Factory.
(b) SocketImplfactory
(c) SocketOption
(d) All of above
Q.14 __ is a protocol for breaking and sending packets to an
address across a network?
(a) TCIPIIP
(c) Socket
Q.15 Full form ofDNS is
(a) Data Network Service
(b) Data Name Service
(c) Domain Network Service
(d) Domain Name System
Q. 16 TCP is -------- oriented protocol.
(a) stream (b) message
(c) block (d) segment
Q.17 What is the output of this program?
1. importjava.net.*;
2. class networking {
3. publicstaticvoid main(String[]args)throwsUnknownHostException{
4. InetAddress obj1 =InetAddress.getByName("sanfoundary.com");
5. InetAddress obj2 =InetAddress.getByName("sanfoundary.com");
6. boolean x = obj1.equals(obj2);
7. System.out.print(x);
8. }
9. }

a) 0
b) 1
c) true
d) false

Q.18 What is the output of this program?

1. importjava.net.*;

PRACTICALKIDA.COM
2. class networking {
3. publicstaticvoid main(String[]args)throwsUnknownHostException{
4. InetAddress obj1 =InetAddress.getByName("cisco.com");
5. InetAddress obj2 =InetAddress.getByName("sanfoundary.com");
6. boolean x = obj1.equals(obj2);
7. System.out.print(x);
8. }
9. }

a) 0
b) 1
c) true
d) false

Q.19. What is the output of this program?

1. Import java.net.*;
2. class networking {
3. public static void main(String[]args) throwsUnknownHostException{
4. InetAddress obj1 =InetAddress.getByName("cisco.com");
5. System.out.print(obj1.getHostName());
6. }
7. }

a) cisco
b) cisco.com
c) www.cisco.com
d) None of the mentioned

Q.20. What is the output of this program?

1. importjava.net.*;
2. class networking {
3. publicstaticvoid main(String[]args)throwsException{
4. URLobj=newURL("http://www.sanfoundry.com/javamcq");
5. URLConnection obj1 =obj.openConnection();
6. System.out.print(obj1.getContentType());
7. }

PRACTICALKIDA.COM
8. }

Note: Host URL is written in html and simple text.


a) html
b) text
c) html/text
d) text/html

Q.21. What is the output of this program?

1. importjava.net.*;
2. class networking {
3. publicstaticvoid main(String[]args)throwsMalformedURLException{
4. URLobj=newURL("http://www.sanfoundry.com/javamcq");
5. System.out.print(obj.toExternalForm());
6. }
7. }

a) sanfoundry
b) sanfoundry.com
c) www.sanfoundry.com
d) http://www.sanfoundry.com/javamcq

Q.22.What is the output of this program?

1. importjava.net.*;
2. class networking {
3. publicstaticvoid main(String[]args)throwsMalformedURLException{
4. URLobj=newURL("http://www.sanfoundry.com/javamcq");
5. System.out.print(obj.getProtocol());
6. }
7. }

a) http
b) https
c) www
d) com

PRACTICALKIDA.COM
Q.23. What is the output of this program?

1. importjava.net.*;
2. class networking {
3. publicstaticvoid main(String[]args)throwsMalformedURLException{
4. URLobj=newURL("http://www.sanfoundry.com/javamcq");
5. System.out.print(obj.getPort());
6. }
7. }

a) 1
b) 0
c) -1
d) garbage value

Q. 24 Exception is thrown by URL class's constructors is __ .


(a) URLNotFound
(b) URLSourceNotFound
(c) MalformedURLException
(d) URLException
Q. 25 Which method is used to know the full URL of an URL object?
(a) fullHostURLO (b) getHostURLO
(c) ExternalFormO (d) toExternalFormO
Ans.: (d)

Q. 26 Which class is used to access actual bits or content


information of a URL ?
(a) URL
(c) URLConnection
(b) URLDecoder
(d) All of the mentioned

Q. 27 __ thrown to indicate that the IP address of a host could


not be determined.
(a) UnknownHostException (b) IOException
(c) HostNotFoundException (d) None of these
Q. 28 What are the types offactory pattern ?
(a) Factory Method (b) Abstract Method
(c) All ofthe above (d) None ofthe above
Ans.: (c)

PRACTICALKIDA.COM
Q. 29 Which class have only one instance?
(a) Adaptor Class (b) Singleton Class

(c) Factory class ·.1(d) Proxy Class
Q. 30 A __ variable is shared by all instances of the class. It
exists even before an object is created.
(a) abstract (b) instance
(c) interface (d) static
Q. 31 __ is wrapper around everything associated with a
reply from an http server?
(a) HTTP (b) HttpResponse
(c) Httpserver (d) httpserver
Q. 32 __ is a bundle of information passed between machines.
(a) Protocol (b) Cache
(c) Datagrams (d) Segment
Q. 33 __ class is necessary to implement datagrams.
(a) DatagramPacket (b) DatagramSocket
(c) Datagram d) Both (a) and (b)

Q. 34 __ method of DatagramPacket is used to find the port


number.
(a) portO
(c) GetPortO
(b) getPortO
(d) findPortO
Q. 35 Which of these tranfer protocol must be used so that URL
can be accessed by URLConnectionclass object?
(a) http (b) https
(c) URL (d) None of the mentioned
Q.36 ………………method is used to know when URL is last modified.
(a) LastModifiedO
(c) getlastModifiedO
(b) getLastModifiedO
(d) GetLastModifiedO
Q. 37 __ method is used to know the type of content used in
theURL.
(a) ContenttypeO (b) contentTypeO
(c) getContentTypeO (d) GetContentTypeO
Q. 38 Which package is used for handling security related issues

PRACTICALKIDA.COM
in a program ?
(a) java.security (b) java.lang.security
(c) java.awt.image (d) java.io.security
Q. 39 Class which allows us to get real time data about private
and protected member of a class is __ .
(a) java.io.security
(b) java.GetInformation
(c) ReflectPermission
(d) MembersPermission
Q. 40 The packages contain classes and interfaces used for input
and output operations of a program is __ .
(a) java.util (b) java.lang
(c) java.io (d) java.file.io
Q. 41 __ class is not a member class of java.io package.
(a) File (b) StringReader
(c) Writer (d) String

Q. 48 To return the currently installed policy object __


method is used.
(a) public Policy getPolicyO
(b) public static Policy GetPolicyO
(c) public Policy getPolicyO
(d) public static Policy getPolicyO

Q.49 A _____ is responsible for determining whether code


executing in the Java runtime environment has permission
to perform a security-sensitive operation.
(a) security object (b) security class
(c) policy object (d) policy method
Q.50 Permission class is a part of _____ package.
(a) java.security
(b) java.lang.Object
(c) java.permission.security
(d) java.security.Permission
Q. 51 Which of following are sub classes of permission class?
(a) AlIPermission (b) FilePermission
(c) ServicePermission (d) All ofthe above

Q.52 What is the output of this program?

1.
2.
PRACTICALKIDA.COM
importjava.net.*;
class networking {
3. publicstaticvoid main(String[]args)throwsMalformedURLException{
4. URLobj=newURL("http://www.sanfoundry.com/javamcq");
5. System.out.print(obj.getHost());
6. }
7. }

a) sanfoundry
b) sanfoundry.com
c) www.sanfoundry.com
d) http://www.sanfoundry.com/javamcq

Q53.What is the output of this program?

1. importjava.net.*;
2. class networking {
3. publicstaticvoid main(String[]args)throwsMalformedURLException{
4. URLobj=newURL(“http://www.sanfoundry.com/javamcq”);
5. System.out.print(obj.toExternalForm());
6. }
7. }

a) sanfoundry
b) sanfoundry.com
c) www.sanfoundry.com
d) http://www.sanfoundry.com/javamcq

Q54. RMI stands for?


a) Remote Mail Invocation
b) Remote Message Invocation
c) Remaining Method Invocation
d) Remote Method Invocation

Q55. A remote object is an object whose method can be invoked from another virtual
environment.
a) True
b) False

PRACTICALKIDA.COM
Q56. A typical _________ program creates some remote objects, makes references to these
objects accessible, and waits for clients to invoke methods on these objects.
a) Server
b) Client
c) Thread
d) Concurrent

Q57. A typical __________ program obtains a remote reference to one or more remote objects
on a server and then invokes methods on them.
a) Server
b) Client
c) Thread
d) Concurrent

Q58. The ___________ layer, which provides the interface that client and server application
objects use to interact with each other.
a) Increasing
b) Count
c) Bit
d) Stub/skeleton

Q59. A layer which is the binary data protocol layer.


a) stub layer
b) skeleton layer
c) remote layer
d) transport protocol

Q60.A middleware layer between the stub skeleton and transport.


a) remote layer
b) instruction layer
c) reference layer
d) remote reference layer

Q61. An object acting as a gateway for the client side.


a) skeleton

PRACTICALKIDA.COM
b) stub
c) remote
d) server

Q62. A gateway for the server side object.


a) skeleton
b) stub
c) remote
d) server

Q63. RMI uses stub and skeleton for communication with the ________ object.
a) client
b) remote
c) server
d) any

Q64. Which of these interface abstracts the output of messages from httpd?
a) LogMessage
b) LogResponse
c) Httpdserver
d) httpdResponse

Q65. Which of these class is used to create servers that listen for either local or remote client
programs?
a) httpServer
b) ServerSockets
c) MimeHeader
d) HttpResponse

Q66. Which of these is a standard for communicating multimedia content over email?
a) http
b) https
c) Mime
d) httpd

Q67. Which of these methods is used to make raw MIME formatted string?
a) parse()
b) toString()

PRACTICALKIDA.COM
c) getString()
d) parseString()

Q68. Which of these class is used for operating on request from the client to the server?
a) http
b) httpDecoder
c) httpConnection
d) httpd

Q69. Which of these method of MimeHeader is used to return the string equivalent of the values
stores on MimeHeader?
a) string()
b) toString()
c) convertString()
d) getString()

Q70. Which of these is an instance variable of class httpd?


a) port
b) cache
c) log
d) All of the mentioned

Q71. Which of these methods of httpd class is used to read data from the stream?
a) getDta()
b) GetResponse()
c) getStream()
d) getRawRequest()

Q72. Which of these method of httpd class is used to get report on each hit to HTTP server?
a) log()
b) logEntry()
c) logHttpd()
d) logResponse()

Q73. Which of these methods are used to find a URL from the cache of httpd?
a) findfromCache()
b) findFromCache()
c) serveFromCache()

PRACTICALKIDA.COM
d) getFromCache()

Q74. Which of these variables stores the number of hits that are successfully served out of
cache?
a) hits
b) hitstocache
c) hits_to_cache
d) hits.to.cache

Q75. Which of these method of httpd class is used to write UrlCacheEntry object into local disk?
a) writeDiskCache()
b) writetoDisk()
c) writeCache()
d) writeDiskEntry()

Q76. Which of these method is used to start a server thread?


a) run()
b) start()
c) runThread()
d) startThread()
Q77. Which of these method is called when http daemon is acting like a normal web server?
a) Handle()
b) HandleGet()
c) handleGet()
d) Handleget()

Q78. What does URL stands for?


a) Uniform Resource Locator
b) Uniform Resource Latch
c) Universal Resource Locator
d) Universal Resource Latch

Q79. Which of these exceptions is thrown by URL class’s constructors?


a) URLNotFound
b) URLSourceNotFound
c) MalformedURLException
d) URLNotFoundException

Q80. Which of these methods is used to know host of an URL?

PRACTICALKIDA.COM
a) host()
b) getHost()
c) GetHost()
d) gethost()

Q81. Which of these methods is used to know the full URL of an URL object?
a) fullHost()
b) getHost()
c) ExternalForm()
d) toExternalForm()

Q82. Which of these class is used to access actual bits or content information of a URL?
a) URL
b) URLDecoder
c) URLConnection
d) All of the mentioned

Q83. Which of these is a wrapper around everything associated with a reply from an http server?
a) HTTP
b) HttpResponse
c) HttpRequest
d) httpserver

Q84. Which of these transfer protocol must be used so that URL can be accessed by
URLConnection class object?
a) http
b) https
c) Any Protocol can be used
d) None of the mentioned

Q85. Which of these methods is used to know when was the URL last modified?
a) LastModified()
b) getLastModified()
c) GetLastModified()
d) getlastModified()

Q86. Which of these methods is used to know the type of content used in the URL?
a) ContentType()
b) contentType()

PRACTICALKIDA.COM
c) getContentType()
d) GetContentType()

Q87. Which of these data member of HttpResponse class is used to store the response from an
http server?
a) status
b) address
c) statusResponse
d) statusCode

Q88. Which of these is a bundle of information passed between machines?


a) Mime
b) Cache
c) Datagrams
d) DatagramSocket

Q89. Which of these class is necessary to implement datagrams?


a) DatagramPacket
b) DatagramSocket
c) All of the mentioned
d) None of the mentioned

Q90. Which of these method of DatagramPacket is used to find the port number?
a) port()
b) getPort()
c) findPort()
d) recievePort()

Q91. Which of these method of DatagramPacket is used to obtain the byte array of data
contained in a datagram?
a) getData()
b) getBytes()
c) getArray()
d) recieveBytes()

Q92. Which of these methods of DatagramPacket is used to find the length of byte array?
a) getnumber()
b) length()

PRACTICALKIDA.COM
c) Length()
d) getLength()

Q93. Which of these class must be used to send a datagram packets over a connection?
a) InetAdress
b) DatagramPacket
c) DatagramSocket
d) All of the mentioned

Q94. Which of these method of DatagramPacket class is used to find the destination address?
a) findAddress()
b) getAddress()
c) Address()
d) whois()

Q95. Which of these is a return type of getAddress() method of DatagramPacket class?


a) DatagramPacket
b) DatagramSocket
c) InetAddress
d) ServerSocket
Q96. Which API gets the SocketAddress (usually IP address + port number) of the remote host
that this packet is being sent to or is coming from.
a) getSocketAddress()
b) getAddress()
c) address()
d) none of the mentioned

Q97.How does applet and servlet communicate?


a) HTTP
b) HTTPS
c) FTP
d) HTTP Tunneling

Q98. In CGI, process starts with each request and will initiate OS level process.
a) True
b) False

Q99. Which class provides system independent server side implementation?


a) Socket

PRACTICALKIDA.COM
b) ServerSocket
c) Server
d) ServerReader

Q100. What happens if ServerSocket is not able to listen on the specified port?
a) The system exits gracefully with appropriate message
b) The system will wait till port is free
c) IOException is thrown when opening the socket
d) PortOccupiedException is thrown

Q101. What does bind() method of ServerSocket offer?


a) binds the serversocket to a specific address (IP Address and port)
b) binds the server and client browser
c) binds the server socket to the JVM
d) binds the port to the JVM

Q102. Which of the below are common network protocols?


a) TCP
b) UDP
c) TCP and UDP
d) CNP

Q103. Which class represents an Internet Protocol address?


a) InetAddress
b) Address
c) IP Address
d) TCP Address

Q104. What does local IP address start with?


a) 10.X.X.X
b) 172.X.X.X
c) 192.168.X.X
d) 10.X.X.X, 172.X.X.X, or 192.168.X.X

Q105. What happens if IP Address of host cannot be determined?


a) The system exit with no message
b) UnknownHostException is thrown
c) IOException is thrown

PRACTICALKIDA.COM
d) Temporary IP Address is assigned

Q106. What is the java method for ping?


a) hostReachable()
b) ping()
c) isReachable()
d) portBusy()

CHAPTER-5 : (Interacting with Database) (CO5)


Q.1 JDBC stands for___.

(a) Java Database Connectivity b)Java Database Control


(c)Java Database Components (d) None of these

Q.2 Which statements about JDBC are true ?

(a) JDBC is an API to connect to relational-, object and XML data sources.
(b) JDBC stands for Java DataBase connectivity.
(c) JDBC is an API to access relational databases, spreadsheets and flat files.
(d) JDBC is an API to bridge the object-relational mismatch between OO programs and
relational databases.

Q.3 Which packages contain the JDBC classes ?

(a) java.jdbc and javax.jdbc (b) java.jdbc and java.jdbc.sql


(c) java.sql and javax.sql (d) java.rdb and javax.rdb

Q.4 JDBC technology-based drivers generally fit into how many categories?

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

PRACTICALKIDA.COM
Q.5 Which type of driver provides JDBC access via one or more ODBC drivers?
(a) Type 1 driver (b) Type 2 driver
(c) Type 3 driver (d) Type 4 driver

Q.6 Which type of driver converts JDBC calls into the network protocol used by the database
management system directly?

(a) Type 1 driver (b) Type 2 driver


(c) Type 3 driver (d) Type 4 driver

Q.7 Which type of driver of JDBC is called pure driver?

(a) Type 1 driver (b) Type 2 driver


(c) Type 3 driver (d) Type 4 driver

Q.8 Which type of driver of JDBC is called partly Java Driver?


(a) Type 1 driver (b) Type 2 driver
(c) Type 3 driver (d) Type 4 driver

Q.9 Which driver is efficient and always preferable for using JDBC applications?
(a) Type 1 driver (b) Type 2 driver
(c) Type 3 driver (d) Type 4 driver

Q.10 The JDBC-ODBC bridge is_____.

(a) three tiered (b) multithreaded


(c) best for any platform (d) all of the above

Q.11 Which driver is called as thin-driver in JDBC?

(a) Type-4 driver (b) Type-1 driver


(c) Type-3 driver (d) Type-2 driver

Q.12 Which driver type of JDBC is used in either applet or servlet?

(a) Type 1 and 2 (b) Type 1 and 3


(c) Type 3 and 4. (d) Type 4 only

Q.13 Which of the following is false as far as type 4 driver is concern?

(a) Type 4 driver is "native protocol, pure java” driver

PRACTICALKIDA.COM
(b) Type 4 drivers are 100 % Java compatible
(c) Type 4 drivers uses socket class to connect to the database.
(d) Type 4 drivers can not be used with Netscape.

Q.14 Which of the following JDBC drivers is known as a partially java driver ?

(a) JOBC-ODBC bridge driver (b) Native-API driver


(c) Network protocol driver (d) Thin driver

Q.15 Which class has strong support of the JDBC architecture ?

(a) The JDBC driver manager (b) The JDBC driver test suite
(c) The JDBC-ODBC bridge (d) All of these

Q.16 In order to transfer data between a database and an application written in the Java
programming language, the JDBC API provides which of these methods?

(a) Methods on the ResultSet class for retrieving SQL SELECT results as Java types.
(b) Methods on the PreparedStatement class for sending Java types as SQL statement parameters.
(c) Methods on the CallableStatement class for retrieving SQL OUT parameters as Java types
(d) All of these.

Q.17 The JDBC API has always supported persistent storage of objects defined in the Java
programming language through the methods getObject and setObject.
(a)True (b) False

Q.18 What is, in terms of JDBC, a DataSource?

(a) A DataSource is the basic service for managing a set of JDBC drivers.
(b) A DataSource is the Java representation of a physical data source.
(c) A DataSource is a registry point for JNDI- services.
(d) A DataSource is a factory of connections to a physical data source.

Q.19 Which of the following describes the correct sequence of the steps involved in making
connection with a database.

1. Loading the driver.


2. Process the results.
3. Making the connection with the database.
4. Executing the SQL statements.
(a) 1,3,4,2 (b) 1,2,3,4
(c) 2,1,3,4 (d) 4,1,2,3

Q.20 Which of the following methods are needed for loading a database driver in JDBC?

PRACTICALKIDA.COM
(a) registerDriver() method (b) Class.forName0
(c) Both a and b (d) getConnection()

Q.21 Which type of statement can execute parameterized queries?

(a) PreparedStatement (b)ParameterizedStatement


(c)CallableStatement (d) All of these

Q.22 What is used to execute parameterized query ?

(a) Statement interface (b) PreparedStatement interface


(c)ResultSet interface (d) None of the above

Q.23 Which of the following encapsulates an SQL statement which is passed to the database to
be parsed, compiled, planned and executed?

(a) DriverManager (b) DBC driver


(c) Connection (d) Statement

Q.24 Which of the following is used to call a stored procedure ?

(a) Statement (b) PreparedStatement


(c) CallableStatmet (d) CalledStatement
Q.25 What happens if you call deleteRow on ResultSet object ?

(a) The row you are positioned on is deleted from the ResultSet, but not from
the database.
(b) The row you are positioned on is deleted from the ResultSet and from the database.
(c) The result depends on whether the property synchronizeWithDataSource is set to true or
false.
(d) You will get a compile error : The method does not exist because you can not delete rows
from a ResultSet.

Q.26 The JDBC-ODBC bridge supports multiple concurrent open statements per connection?

(a) True (b) False

Q.27 All raw data types (for instance-data for images) should be read and uploaded to the
database as an array of_____.

(a) byte (b) int


(c) boolean (d) char

Q.28 Are prepared statements actually compiled?

PRACTICALKIDA.COM
(a) Yes, they compiled
(b) No, they are bound by the JDBC driver

Q.29 When the message "No Suitable Driver” occurs?


(a) When the driver is not registered by Class.forname() method.
(b) When the user name, password and the database does not match.
(c) When the JDBC database URL passed is not constructed properly
(d) When the type 4 driver is used

Q.30 Database system compiles query when it is____.

(a) executed (b) initialized


(c) prepared (d) invoked

Q.31 ______ is an open source DBMS product that runs in window as well as Linux.

(a) JSP/SQL (b) MySQL


(c) Microsoft Access (d) SOL Server

Q.32 To execute a statement, we invoke method _______.

(a) executeUpdate method (b) executeRel method


(c) executeStmt method (d) executeConn method
Q.33 Method on resultset that tests whether or not there remains at least one unfetched tuple in
result set, is said to be_____.

(a) fetch method (b) current method


(c) next method (d) access method

Q.34 The ResultSet.next method is used to move to the next row of the ResultSet, making it the
current row.

(a) True (b) False

Q.35 ResultSet object can be moved forward only and it is updatable.

(a) True (b) False

Q.36 Which JDBC drivers will run your program?

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


(c) The JDBC driver test suite. (d) None of the above.

Q.37 JDBC is a Java API that is used to connect and execute query to the database.

PRACTICALKIDA.COM
(a) True (b) False

Q.38 Which of the following statements loads the JDBC-ODBC driver?

(a) Class.forName(sun.jdbc.odbc.JdbcOdbcDriver)
(b) Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")
(c) Class.loadClass(sun.jdbc.odbc.JdbcOdbcDriver)
(d) Class.loadClass("sun.jdbc.odbc.JdbcOdbcDriver")

Q.39 Where is com.mysql.jdbc.Driver located?

(a) in the standard Java library bundled with JDK


(b) in a JAR file mysqljdbc.jar downloadable from the book's Companion Website
(c) in a JAR file classes12.jar downloadable from the book's Companion Website
(d) in a JAR file ojdbc14.jar downloadable from the book's Companion Website

Q.40 To execute a SELECT statement "select * from Address" on a Statement object stmt, use

(a) stmt.execute("select * from Address");


(b) stmt.executeQuery("select * from Address");
(c) stmt.executeUpdate("select * from Address");
(d) stmt.query("select * from Address”);
Q.41 Which of the following function is used to find the column
count of the particular resultset ?

(a) getMetaData() (b) simple


(c) getColumnCount() (d) parameterized

Q. 42 How can you retrieve information from a ResultSet ?

(a) By invoking the method get( .. , String type)on the ResultSet, where type is the database type
(b) By invoking the method get(…, Type type)on the ResultSet, where Type is an object which
represents a database type
(c) By invoking the method getValue( .. ), and cast the result to the desired Java type.
(d) By invoking the special getter methods on the ResultSet : getString( .. ), getBoolean( .. ),
getClob(. .. ), ..

Q. 43 Are ResultSets updateable ?

(a) Yes, but only if you call the method openCursorO on the ResultSet, and if the driver and
database support this option
(b) Yes, but only if you indicate a concurrency strategy when executing the statement, and if the
driver and database support this option

PRACTICALKIDA.COM
(c) Yes, but only if the ResultSet is an object of class UpdateableResultSet, and if the driver and
database support this option
(d) No, ResultSets are never updateable. You must explicitly execute DML statements (i.e.
insert, delete and update) to change the data in the underlying
database.

Q. 44 What is JDBC ?

(a) java compiler (b) Java API


(c) Java interpreter (d) Both (a) and (b)

Q. 45 JDBC is a ______ interface, which means that it is used to invoke SQL commands
directly

(a) low-level (b) middle-level


(c) higher-level (d) user

Q. 46 Kind of driver converts JDBC calls on the client API for Oracle, Sybase, Informix, DB2,
or other DBMS is known as, _____ .

(a) JDBC-Net pure Java driver


(b) JDBC-ODBC Bridge plus ODBC driver
(c) Native-API partly-Java driver
(d) Both (a) and (b)
Q.47 The JDBC-ODBC bridge allows _____ to be used as ____.

(a) JDBC drivers, ODBC drivers (b) Drivers, Application


(c) ODBC drivers, JDBC drivers (d) Application, drivers

Q. 48 What MySQL property is used to create a surrogate key in MySQL?

(a) UNIQUE (b) SEQUENCE


(c) AUTO_INCREMENT (d) None of the mentioned

Q. 49 ODBC minimum SQL grammar contains ____.

(a) INSERT, UPDATE, DELETE only (b) Stored procedure


(c) date, time and timestamp only (d) CREATE and DROP VIEW only

Q. 50 Type 1 driver is also known as_____ .

(a) JDBC-Native API (b) JDBC-ODBC Bridge Driver


(c) JDBC-net pure java (d) None of these

Q. 51 ODBC requires configuring as _____which represents the target database.

PRACTICALKIDA.COM
(a) Data Source Name
(c) Data source
(b) Domain Name
(d) Source name

Q. 52 Type 2 driver is also known as ______.

(a) JDBC-Native API (b) JDBC-ODBC Bridge Driver


(c) JDBC-net pure java (d) None of these

Q. 53 ______ calls get converted into native C or C++ API calls.

(a) API (b) JDBC


( c) JDBC API (d) None ofthese

Q. 54 Which of the following translates the socket information in call format required by the
DBMS?

(a) Application server (b) Middleware application server


(c) Server (d) Middleware

Q.55 Analyze the following code:


ResultSetresultSet = statement.executeQuery ("select firstName, mi, lastName from Student
where lastName " + " = 'Smith'");
System.out.println(resultSet.getString(1));
(a) If the SQL SELECT statement returns no result, resultSet is null.
(b) The program will have a runtime error, because the cursor in resultSet does not point to a
row. You must use resultSet.next() to move the cursor to the first row in the result set.
Subsequently, resultSet.next() moves the cursor to the next row in the result set.
(c) resultSet.getString(1) returns the firstName field in the result set.
(d) resultSet.getString(1) returns the mi field in the result set.

Q. 56 Which of the following model is java applet or application directly Communicates with
data source?

(a) Three tier (b) N-tier


(c) Two tier (d) None of these

Q. 57 _____ interface is important from java.sql package in JDBC.

(a) Statement (b) Result


(c) Connection (d) None of these

Q. 58 Connection interface helps by providing the different methods for--------- and -----

(a) Transactions , Connection (b) Transactions, Error handling

PRACTICALKIDA.COM
(c) Error handling , Connection (d) None of the above

Q. 59 Driver manager class is used for establishing connection .

(a) True (b) False

Q. 60 JDBC driver manager is known as the _____ of the JDBC architecture.

(a) front end (b) middle layer


(c) backbone (d) None of these

Q. 61 Every driver must provide a class that should implement the Driver interface.

(a) True (b)False

Q. 62 ______-interface allows storing results of query ?

(a) Statement (b) Connection


(c) Resultset (d) None ofthese

Q.63 getUserNameO method is used to _____.

(a) retrieve name of user (b) retrieve name


(c) access name (d) None of these
Q. 64 Which of the following query is used for SELECT query ?

(a) execute(); (b) execute(String sql);


(c) executeUpdate(String sql); (d) executeQuery(String sql);

Q.65 What is the return value from stmt.executeUpdate("insert into T values (100, ‘Smith')")

(a) void
(b) an int value indicating how many rows are effected from the invocation
(c) a value indicating whether the SQL statement has been executed successfully
(d) an object that contains the status of the execution

Q.66 Suppose a prepared statement is created as follows:


Statement preparedStatement = connection.prepareStatement
("insert into Student (firstName, mi, lastName) " +
"values (?, ?, ?)");
To set a value John to the first parameter, use

(a) preparedStatement.setString(0, "John");


(b) preparedStatement.setString(1, "John");
(c) preparedStatement.setString(0, 'John');

PRACTICALKIDA.COM
(d) preparedStatement.setString(1, ‘John');

Q.67 How do you know in your Java program that a SQL warning is generated as a result of
executing a SQL statement in the database?

a) You must catch the checked SQLException which is thrown by the method which executes
the statement
b) You must catch the unchecked SQLWarningException which is thrown by the method which
executes the statement
c) You must invoke the getWarnings() method on the Statement object (or a sub interface
thereof)
d) You must query the ResultSet object about possible warnings generated by the database

Q.68 To create a statement on a Connection object conn, use

(a) Statement statement = conn.statement();


(b) Statement statement = Connection.createStatement();
(c) Statement statement = conn.createStatement();
(d) Statement statement = connection.create();

Q.69 What is correct about DDL statements (create, grant,...)?

(a) DDL statements are treated as normal SQL statements, and are executed by calling the
execute() method on a Statement (or a sub interface thereof) object
(b) To execute DDL statements, you have to install additional support files
(c) DDL statements can not be executed by making use of JDBC, you should use the native
database tools for this.
(d) Support for DDL statements will be a feature of a future release of JDBC

Q.70 PreparedStatement is a subinterface of Statement

(a) True (b)False

Q.71 The parameters in a prepared statement is denoted using the ? sign.

(a) True (b)False

Q.72 PreparedStatement is efficient for repeated executions.

(a) True (b)False

Q.73 The prepareStatement is not available in java.sql.Connection interface.

(a) True (b)False

PRACTICALKIDA.COM
Q.74 Which of the following is not interface?

(a) DriverManager (b) Connection


(c) Statement (d) ResultSet

Q.75 The statement interface cannot accept parameters.

(a) True (b)False

Q.76 There are ____ types of statements

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

Q.77 execute() method returns _____ value.

(a)boolean (b)integer
(c)ResultSet Object (d) String

Q.78 executeUpdate() method returns _____ value.

(a)boolean (b)integer
(c)ResultSet Object (d) String
Q.79 executeQuery() method returns _____ value.

(a)boolean (b)integer
(c)ResultSet Object (d) String

Q.80

(a)boolean (b)integer
(c)ResultSet Object (d) String

Q.81 API stands for Application Programming Interface.

(a) True (b)False

Q.82 JDBC is useful for both application developers and JDBC driver vendors.

True (b)False

Q.83 Any third party vendor cannot design their own JDBC drivers.

(a) True (b)False

PRACTICALKIDA.COM
Q.84 The JDBC specification is prepared by Sun Microsystems.

(a) True (b)False

Q.85 JDBC API supports both two-tier and three-tier processing model.

(a) True (b)False

Q.86 JDBC is an API that cannot access data stored in a Relational Database.

(a) True (b)False

Q.87 Which of the following is correct about driver interface of JDBC?

(a) JDBC driver is an interface enabling a Java application to interact with a database.
(b) The JDBC driver gives out the connection to the database and implements the protocol for
transferring the query and result between client and database.
(c)Both of the above
(d) None of the above

Q.88 How many Result sets available with the JDBC 2.0 core API?
(a) 2 (b) 3
(c) 4 (d) 5
Q.89 The performance of the application will be faster if you use PreparedStatement interface
because query is compiled only once.

(a) True (b) False

Q.90 Which model does a Java applet or application talks directly to the data source?

(a) Two-tier models (b) Three-tier models


(c) Both A & B (d) None of the above

CHAPTER-6 : (Servlets) (CO6)

1.How constructor can be used for a servlet?


a) Initialization
b) Constructor function
c) Initialization and Constructor function
d) Setup() method

2. Can servlet class declare constructor with ServletConfig object as an argument?


a) True
b) False

PRACTICALKIDA.COM
3. What is the difference between servlets and applets?
i.Servlets execute on Server; Applets execute on browser
ii.Servlets have no GUI; Applet has GUI
iii.Servlets creates static web pages; Applets creates dynamic web pages
iv.Servlets can handle only a single request; Applet can handle multiple requests
a) i,ii,iii are correct
b) i,ii are correct
c) i,iii are correct
d) i,ii,iii,iv are correct

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

5. Which method is used to get three-letter abbreviation for locale’s country in servlets?
a) Request.getISO3Country()
b) Locale.getISO3Country()
c) Response.getISO3Country()
d) Local.retrieveISO3Country()
6. Which of the following code retrieves the body of the request as binary data?
a) DataInputStream data = new InputStream()
b) DataInputStream data = response.getInputStream()
c) DataInputStream data = request.getInputStream()
d) DataInputStream data = request.fetchInputStream()

7. When destroy() method of a filter is called?


a) The destroy() method is called only once at the end of the life cycle of a filter
b) The destroy() method is called after the filter has executed doFilter method
c) The destroy() method is called only once at the begining of the life cycle of a filter
d) The destroyer() method is called after the filter has executed

8. Which of the following is true about servlets?


a) Servlets execute within the address space of web server
b) Servlets are platform-independent because they are written in java
c) Servlets can use the full functionality of the Java class libraries
d) Servlets execute within the address space of web server, platform independent and uses the
functionality of java class libraries

9. How is the dynamic interception of requests and responses to transform the information done?
a) servlet container
b) servlet config
c) servlet context

PRACTICALKIDA.COM
d) servlet filter

10. Which are the session tracking techniques?


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

11. Connection Pooling Class manages no of user requests for connections to improve the
performance.

a. True
b. False

12. Which object of HttpSession can be used to view and manipulate information about a
session?
a. session identifier
b. creation time
c. last accessed time
d. All mentioned above

13. Using mail API we cannot send mail from a servlet.

a. True
b. False

14. Which class provides stream to read binary data such as image etc. from the request
object?

a. ServltInputStream
b. ServletOutputStream
c. Both A & B
d. None of the above

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

PRACTICALKIDA.COM
response to another resource, it may be servlet, jsp or html file.

a. True
b. False

16. Which of these ways used to communicate from an applet to servlet?

a. RMI Communication
b. HTTP Communication
c. Socket Communication
d. All mentioned above

17. Which methods are used to bind the objects on HttpSession instance and get the objects?

a. setAttribute
b. getAttribute
c. Both A & B
d. None of the above

18. Which type of ServletEngine is a server that includes built-in support for servlets?

a. Add-on ServletEngine
b. Embedded ServletEngine
c. Standalone ServletEngine
d. None of the above

19.What type of servlets use these methods doGet(), doPost(),doHead(), doDelete(),


doTrace()?

a. Genereic Servlets
b. HttpServlets
c. All of the above
d. None of the above

20.Which cookie it is valid for single session only and it is removed each time when the user
closes the browser?

a. Persistent cookie
b. Non-persistent cookie
c. All the above
d. None of the above
Ans:- b

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

PRACTICALKIDA.COM
side.

a. True
b. False

22. Web server is used for loading the init() method of servlet.

a. True
b. False

23.Servlets handle multiple simultaneous requests by using threads.

a. True
b. False

24. 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
25. Which packages represent interfaces and classes for servlet API?

a. javax.servlet
b. javax.servlet.http
c. Both A & B
d. None of the above

26. Which class can handle any type of request so that it is protocol-independent?

a. GenericServlet
b. HttpServlet
c. Both A & B
d. None of the above

27. Which HTTP Request method is non-idempotent?

a. GET
b. POST
c. BOTH A & B

PRACTICALKIDA.COM
d. None of the above

28. Which object is created by the web container at time of deploying the project?

a. ServletConfig
b. ServletContext
c. Both A & B
d. None of the above

29. What is the lifecycle of a servlet?

a. Servlet class is loaded


b. Servlet instance is created
c. init,Service,destroy method is invoked
d. All mentioned above

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

a. HttpSession
b. URL rewriting
c. Cookies
d. Hidden form fields

31. In HTTP Request what asks for the loopback of the request message, for testing or for
troubleshooting?

a. PUT
b. OPTIONS
c. DELETE
d. TRACE

32. Which one of the following scopes does the attribute in servlet is an object that can be
set, get or removed?

a. session scope
b. request scope
c. application scope
d. All mentioned above

33. Which are the examples of Application Server?

PRACTICALKIDA.COM
a. Apache
b. Tomcat
c. JBoss
d. Weblogic
e. Both C & D

34. How many techniques are used in Session Tracking?

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

35. In HTTP Request method Get request is secured because data is exposed in URL bar

a. True
b. False

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

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


b. For each request, it starts a process and Web server is limited to start processes
c. It uses platform dependent language e.g. C, C++, perl
d. All mentioned above

37. Servlet technology is used to create web application

a. True
b. False

38. What technique is used for the authentication mechanism in the servlet specification?
a. Role Based Authentication
b. Form Based Authentication
c. Both A & B
d. None of the above

39. What does MIME stand for?


a) Multipurpose Internet Messaging Extension
b) Multipurpose Internet Mail Extension
c) Multipurpose Internet Media Extension
d) Multipurpose Internet Mass Extension

PRACTICALKIDA.COM
40. What is the storage capacity of single cookie?
a) 2048 MB
b) 2048 bytes
c) 4095 bytes
d) 4095 MB

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


a) client
b) server
c) tomcat
d) applet

42. Which component can be used for sending messages from one application to another?
a) server
b) client
c) mq
d) webapp

43. How are java web applications packaged?


A) jar
b) war
c) zip
d) both jar and war

44. How can we connect to database in a web application?


a) oracle sql developer
b) toad
c) JDBC template
d) mysql

45. How can we take input text from user in HTML page?
a) input tag
b) inoutBufferedReader tag
c) meta tag
d) scanner tag

46. Which of the below is not a javascript framework for UI?


a) Vaadin
b) AngularJS
c) KendoUI
d) Springcore

PRACTICALKIDA.COM
47. Which of the below can be used to debug front end of a web application ?
a) Junit
b) Fitnesse
c) Firebug
d) Mockito

48. What type of protocol is HTTP?


a) stateless
b) stateful
c) transfer protocol
d) information protocol

49. The Java specification defines an application interface for communication between the
web server and the application program
a) servlet
b) randomise
c) applet
d) script

50. Which method is used to specify before any lines that uses the PintWriter?
a) setPageType()
b) setContextType0
c) setContentType()
d) setResponseType()

51. What are the functions of Servlet container?


a) Lifecycle management
b) Communication support
c) Multithreading support
d) All of the above

52. What is bytecode?


a) Machine-specific code
b) Java code
c) Machine-independent code
d) None of the mentioned

53. What type of servlets use these methods doGet(),doTrace(),doPost(),doHead,doDelete()?


a) Genereic Servlets
b) HttpServlets
c) All of the above
d) None of these

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

PRACTICALKIDA.COM
55. Which packages represent interfaces and classes for servlet API?
a) javax.servlet
b) javax.servlet.http
c) Both a and b
d) None of these

56. What is the lifecycle of a servlet ?


a) Servlet class is loaded
b) Servlet instance is created
c) init, Service, destroy method is invoked
d) All of these

57. What is the difference between servlet and applet?


a) servlets execute on servers while applets execute on browser
b) servlets create static pages while applets create dynamic pages
c) servlets can execute single request while applets execute multiple requests
d) None of these

58. A deployment descriptor describes.


a) web component response settings
b) web component settings
c) web component request settings
d) All of these
59. Which object is created by the web container at time of deploying the project ?
a) ServletConfig
b) ServletContext
c) Both a and b
d) None of the above

60. The doGet() method extracts values of the parameter's types and number by using
a) response.getAttribute()
b) response.getParameter()
c) request.getParameter()
d) request.setParameter()

61. The life cycle of a servlet is managed by


a) http and https
b) servlet context
c) servlet itself
d) servlet container

62. Which method take a string not a URL?


a) sendRedirect
b) forward
c) Both

PRACTICALKIDA.COM
d) None

63. Which method shows the client what server is receiving?


a) doGet
b) doOption
c) doTrace
d) doPost
64. Which of the following are session tracking techniques
a) URL rewriting, using session object, using cookies,using hidden fields
b) URL rewriting, using serviet object, using responseobject, using cookies
c) URL rewriting, using session object, using responseobject, using hidden field
65. Which methods are used to bind the objects HttpSession instance and get the objects?
a) setAttribute
b) getAttribute
c) both a and b
d) None of the above

66.Sessions is a part of the SesionTracking and it is for maintaining the client state at server side.
a) True
b) False

67. 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) None of these
d) All of these

68. Which method in session tracking is used in a bit of information that is sent by a web server
to a browser and which can later be read back from that browser?
a) HttpSession
b)URL rewriting
c) Cookies
d) Hidden form fields

69. The Java specification defines an application programming interface for


communication between the Web server and the application program.
(a) Server (b) Servlet
(c) Program (d) Randomize

70. Which ofthe following is not true for servlet ?


(a) It is persistent (b) Platform independent
(c) High performance (d) It is multi threaded
(e) It is single threaded.

PRACTICALKIDA.COM
71. Which of the following is an approach for state maintenance in Web applications?
(a) Hidden Form Field (b) URL Rewriting
(c) Cookies (d) HTTP Session
(e) All of the above.

72. Which method of the request object is used to extract values of the input fields in a form
when it is submitted?
(a) getParameter (b) getParameterNames
(c) getValues (d) putValues
(e) getParameters.

73. Which of the following are interface?


1. ServletContext 2. Servlet
3. GenericServlet 4. HttpServlet
(a) All (1), (2), (3) and (4)
(b) Only (1) and (2)
(c) Only (1), (3) and (4)
(d) Only (1) and (4)
74. Which of the following methods are main methods in life cycle of servlet?
1. initO 2. serviceO
3. destroyO 4. stop()
5. waitO

(a) All (1), (2), (3), (4) and (5)


(b) Only (1), (2) and (3)
(c) Only (3), (4) and (5)
(d) Only (1), (4) and (5)

75. During initialization of servlet, a servlet instance can throw __ .


(a) An UnavailableException (b) A ServletException
(c) Both (a) and (b) (d) None

76. Java servlets are efficient and powerful solution for creating __ for the web.
(a) dynamic content (b) static content
(c) hardware (d) both (a) and (b)
77. __ is the first phase of the servlet life cycle.
(a) Initialization (b) Service
(c) Destruction (d) Both (a) and (b)

78. The service phase of the servlet life cycle represents a interactions with requests until the
servlet is __ o
(a) created (b) running

PRACTICALKIDA.COM
(c) initiated (d) destroyed

79.. The GET and POST methods are specified in _________.


a) a CGI program
b) a Java program
c) an HTML form
d) a URL string

80. If your request is not time-sensitive, such as finding the address of a student in the database,
use the __________ method to speed up the performance.
a) GET
b) POST
c) DELETE
d) UPDATE

81. Apache Tomcat is a ________.


a) Servlet
b) Java program
c) Web server
d) Web server that is capable of running Java programs.

82. A servlet is an instance of __________.


a) the Object class
b) the Applet class
c) the HttpServlet class
d) the HTTPServlet class

83. Why use RequestDispatcher to forward a request to another resource, instead of using a
sendRedirect?
a) Redirects are no longer supported in the current servlet API.
b) Redirects are not a cross-platform portable mechanism.
c) The RequestDispatcher does not use the reflection API.
d) The RequestDispatcher does not require a round trip to the client, and thus is more
efficient and allows the server to maintain request state.

84. What is the difference between doing an include or a forward with a RequestDispatcher?
a) The forward method transfers control to the designated resource, while the include
method invokes the designated resource, substitutes its
output dynamically in the display, and returns control to the calling page.
b) The two methods provide the same functionality, but with different levels of
persistence.
c) The forward method is deprecated as of JSP 1.1 and the include method should be used
in order to substitute portions of a dynamic display at
runtime.

PRACTICALKIDA.COM
d) The include method transfers control to a dynamic resource, while the forward method
allows for dynamic substitution of another JPS pages
output, returning control to the calling resource.

85. Given following form:


<form action=”register.do”>
<input type=”text” name=”Name”>
<input type=”submit” value=”Save”>
</form>
and a servlet code:
public class RegisterServlet extends HttpServlet{
pulic void doPost(HttpServletRequest req, HttpServletResponse res) {
// registration logic goes here
return;
}
}
With the above code, assuming the servlet is configured properly and registration logic works
good, trying to register user fails.
Choose one reason.
a) The registration fails because, above servlet dont have doGet() method.
b) The registration fails because, above servlet dont have service() method.

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

PRACTICALKIDA.COM
.

PRACTICALKIDA.COM

You might also like