Exam Sutra Advance Java Chapter 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

Unit 1 : Abstract Windowing Toolkit

Total no. of Questions - 120

1. Give the Abbreviation of AWT:

a. Applet windowing Toolkit


b. Abstract windowing toolkit
c. Absolute windowing toolkit
d. None of these

2. Which is a component in AWT that can contain another components like


buttons, textfields, labels etc?

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

3. How many types of controls does AWT support?

a. 7
b. 6
c. 5
d. 8

4. Which class provides may methods for graphics programming?

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

7. By which method we can set or change the text in a label in AWT?

a. setText()
b. getText()
c. addText()
d. all of these

8. on which side applet always executed?

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

10. Applet can be embedded in ______

a. HTML document
b. Word document
c. Gif file
d. Rtf file

11. Which of the following is true about applet?

a. Applets do not have a main() method.


b. Applets must run under applet viewer or web browser
c. The user I/O is not performed using java’s stream I/O class
d. All of these

12. Executable applet is ____________

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

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

a. Display()
b. Paint()
c. displayApplet()
d. show()

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

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

19. When we invoke repaint() for a java.awt.component object, the AWT


invokes the method:

a. Draw()
b. Update()
c. Show()
d. Paint()

20. Which method executes only once ?

a. Start()
b. Stop()
c. Init()
d. Destroy()

21. What does the following line of code do?

TextField text = new TextField(20);


a. Creates text object that can hold 20 rows of text
b. Creates text object that can hold 20 columns of text
c. Creates the object text and initializes it with the value 20
d. This is invalid code

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

24. Which of the following methods can be used to remove a


java.awt.component object from the display()?

a. Disappear()
b. Delete()
c. Remove()
d. Hide()

25. These two ways are used to create a Frame

1. By creating the object of Frame class ( association )


2. By extending frame class ( inheritance )

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

28. How many ways can we align the label in a container?

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

30. The various controls supported by AWT are:

a. Labels, push buttons


b. Checkbxes, choice lists
c. Scrollbars, test fields, text area
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

32. Arranges the components horizontally:


a. Border layout
b. Card layout
c. Grid layout
d. Flow layout

33. The most commonly used layout managers are ______.

a. Flow layout
b. Border layout
c. Grid layout
d. All of these

34. Default layout manager for subclasses of window is _____

a. Card layout
b. Gridbag layout
c. Frame
d. Border layout

35. Each menu is associated with a _______ list of menu items.

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

38. Menu items are added to ______

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

a. Use to deploy applets to a multi-browser environment.


b. Use to deploy applets that are to be used only with the Mozilla family
of browsers
c. Use to deploy applets that are to be used only with Internet Explorer

Ans - _____________________________________________________

45. How will you initialize an applet ?

Ans - By including the initialization code in the init() method.

46. How do you set security in applets ?

Ans – by using SetSecurityManager() method.

47. When is update method called?

a. Whenever we minimize, maximize, restart the applet and explicitly


calling the repaint() method in the code
b. Repaint() method will implicitly call the update() method.
c. Both a & b
d. None of these

48. Which method is called by applet class to load an image?

Ans - getImage(URL object, filename) is used for this purpose.

49. How does applet recognize the height and width?

Ans - Using getParameters() method.

50. What is the relationship between clipping and repainting?

Ans - When a window is repainted by the AWT painting thread, it sets


the clipping regions to the area of the window that requires repainting.

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.

52. What is the order of method invocation in an Applet ?

a. Init() >> start() >> paint() >> destroy() >> stop()


b. Start() >> paint() >> init() >> stop() >> destroy()
c. Init() >> start() >> paint() >> stop() >> destroy()
d. All of these

53. The panel class is derived from the___class

Ans: Container class

54. Panel contains no border,nomenubar and no title bar

Ans: True

55. Which Event is Suported by Frame class

a)Window Open

b)Window Close

c)WindowActivated,Deactivated

d)All of these

56. Which type of datatype is passed to voidSetVisible Method

Ans:Boolean

57. Find out the error in following code and rewrite the corred code

importjava.awt.*;

public class frameDemo


{

public class void main(Sringargs[])

framedemofr=new frameDemo();

fr.setSize(400,500);

fr.setVisible(true);

fr.setLayout(new FlowLayout());

Ans:

Frame Demo class Should be inherited from the frame class.

importjava.awt.*;

public class frameDemo extends Frame

public class void main(Sringargs[])

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

59. What is the Correct syantax to define a button in Awt.

a)Button(String s)

b)Button(String s,int alignment)

c)both a and b

d)none of these

60. In How Many Ways we can define a Button in Awt.

a)3

b)4

c)7

d)1

61. Find out the error in following program and rewrite the code

importjava.awt.*;

public class frDemo extends Frame

public class void main(Sringargs[])

{
frDemofr=new frDemo();

fr.setSize(400,500);

fr.setVisible(true);

fr.setLayout(new FlowLayout());

Button btn1=new Button("Button1");

add(btn1);

Ans:We have to use the frDemo object as fr.add(btn1);

62. Which component acts just like a radio button

Ans: CheckboxGroup

63. In How many ways we can use Scrollbar

Ans: 2(horizontal and vertical).

64. What is the correct syantax to define TextArea

Ans: TextArea(int n, int m).

65. The Graphics class is suported by the package___

Ans:java.awt

66. How can we use the drawString method in Awt Write down the correct
Syantax.

Ans: void drawstring (String s, int x, int y)

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.

70. The correct syntax to denote alignment is ___________

a) FlowLayout.Left

b) LEFT.FLOWLAYOUT

c) FlowLayout.LEFT

d) none of these

71. A ___________ dictates the style of arranging the components in a


container.

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)

74. getLabel() method used to retrieve the label of a button.

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

77. Which layout manager is the invalid one in AWT ?

a) Horizontal Layout
b) Flow Layout
c) Grid Layout
d) GridBag Layout

78. Which of the layout manager arranges component in a grid ?

a) Horizontal Layout
b) Grid Layout
c) Tabular Layout
d) GridBag Layout
79. No. of parameters is passed to GridLayout manager is ______

Ans – 2 ( one for row and one for column )

80. Which layout should be used to create this UI ?

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

82. Which layout is conceptually thought as a collection of cards lying on a


panel ?
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 ?

Ans – add() method

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 ?

a) Public void first ( Container parent )


b) Public void last ( Container parent )
c) Public void previous ( Container parent )
d) All of these

86. In card layout which method is used to flip to the specified card with the
given name ?

Ans - public void show(Container parent, String 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 ?

a) Weight x and weight y


b) Int x and int y
c) Gridx and gridy
d) Ipadx and ipady

90. ____________ denote the extra space occupied by the component


horizontally or vertically when the output window is resized.

a) Weight x and weight y


b) Int x and int y
c) Gridx and gridy
d) Ipadx and ipady

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

93. What is the correct constructor for 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

95. A label is a simple control which is used to display _________________on


the window

Ans – Text ( non-editable )

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

98. By default the Frame has a ________________________________

a) resizing corners
b) borders
c) Title bars
d) all of these

99. Canvas is a _____________

a) text field
b) a picture
c) window
d) panel

100. Choose the incorrect statement :

a) setLayout(new FlowLayout())
b) setLayout(new GridbagLayout())
c) setLayout(new BorderLayout(3,4))
d) none of these

101. Default layout manager for panel is ___________

a) Card Layout
b) Border Layout
c) Flow Layout
d) GridBag Layout

102. Default layout manager for frame is ___________

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 ?

Frame fr = new Frame();

MenuBar mbar = new MenuBar();

a) fr.addMenu(menubar)
b) fr.setMenuBar(mbar);
c) both a & b
d) none of these

105. The dialog boxes contains minimize and maximize buttons.

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 ?

a) Modal dialog box


b) Modeless Dialog box
c) Both a & b
d) None of these

107. In which type of dialog box user have to close it first in order to continue
using the application ?

a) Modal dialog box


b) Modeless Dialog box
c) Both a & b
d) None of these

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 – File Dialog

110. Panel is for _______________ components.

Ans – grouping

111. In Graphics class Which method is used to set the graphics currentcolor to
the specified color?

Ans - public abstract void setColor(Color c)


112. Which constructor is used to create dialog box ?

a) Dialog ( Dialog owner )


b) Dialog ( Dialog owner , String title )
c) Dialog ( Dialog owner , String title , Boolean modal )
d) All of these

113. Signature for file dialog box is ______________-

Ans – public class FileDialog extends Dialog

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) Use setLayout() method


b) Use changeLayout() method
c) Use updateLayout() method
d) none of these

119. Frame is a standard window,which is ____________________of Window


class from AWT hierarchy.

a) Parent class
b) Sub class
c) Abstract class
d) Virtual class

120. Font class is available in ______________

Ans – java.awt package

You might also like