Exam Sutra Advance Java Chapter 1
Exam Sutra Advance Java Chapter 1
Exam Sutra Advance Java Chapter 1
a. Window
b. Container
c. Panel
d. Frame
a. 7
b. 6
c. 5
d. 8
a. Java.awt
b. Java.graphics
c. Java.awt.graphics
d. None of these
5. Which is the container that doesn’t contain title bar and menu bars. It can
have other components like button, text field etc?
a. Window
b. Frame
c. Panel
d. Container
6. Which object can be constructed to show any number of choices in the visible
window?
a. Choice
b. Menu
c. List
d. Checkbox
a. setText()
b. getText()
c. addText()
d. all of these
a. Server side
b. Client side
9. Which method of the applet class displays the result of applet code on
screen?
a. Run() method
b. Paint() method
c. drawstring() method
d. main() method
a. HTML document
b. Word document
c. Gif file
d. Rtf file
a. .applet file
b. .java html
c. .java file
d. .class file
13. Which of the following is used to interpret and execute Java Applet Classes
Hosted by HTML?
a. Applet Viewer
b. Applet Screen
c. Applet watcher
d. Applet show
14. Java applet are used to create _______ applications
a. Graphical
b. User interactive
c. Both a & b
d. None of the above
a. Display()
b. Paint()
c. displayApplet()
d. show()
a. Display()
b. Paint()
c. Show()
d. All of these
17. Which object can be constructed to show any number of choices in the
visible window?
a. Labels
b. Choice
c. List
d. Checkbox
18. Which of the following class is derived from the container class?
a. Component
b. Panel
c. Menu component
d. List
a. Draw()
b. Update()
c. Show()
d. Paint()
a. Start()
b. Stop()
c. Init()
d. Destroy()
22. Which of these classes can be added to any container class, using the add
method defined in the container class?
a. Button
b. checkboxMenuItem
c. menu
d. menubar
23. which of the following methods can be used to change the size of a
java.awt.component object?
a. Dimension()
b. Setsize()
c. Area()
d. Size()
a. Disappear()
b. Delete()
c. Remove()
d. Hide()
a. True
b. False
26. The title of the frame can be set in AWT using the method.
a. setHeading
b. setTitle
c. Create Title
d. setTitle
27. Which are passive controls that do not support any interaction with the user?
a. Choice
b. List
c. Labels
d. Checkbox
a. 1
b. 2
c. 3
d. 4
29. By which method we can set or change the text in an Label In AWT?
a. setText()
b. getText()
c. addText()
d. all of these
31. Which layout manager places components in one of the five regions : north,
south , east , west and center?
a. Absolute layout
b. Grid layout
c. Border layout
d. Flow layout
a. Flow layout
b. Border layout
c. Grid layout
d. All of these
a. Card layout
b. Gridbag layout
c. Frame
d. Border layout
a. Checkbox
b. Drop-down
c. Choice
d. None of these
36. Which class can be used to represent a checkbox with a textual label that
can appear in a menu?
a. Menu bar
b. Menuitem
c. Checkboxmenuitem
d. Menu
37. Which abstract class is the super class of all menu related classes?
a. MenuComponent
b. MenuBar
c. MenuItem
d. CheckBoxMenuItem
a. Menus
b. Menubar
c. Frame
d. Both a & b
39. Dialog box does not have minimize and maximize button
a. True
b. False
40. A dialog box is referred to as modeless if the user does not have to close it
in order to continue using the application that owns the dialog box.
a. True
b. False
41. The ______ class displays a dialog window from which the user can select a
file.
a. Dialog
b. Filedialog
c. File
d. None of these
42. Find out the error in the given program and write down the correct answer.
import java.awt.*;
import java.awt.event.*;
class FrameJavaExample
{
public static void main (String args[])
{
Frame frame = new Frame("Frame Java Example");
//set the size of the frame
frame.setSize(300,250);
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}
Ans : __________________________________________________________
43. Which one of the following is the correct syntax for defining a label in
AWT ?
a. Label (String s)
b. Label ( String s, int style )
c. Both a & b
d. None of these
44. Match the following tag names with the descriptions in the following lists:
1. EMBED tag
2. APPLET tag
3. OBJECT tag
Ans - _____________________________________________________
51. Why does it take so much time to access an Applet having Swing
components the first time?
Ans - Because behind every swing component are many Java objects and
resources.
This takes time to create them in memory. JDK 1.3 from Sun has some
improvements which may lead to faster execution of Swing applications.
Ans: True
a)Window Open
b)Window Close
c)WindowActivated,Deactivated
d)All of these
Ans:Boolean
57. Find out the error in following code and rewrite the corred code
importjava.awt.*;
framedemofr=new frameDemo();
fr.setSize(400,500);
fr.setVisible(true);
fr.setLayout(new FlowLayout());
Ans:
importjava.awt.*;
framedemofr=new frameDemo();
fr.setSize(400,500);
fr.setVisible(true);
fr.setLayout(new FlowLayout());
}
}
58. Which one of the following is not a valid alignment for label component
a)LEFT.CENTER
b)LEFT.RIGHT
c)Left.MIDDLE
d)LABEL.LEFT
a)Button(String s)
c)both a and b
d)none of these
a)3
b)4
c)7
d)1
61. Find out the error in following program and rewrite the code
importjava.awt.*;
{
frDemofr=new frDemo();
fr.setSize(400,500);
fr.setVisible(true);
fr.setLayout(new FlowLayout());
add(btn1);
Ans: CheckboxGroup
Ans:java.awt
66. How can we use the drawString method in Awt Write down the correct
Syantax.
67. Write down the correct syantax to run applet program using applet veiwer.
Ans:javac FirstApplet.java
appletviewer FirstApplet.html
68. Which method allows us to live some space between underline window on
the applet and layout manager.
Ans: getInsets()
69. Which layout is used when we want to perform various set graphical control
at the same time
Ans: CardLayout.
a) FlowLayout.Left
b) LEFT.FLOWLAYOUT
c) FlowLayout.LEFT
d) none of these
a) border layout
b) grid layout
c) panel
d) layout manager
72. Which method used to place some text in the text field?
a) getText(String str)
b) setText(String str)
c) putText(String str)
d) None of the above
73. Which method used to change the foreground (text) color of components
like text field?
a) setBackground(Color clr)
b) setForeground(Color clr)
c) setColor(Color clr)
d) setEditable(boolean state)
a) Yes
b) No
c) Can be yes or no
d) Can not say
75. Which of the following option match for the given program?
import java.awt.*;
public class Layouts extends Frame {
Layouts() {
java.awt.Container container = new Container();
container.setLayout(new GridLayout(3, 2));
container.add(new java.awt.Button("A"));
container.add(new java.awt.Button("B"));
java.awt.Container container2 = new Container();
container2.setLayout(new GridLayout(1, 1));
container.add(container2);
container2.add(new java.awt.Button("C"));
container.add(new java.awt.Button("D"));
container2.add(new java.awt.Button("E"));
add(container);
pack();
}
public static void main(String[] args) {
new Layouts().show();
}
}
Ans – B
76. In which layout there are four components at the four sides and one
component occupying large area at the center ?
a) Border Layout
b) Flow Layout
c) Grid Layout
d) GridBag Layout
a) Horizontal Layout
b) Flow Layout
c) Grid Layout
d) GridBag Layout
a) Horizontal Layout
b) Grid Layout
c) Tabular Layout
d) GridBag Layout
79. No. of parameters is passed to GridLayout manager is ______
a) Horizontal Layout
b) Grid Layout
c) Tabular Layout
d) GridBag Layout
81. ___________ layout manager allows us to have more than one layout.
a) Horizontal Layout
b) Card Layout
c) Grid Layout
d) GridBag Layout
83. In card layout which method is used to add the cards on the panel ?
84. Which of the following is the valid constructor to use card layout in your
program ?
a) CardLayout()
b) CardLayout( int hgap int vgap )
c) Both a & b
d) None of these
85. Which method is used to flip to the previous card of the given container ?
86. In card layout which method is used to flip to the specified card with the
given name ?
87. In card layout which method is used to remove the specified component
from the layout.
a) hideLayout ( Container parent )
b) removeLayout ( Container parent )
c) removeLayoutComponent(Component cm)
d) All of these
88. Which layout manager is considered as the most flexible and complex
layout manager ?
a) Card Layout
b) Border Layout
c) Flow Layout
d) GridBag Layout
89. Which one of the following denotes increase and decrease in horizontal or
vertical preferred size of the component ?
91. In gridbag layout ________ value denotes how the components should
expand within the display area.
a) fill
b) Int x and int y
c) Gridx and gridy
d) Ipadx and ipady
92. Which layout manager should be used to create this type of User Interface ?
a) Card Layout
b) Border Layout
c) Flow Layout
d) GridBag Layout
Ans - GridBagLayout()
94. Which class can be used to represent a checkbox with a textual label that
can appear in a menu. Select the one correct answer.
a) Select
b) Checkbox
c) List
d) CheckboxMenuItem
96. A superclass of Textfield and TextArea classes that is used to create single-
line , multiline textfields rexpectively is_____.
Ans – TextComponent
97. BorderLayout class has __________regions to add components to it
a) two
b) three
c) four
d) five
a) resizing corners
b) borders
c) Title bars
d) all of these
a) text field
b) a picture
c) window
d) panel
a) setLayout(new FlowLayout())
b) setLayout(new GridbagLayout())
c) setLayout(new BorderLayout(3,4))
d) none of these
a) Card Layout
b) Border Layout
c) Flow Layout
d) GridBag Layout
a) Card Layout
b) Border Layout
c) Flow Layout
d) GridBag Layout
103. For creating the complete menu bar the constructors we use ______
a) Public MenuBar()
b) Public Menu(String title )
c) Public MenuItem(String title )
d) All of these
104. Which one of the following is the correct syntax to add menu bar in any
frame ?
a) fr.addMenu(menubar)
b) fr.setMenuBar(mbar);
c) both a & b
d) none of these
a) False
b) True
106. In which type of dialog box user does not have to close it in order to
continue using the application ?
107. In which type of dialog box user have to close it first in order to continue
using the application ?
108. Which method is used to set the mode of the file dialog.
Ans –SetMode(int)
109. The ________ class displays a dialog window from which the user can
select a file.
Ans – grouping
111. In Graphics class Which method is used to set the graphics currentcolor to
the specified color?
114. In file dialog which method indicates whether file dialog box is for loading
from a file or saving to a file ?
a) getDirectory()
b) getFile()
c) getMode()
d) none of these
115. Which method sets the selected file for this file dialog window to be the
specified file.
a) getDirectory()
b) getFile()
c) setFile()
d) none of these
116. In file dialog which constant value indicates that the purpose of the file
dialog window is to locate a file to which to write.
a) SAVE
b) LOAD
c) Both a & b
d) none of these
117. In applet, which of the following tag is used for accepting user defined
parameter?
Ans – param
118. How do you change the current layout managers for a container?
a) Parent class
b) Sub class
c) Abstract class
d) Virtual class