0% found this document useful (0 votes)
26 views38 pages

Java Mcqs

The document consists of a series of multiple-choice questions focused on Java applets, covering topics such as applet creation, lifecycle methods, and graphics handling. It tests knowledge on HTML tags for embedding applets, Java methods for painting and initializing, and the applet's execution environment. The questions also explore the functionality of various methods and attributes related to applets.

Uploaded by

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

Java Mcqs

The document consists of a series of multiple-choice questions focused on Java applets, covering topics such as applet creation, lifecycle methods, and graphics handling. It tests knowledge on HTML tags for embedding applets, Java methods for painting and initializing, and the applet's execution environment. The questions also explore the functionality of various methods and attributes related to applets.

Uploaded by

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

What is an applet primarily written in?

A. Java

B. Python

C. C++

D. JavaScript

2. What is the purpose of the applet tag in HTML?

A. To link CSS files

B. To embed Java applets

C. To create forms

D. To include images

3. Which class do you extend to create a Java applet?

A. Applet

B. Swing

C. JApplet

D. Panel

4. What does the applet run in for security reasons?

A. A virtual machine

B. A sandbox

C. A container

D. A framework

5. What method must be overridden to display content in an applet?

A. paint()

B. start()
C. init()

D. run()

6. Which command is used to run an applet using the applet viewer?

A. java applet

B. runapplet

C. appletviewer

D. executeapplet

7. What is the main function of the browser in relation to applets?

A. To provide the main method

B. To execute applets

C. To compile applets

D. To store applets

8. What is the typical file extension for a Java applet source code file?

A. .html

B. .class

C. .java

D. .applet

9. What does the Graphics object allow you to do in an applet?

A. Manage applet lifecycle

B. Create user interfaces

C. Draw and display graphics

D. Handle events
10. What is required in the HTML file to specify the applet’s dimensions?

A. <size>

B. <dimensions>

C. <applet>

D. <embed>

11. What is the purpose of the appletviewer application?

A. To debug applets

B. To compile Java code

C. To view applets without a browser

D. To create applets

12. What is the output of the HelloApplet when executed?

A. Hello World

B. Hello Applet

C. Hello Java

D. Hello User

13. Which of the following is NOT a feature of applets?

A. They can run in any browser

B. They have access to the client’s file system

C. They are embedded in HTML

D. They are written in Java

14. What is the first step in creating an applet?

A. Write the HTML file

B. Import required packages


C. Compile the applet

D. Run the applet

15. What does the ‘code’ attribute in the applet tag specify?

A. The applet’s class name

B. The applet’s height

C. The applet’s width

D. The applet’s version

16. What is the typical width of the HelloApplet as defined in the HTML?

A. 200

B. 150

C. 100

D. 250

17. What is the role of the ‘init()’ method in an applet?

A. To start the applet

B. To initialize the applet

C. To paint the applet

D. To stop the applet

18. What is the significance of the ‘paint()’ method in an applet?

A. It draws graphics on the applet

B. It handles user input

C. It initializes the applet

D. It compiles the applet


19. What is the purpose of the init() method in an applet’s life cycle?

A. To perform final cleanup

B. To start the applet’s execution

C. To initialize the applet

D. To repaint the applet

20. Which method is called when the applet becomes visible for the first
time?

A. init()

B. start()

C. paint()

D. stop()

21. What happens when the stop() method is called?

A. The applet is initialized

B. The applet’s execution is stopped

C. The applet is painted

D. The applet is destroyed

22. How many times is the destroy() method called during an applet’s life
cycle?

A. Once

B. Three times

C. Twice

D. Never

23. What is the main function of the start() method?


A. To start the applet’s execution

B. To stop the applet’s execution

C. To initialize the applet

D. To perform final cleanup

24. Which method should be overridden to perform painting in an applet?

A. paint()

B. start()

C. init()

D. stop()

25. Which method should be overridden to perform painting in an applet?

A. paint()

B. start()

C. init()

D. stop()

26. What is the sequence of method calls when an applet is loaded?

A. init() -> start() -> paint()

B. paint() -> init() -> start()

C. start() -> init() -> paint()

D. stop() -> destroy() -> init()

27. What does the paint() method do in an applet?

A. Initializes the applet

B. Starts the applet’s execution

C. Handles the applet’s final cleanup


D. Handles the drawing of the applet

28. What is the sequence of method calls when an applet is loaded?

A. init() -> start() -> paint()

B. paint() -> init() -> start()

C. start() -> init() -> paint()

D. stop() -> destroy() -> init()

29. What does the paint() method do in an applet?

A. Initializes the applet

B. Starts the applet’s execution

C. Handles the applet’s final cleanup

D. Handles the drawing of the applet

30. When is the stop() method called?

A. When the applet is minimized

B. When the applet is first loaded

C. When the applet is destroyed

D. When the applet is painted

31. What is the role of the destroy() method in an applet?

A. To initialize the applet

B. To perform final cleanup

C. To start the applet

D. To repaint the applet


32. Which method is called when a user revisits a page containing the
applet?

A. init()

B. paint()

C. start()

D. stop()

33. Which method is called when a user revisits a page containing the
applet?

A. init()

B. paint()

C. start()

D. stop()

34. What is the first method called in the applet life cycle?

A. init()

B. paint()

C. start()

D. destroy()

35. What does the init() method resemble in terms of functionality?

A. Constructor

B. Finalizer

C. Destructor

D. Painter

36. Which method is responsible for cleaning up resources before an applet


is unloaded?
A. init()

B. start()

C. stop()

D. destroy()

37. What is the expected output when the init() method is called?

A. start() called

B. init() called

C. paint() called

D. stop() called

38. What is the purpose of the applet’s life cycle methods?

A. To handle network connections

B. To manage user input

C. To control the applet’s execution flow

D. To store applet data

39. Which method is called when the applet is no longer needed?

A. init()

B. start()

C. stop()

D. destroy()

40. What happens when the paint() method is called again?

A. The applet is stopped

B. The applet is repainted

C. The applet is initialized


D. The applet is destroyed

41. What is the last method called in the applet life cycle?

A. init()

B. start()

C. stop()

D. destroy()

42. What is the purpose of the applet’s life cycle methods?

A. To handle network connections

B. To manage user input

C. To control the applet’s execution flow

D. To store applet data

43. Which method is called when the applet is no longer needed?

A. init()

B. start()

C. stop()

D. destroy()

44. What happens when the paint() method is called again?

A. The applet is stopped

B. The applet is repainted

C. The applet is initialized

D. The applet is destroyed

45. What is the last method called in the applet life cycle?
A. init()

B. start()

C. stop()

D. destroy()

46. What is the purpose of the applet’s life cycle methods?

A. To handle network connections

B. To manage user input

C. To control the applet’s execution flow

D. To store applet data

47. Which method is called when the applet is no longer needed?

A. init()

B. start()

C. stop()

D. destroy()

48. What happens when the paint() method is called again?

A. The applet is stopped

B. The applet is repainted

C. The applet is initialized

D. The applet is destroyed

49. What is the last method called in the applet life cycle?

A. init()

B. start()

C. stop()
D. destroy()

50. What is the purpose of the destroy() method in an applet?

A. To draw graphics on the applet

B. To initialize the applet

C. To clean up resources before the applet is destroyed

D. To handle user input

51. What is the purpose of the destroy() method in an applet?

A. To draw graphics on the applet

B. To initialize the applet

C. To clean up resources before the applet is destroyed

D. To handle user input

52. Which HTML tag is used to embed an applet in a webpage?

A. <applet>

B. <object>

C. <embed>

D. <iframe>

53. Which HTML tag is used to embed an applet in a webpage?

A. <applet>

B. <object>

C. <embed>

D. <iframe>

54. What does the Math.random() method return?


A. A random string

B. A random double value between 0.0 and 1.0

C. A random integer

D. A random boolean value

55. What does the Math.random() method return?

A. A random string

B. A random double value between 0.0 and 1.0

C. A random integer

D. A random boolean value

56. How often is the repaint method called in the described program?

A. Every 500 ms

B. Every 2000 ms

C. Every 1000 ms

D. Every 3000 ms

57. What is the maximum number of random locations the string ‘java’ can
be drawn in one call of the paint method?

A. 20

B. 40

C. 60

D. 80

58. What is the maximum number of random locations the string ‘java’ can
be drawn in one call of the paint method?

A. 20
B. 40

C. 60

D. 80

59. What is the purpose of the drawJava() method?

A. To clear the screen

B. To generate random numbers

C. To write the string ‘java’ on random locations

D. To initialize the applet

60. What is the range of random numbers generated by the expression (int)
(Math.random() * 5)?

A. 0 to 4

B. 0 to 5

C. 1 to 5

D. 1 to 4

61. What is the width of the applet as specified in the HTML code?

A. 150

B. 100

C. 200

D. 250

62. What is the width of the applet as specified in the HTML code?

A. 150

B. 100

C. 200
D. 250

63. What happens after 10 calls to repaint in the program?

A. The applet is destroyed

B. The applet stops responding

C. The screen is cleared

D. The applet is resized

64. Which of the following is NOT a part of the applet life cycle?

A. init()

B. start()

C. stop()

D. execute()

65. What is the height of the applet as specified in the HTML code?

A. 200

B. 150

C. 100

D. 300

66. What type of graphics context is used in the drawJava() method?

A. Graphics2D

B. Canvas

C. Graphics

D. Image

67. What is the height of the applet as specified in the HTML code?
A. 200

B. 150

C. 100

D. 300

68. What type of graphics context is used in the drawJava() method?

A. Graphics2D

B. Canvas

C. Graphics

D. Image

69. What is the primary function of the appletviewer command?

A. To debug Java applications

B. To compile Java code

C. To execute applets

D. To create applet files

70. How many different fonts are randomly selected for drawing the string
‘java’?

A. 4

B. 3

C. 2

D. 5

71. What is the primary function of the appletviewer command?

A. To debug Java applications

B. To compile Java code


C. To execute applets

D. To create applet files

72. How many different fonts are randomly selected for drawing the string
‘java’?

A. 4

B. 3

C. 2

D. 5

73. What is the purpose of the applet’s console output during experiments?

A. To log user interactions

B. To display errors

C. To show the applet’s life cycle

D. To provide performance metrics

74. What does the term ‘panel height’ refer to in the context of the
drawJava() method?

A. The height of the browser window

B. The height of the applet window

C. The height of the drawing area

D. The height of the HTML document

75. What is the significance of the RGB color model in the drawing process?

A. It defines the applet’s background color

B. It determines the font style

C. It selects colors for drawing


D. It sets the applet’s dimensions

76. What is the expected output of the program when executed?

A. A series of random strings

B. An animated display of the string ‘java’

C. A static image

D. A compilation error

77. What is the significance of the RGB color model in the drawing process?

A. It defines the applet’s background color

B. It determines the font style

C. It selects colors for drawing

D. It sets the applet’s dimensions

78. What is the expected output of the program when executed?

A. A series of random strings

B. An animated display of the string ‘java’

C. A static image

D. A compilation error

79. What does the method chooseColor() do in the provided code?

A. It selects a random font

B. It draws a string on the screen

C. It generates a random color

D. It clears the graphics context


80. How many different fonts can be randomly selected by the chooseFont()
method?

A. 2

B. 4

C. 3

D. 5

81. What is the purpose of the paint() method in the code?

A. To choose a random color

B. To initialize the graphics context

C. To draw the string ‘java’ at random locations

D. To clear the screen

82. In the chooseFont() method, which font style is used for the ‘Serif’ font?

A. Plain

B. Bold

C. Italic

D. Bold + Italic

83. What is the maximum value for the RGB color components generated in
chooseColor()?

A. 256

B. 700

C. 255

D. 1000

84. What is the maximum value for the RGB color components generated in
chooseColor()?
A. 256

B. 700

C. 255

D. 1000

85. What happens when the clearCounter reaches 10 in the paint() method?

A. The screen is cleared

B. The program terminates

C. A new font is chosen

D. The color is reset

86. Which method is responsible for drawing the string ‘java’ on the graphics
context?

A. chooseFont()

B. drawJava()

C. chooseColor()

D. paint()

87. What type of object does the chooseFont() method return?

A. Color

B. Font

C. Graphics

D. String

88. How many times does the loop in the paint() method iterate to draw the
string ‘java’?

A. 20
B. 40

C. 30

D. 50

89. What is the purpose of the Graphics2D object in the paint() method?

A. To perform advanced 2D graphics operations

B. To set the color for drawing

C. To create a new font

D. To clear the screen

90. Which method is called to set the color before drawing the string?

A. chooseColor()

B. drawJava()

C. setColor()

D. paint()

91. What is the range of random values generated for the fontChoice
variable in chooseFont()?

A. 1 to 3

B. 1 to 4

C. 0 to 3

D. 0 to 4

92. Which color model is used in the chooseColor() method?

A. RGB

B. HSV

C. CMYK
D. HSL

93. What does the method drawJava() do?

A. It generates a random color

B. It selects a random font

C. It draws the string ‘java’

D. It clears the graphics context

94. What is the initial value of the clearCounter variable in the paint()
method?

A. 1

B. 10

C. 0

D. 40

95. Which color model is used in the chooseColor() method?

A. RGB

B. HSV

C. CMYK

D. HSL

96. What does the method drawJava() do?

A. It generates a random color

B. It selects a random font

C. It draws the string ‘java’

D. It clears the graphics context


97. What is the initial value of the clearCounter variable in the paint()
method?

A. 1

B. 10

C. 0

D. 40

98. What type of loop is used in the paint() method to draw the strings?

A. For loop

B. While loop

C. Do-while loop

D. Nested loop

99. What happens if the paint() method is called more than 10 times?

A. The program crashes

B. The screen is cleared

C. No action is taken

D. A new string is drawn

100. Which of the following is NOT a font type used in the chooseFont()
method?

A. Serif

B. SansSerif

C. Monospaced

D. Arial

101. Which of the following is NOT a font type used in the chooseFont()
method?
A. Serif

B. SansSerif

C. Monospaced

D. Arial

102. What is the purpose of the random number generation in the


chooseColor() method?

A. To determine the position of the string

B. To create RGB color values

C. To select a font

D. To set the size of the string

103. What is the purpose of the Timer in the JavaAnim class?

A. To count the number of times paint is called

B. To schedule the repainting of the applet

C. To manage user input events

D. To change the background color

104. Which method is overridden to perform custom painting in the JavaAnim


applet?

A. paint()

B. init()

C. actionPerformed()

D. chooseColor()

105. What color is set as the background in the init() method?

A. Black
B. White

C. Blue

D. Green

106. How often does the Timer trigger the actionPerformed method?

A. Every 2000 milliseconds

B. Every 1000 milliseconds

C. Every 500 milliseconds

D. Every 300 milliseconds

107. How often does the Timer trigger the actionPerformed method?

A. Every 2000 milliseconds

B. Every 1000 milliseconds

C. Every 500 milliseconds

D. Every 300 milliseconds

108. What does the chooseColor() method return?

A. A random string

B. A random color

C. A random font

D. A random integer

109. What is the maximum number of times the clearRect method is called
before the clearCounter resets?

A. 10

B. 15

C. 5
D. 20

110. What does the chooseColor() method return?

A. A random string

B. A random color

C. A random font

D. A random integer

111. What is the maximum number of times the clearRect method is called
before the clearCounter resets?

A. 10

B. 15

C. 5

D. 20

112. Which font style is NOT used in the chooseFont() method?

A. Italic

B. Underline

C. Bold

D. Plain

113. What is drawn on the applet using the drawJava() method?

A. The word ‘Java’

B. A rectangle

C. A circle

D. A line
114. What is the purpose of the actionPerformed method in the JavaAnim
class?

A. To initialize the applet

B. To handle user input

C. To repaint the applet

D. To choose a random color

115. In the HTML file, what is the width of the applet specified as?

A. 1000

B. 800

C. 1200

D. 700

116. In the HTML file, what is the width of the applet specified as?

A. 1000

B. 800

C. 1200

D. 700

117. What does the clearRect method do in the paint method?

A. Draws a rectangle

B. Changes the color

C. Clears a specified area

D. Sets the font

118. Which class does JavaAnim extend?

A. JFrame
B. JApplet

C. JPanel

D. JComponent

119. What is the range of random values used for generating colors in
chooseColor()?

A. 0 to 255

B. 0 to 100

C. 0 to 200

D. 0 to 300

120. What is the main purpose of the JavaAnim applet?

A. To display static text

B. To create an animated display of the word ‘java’

C. To handle user input

D. To manage database connections

121. What is the height of the applet specified in the HTML file?

A. 700

B. 500

C. 600

D. 800

122. Which method is responsible for choosing a random font in the


JavaAnim class?

A. chooseFont()

B. init()
C. chooseColor()

D. drawJava()

123. What happens when clearCounter reaches 10 in the paint method?

A. The drawing area is cleared

B. The background color changes

C. The applet stops running

D. The font changes

124. What is the main component used for drawing in the paint method?

A. Graphics

B. Graphics2D

C. Canvas

D. Image

125. What is the default font size used in the ‘SansSerif’ font option?

A. 17

B. 15

C. 20

D. 23

1. A

2. B

3. C

4. B
5. A

6. C

7. A

8. C

9. C

10. Invalid Answer Index

11. C

12. A

13. B

14. B

15. A

16. B

17. B
18. A

19. C

20. C

21. B

22. A

23. A

24. A

25. A

26. Invalid Answer Index

27. D

28. Invalid Answer Index

29. D

30. A

31. B
32. C

33. C

34. A

35. A

36. D

37. B

38. C

39. D

40. B

41. D

42. C

43. D

44. B
45. D

46. C

47. D

48. B

49. D

50. C

51. C

52. Invalid Answer Index

53. Invalid Answer Index

54. B

55. B

56. C

57. B

58. B
59. C

60. A

61. A

62. A

63. C

64. D

65. C

66. A

67. C

68. A

69. C

70. A

71. C
72. A

73. C

74. C

75. C

76. B

77. C

78. B

79. C

80. B

81. C

82. D

83. C

84. C

85. A
86. B

87. B

88. B

89. A

90. C

91. B

92. A

93. C

94. C

95. A

96. C

97. C

98. A
99. B

100. D

101. D

102. B

103. B

104. A

105. A

106. B

107. B

108. B

109. A

110. B

111. A

112. B
113. A

114. C

115. A

116. A

117. C

118. B

119. A

120. B

121. A

122. A

123. A

124. B

125. A

You might also like