Programming In Java Week 8 NPTEL Assignment Answers 2025

NPTEL Programming In Java Week 8 Assignment Answers 2024

1. What does AWT stand for in Java?
a. Applet Windowing Toolkit
b. Abstract Window Toolkit
c. Absolute Windowing Toolkit
d. None of the above

Answer: b
Explanation: AWT stands for Abstract Window Toolkit. It is a part of Java used to develop GUI applications.


2. When we invoke repaint() for a java.awt.Component object, the AWT invokes which of the following method?
a. draw()
b. show()
c. update()
d. none of the mentioned

Answer: c
Explanation: The repaint() method internally calls the update() method, which in turn calls the paint() method to redraw the component.


**3. Which is/are used to create a Frame?

  1. By creating the object of Frame class (association)
  2. By extending Frame class (inheritance)**

a. Only 1
b. Only 2
c. Both
d. None

Answer: c
Explanation: You can create a Frame either by instantiating the Frame class or by extending it, both are valid approaches.


4. Which AWT concept allows you to handle events such as button clicks or mouse movements?
a. Event Handling
b. Component Interaction
c. Process Management
d. GUI Processing

Answer: a
Explanation: Event Handling in AWT enables developers to respond to user actions like clicks, key presses, or mouse movements.


5. Which of the following methods can be used to change the size of a java.awt.Component object?

  1. dimension()
  2. setSize()
  3. area()
  4. size()
  5. resetSize()**

a. 1, 2, 3 & 5
b. 4 & 5
c. 1, 2 & 5
d. only 2

Answer: d
Explanation: setSize() is the only valid method among the options provided to change the size of a component in AWT.


6. Which of the following is TRUE regarding checkbox and radio button?
a. Checkbox is used for single selection item whereas radio button is used for multiple selection.
b. Checkbox is used for multiple selection items whereas radio button is used for single selection.
c. Both are used for multiple as well as single item selection.
d. Checkbox is the same as radio buttons.

Answer: b
Explanation: Checkboxes allow multiple selections while radio buttons allow only one selection from a group.


7. How is AWT different from Swing in Java?
a. AWT is for web applications, Swing is for desktop applications
b. AWT uses lightweight components, Swing uses heavyweight components
c. AWT is newer than Swing
d. AWT and Swing are synonyms, used interchangeably

Answer: b
Explanation: AWT uses heavyweight components dependent on native code, while Swing components are lightweight and written in Java.


8. What is the primary purpose of AWT components in GUI programming?
a. To perform mathematical calculations
b. To interact with databases
c. To create graphical user interfaces
d. To handle network communications

Answer: c
Explanation: AWT provides tools and components to build graphical user interfaces like buttons, labels, and windows.


9. What will be the output of the Java code given below?
a. A frame with a button “NPTEL – Programming in Java” at coordinates (30, 50)
b. Compilation error
c. An empty frame with no button
d. A frame with a button, but not at the specified coordinates

Answer: a
Explanation: The code correctly creates a button and sets its location using setBounds(30, 50, ...), so it will appear at the specified coordinates.


10. What is the layout manager used in the Java code given below?
a. Border Layout
b. Flow Layout
c. Grid Layout
d. Card Layout

Answer: c
Explanation: The code makes use of the GridLayout, which arranges components in a grid with equal-sized cells.