CBSE Class 12 Informatics Practices Java GUI Programming Revision Tour Assignment

Download CBSE Class 12 Informatics Practices Assignments

Review targeted academic assignments with the CBSE Class 12 Informatics Practices Java GUI Programming Revision Tour Assignment. Built according to official CBSE standards for the 2026-27 term, these downloadable Class 12 Informatics Practices worksheets support effective daily practice for Java Gui Programming.

Access CBSE School Assignments and Answers

Access the complete assignment PDF for Class 12 Informatics Practices below. Regular practice with these targeted academic tasks builds familiarity with standard question patterns and helps secure higher marks in final school evaluations.

Question 1. State the output of the following program: public static void main(String args[ ]) { int x = 10; float y = 10.0; System.out.println((x>y)? true: false); }
Answer: false
In simple words: The ternary operator checks if 10 is greater than 10.0, which is false, so it prints false.

Exam Tip: Be careful with numeric comparisons between integer and floating-point types in Java expressions.

 

Question 2. Given a package named EDU.student, how would you import a class named Test contained in this package? Write one line statement.
Answer: import EDU.student.Test;
In simple words: Use the import keyword followed by the full package path and class name.

Exam Tip: Remember to put a semicolon at the end of every import statement.

 

Question 3. Consider the following class definition: Class Student { abstract double result( ) } This code will not compile since a keyword is missing in the first line. What is the keyword?
Answer: abstract
In simple words: An abstract method can only exist inside an abstract class, so the class must be declared as abstract.

Exam Tip: Always check if a class containing abstract methods is also marked with the abstract modifier.

 

Question 4. Can an abstract method be declared final? Yes or No.
Answer: No
In simple words: Abstract methods must be overridden by subclasses, whereas final methods cannot be overridden, making them mutually exclusive.

Exam Tip: Modifiers final and abstract cannot be used together for methods or classes.

 

CHAPTER-4 JAVA GUI PROGRAMMING REVISION TOUR - II [Swing Controls]

 

Question 1. What does getPassword() on a password field return?
(a) a string
(b) an integer
(c) a character array.
Answer: (c) a character array.
The getPassword() method in JPasswordField returns an array of characters for security reasons so that password strings can be cleared from memory easily.
In simple words: It returns characters instead of a String to keep passwords secure.

Exam Tip: Remember that JPasswordField.getPassword() returns char[] and not String.

 

Question 2. Which of the following component is the best suited to accept the country of the user?
A. List
B. Combo box
C. Radio button
D. Check box
Answer: B. Combo box
A combo box takes up minimal space and is ideal for selecting a single item from a large preset list like countries.
In simple words: A combo box is best for dropdown single-selection lists.

Exam Tip: Combo boxes are best when space is constrained and a single choice is required from many options.

 

Question 3. What command do you need to write in actionPerformed() event handler of a button, in order to make it exit button?
a. System.out.println();
b. System.exit(0);
c. System.out.print()
Answer: b. System.exit(0);
System.exit(0) terminates the currently running Java Virtual Machine and closes the application.
In simple words: System.exit(0) shuts down the program completely.

Exam Tip: Parameter 0 in System.exit(0) indicates normal termination without errors.

 

Question 4. What method would you use, in order to simulate a button's (namely Okbtn) click event, without any mouse activity from user's side?
a. Okbtn.setText()
b. Okbtn.getText()
c. Okbtn.doClick()
Answer: c. Okbtn.doClick()
The doClick() method programmatically triggers a click event on a button component.
In simple words: doClick() performs a click action via code.

Exam Tip: doClick() is useful for keyboard shortcuts or automated form submissions.

 

Question 5. What would be the name of the event handler method in the ListSelection listener interface for a list namely CheckList to handle its item selections?
a. CheckListValueChanged()
b. getSelectedValue()
c. clearSelection()
Answer: a. CheckListValueChanged()
List selection events are handled using valueChanged methods, named according to the component prefix.
In simple words: ValueChanged is the naming convention for list selection handlers.

Exam Tip: Pay attention to the listener interface names and their corresponding event-handling method signatures.

 

Question 6. Which control displays text that the user cannot directly change or edit?
a. TextField
b. Checkbox
c. Combobox
d. Label
Answer: d. Label
A JLabel component is specifically designed for displaying static text or images that the user cannot edit.
In simple words: Labels show read-only text.

Exam Tip: Use JLabel when you want descriptive uneditable text on your form.

 

Question 7. Which control provides basic text editing facility?
a. TextField
b. Checkbox
c. Combobox
d. Label
Answer: a. TextField
JTextField allows the user to type and edit a single line of text.
In simple words: Text fields let users type and edit text.

Exam Tip: JTextField is for single-line text input, while JTextArea is for multiple lines.

 

Question 8. Occurrence of an activity is called:
a. Function
b. Class
c. Object
d. Event
Answer: d. Event
An event represents an action or occurrence recognized by the GUI program, such as a button click or key press.
In simple words: Events are actions that trigger program responses.

Exam Tip: GUI programming is heavily event-driven.

 

Question 9. Which property is used to set the text of the Label?
a. font
b. text
c. name
d. icon
Answer: b. text
The text property holds the string displayed by a label component.
In simple words: The text property defines what the label says.

Exam Tip: You can change a label's text at runtime using setText("string").

 

Question 10. The object containing the data to be exhibited by the combo box by which property.
a. editable
b. model
c. selectedIndex
d. selectedItem
Answer: b. model
The model property manages the collection of items displayed in a combo box or list.
In simple words: The model holds the list items.

Exam Tip: DefaultComboBoxModel is typically used to populate combo box items programmatically.

 

Question 11. What is GUI programming?
Answer: A GUI (Graphical User Interface) is an interface that uses pictures and other graphic entities along with text, to interact with the user.
In simple words: GUI programming creates graphical windows and buttons for user interaction.

Exam Tip: GUI applications make software user-friendly compared to command-line interfaces.

 

Question 12. How is swing related to GUI programming?
Answer: We can create a GUI application on the Java platform using Swing API (Application Programming Interface), which is part of Java Foundation Classes (JFC).
In simple words: Swing is Java's library for building graphical user interfaces.

Exam Tip: Swing components start with the letter 'J' (e.g., JFrame, JButton, JLabel).

 

Question 13. What is an event? What is event handler?
Answer: An event is the occurrence of some activity either initiated by the user or by the system. Important components in Event Handling include:
1. Event Source: The GUI component that generates the event, e.g., Button.
2. Event Handler or Event Listener: Code that receives and handles events through Listener Interfaces.
3. Event Object or Message: Created when an event occurs, containing information about the event.
In simple words: Events are actions, and handlers are pieces of code that respond to them.

Exam Tip: Always distinguish between the event source, the event object, and the listener/handler.

 

Question 14. What is the default name of action event handler of a button namely TestBtn?
Answer: private void TestBtnActionPerformed(java.awt.event.ActionEvent evt) { }
In simple words: NetBeans automatically names button event handlers using component name plus ActionPerformed.

Exam Tip: Default naming conventions help identify component event methods easily in IDEs.

 

Question 15. What property would you set to assign access key to a button?
Answer: Mnemonic property is used to assign access key or shortcut (Alt + Key).
In simple words: The mnemonic property sets keyboard shortcuts for buttons.

Exam Tip: Mnemonics allow users to activate buttons using Alt combined with a designated letter key.

 

Question 16. Which method can programmatically perform the click action of a push button?
Answer: doClick()
In simple words: Calling doClick() simulates a user clicking the button.

Exam Tip: doClick() invokes the button's action listener programmatically.

 

Question 17. Which property would you set the setting the password character as '$'?
Answer: echoChar
In simple words: echoChar defines the mask character displayed in password fields.

Exam Tip: The default echo character in Java password fields is usually an asterisk (*).

 

Question 18. Which method returns the password entered in a password field?
Answer: char [ ] getPassword()
In simple words: getPassword() retrieves the typed password characters.

Exam Tip: Use new String(passwordField.getPassword()) if you need to convert the character array to a String for validation.

 

Question 19. Which list property do you set for specifying the items for the list.
Answer: model
In simple words: The model property defines the items shown in a list.

Exam Tip: You can configure list elements via the model property dialog in NetBeans.

 

Question 20. Which method would you use to determine the index of selected item in a list?
Answer: int getSelectedIndex()
In simple words: getSelectedIndex() returns the numeric position of the selected item.

Exam Tip: List indices start at 0. If nothing is selected, getSelectedIndex() returns -1.

 

Question 21. Which method would you use to insert an item at specified index, in the list?
Answer: void setSelectedIndext(int index) (Note: Model methods like addElement or insertElementAt are typically used on list models, but setSelectedIndices/Index sets selection).
In simple words: List models handle inserting items into lists.

Exam Tip: Always interact with the list model when adding or removing items dynamically.

 

Question 22. How you can determine whether 5th item in a list is selected or not?
Answer: isSelectedIndex(4)
In simple words: Use index 4 to check the 5th item since indices start at 0.

Exam Tip: Remember that item positions are 0-indexed in Java.

 

Question 23. Which method you would use to insert 'Hello' at 10th position in the Text Area control.
Answer: void insert("Hello", 9)
In simple words: insert() places text at a specific character offset.

Exam Tip: Character offsets in text components are also 0-indexed.

 

Question 24. Which method you would like to use to insert an Icon (picture) on a Push Button.
Answer: void setIcon(Icon)
In simple words: setIcon() adds images to buttons.

Exam Tip: You can pass an ImageIcon object to the setIcon() method.

 

Question 25. Which property would you like to set to make a Combo box editable?
Answer: editable
In simple words: Setting editable to true lets users type custom values into a combo box.

Exam Tip: By default, combo boxes are non-editable (dropdown only).

 

Question 26. What is Layout Manager? Name the layout managers offered by NetBeans?
Answer: Layout managers enable you to control the way in which visual components are arranged in GUI forms by determining the size and position of components within containers.
Seven types of layout available:
1. Flow Layout
2. Grid Layout
3. Card Layout
4. Spring Layout
5. Border Layout
6. GridBag Layout
7. Box Layout
In simple words: Layout managers automatically organize GUI component positions and sizes.

Exam Tip: FlowLayout arranges components left to right, while BorderLayout uses North, South, East, West, and Center regions.

 

Question 27. Name three commonly used properties and methods of the following controls: (a) text field (b) text area (c) Check Box
Answer:
(a) Properties: text, font, editable. Methods: void setText(), String getText(), void setEditable(boolean).
(b) Properties: enabled, editable, wrapStyleWord. Methods: setText(), getText(), isEditable().
(c) Properties: font, text, selected. Methods: getText(), isEnabled(), isSelected().
In simple words: Each control has specific properties for appearance and methods for manipulation.

Exam Tip: Learn standard getter and setter method prefixes (get, set, is).

 

Question 28. What is dispose() used for?
Answer: dispose() is used to hide and dispose of the frame when the user closes it. This removes the frame from the screen and frees up any resources used by it.
In simple words: dispose() closes windows and releases memory resources.

Exam Tip: setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE) is commonly used for secondary windows.

 

Question 29. What is the difference between-(a) Text field & Text area (b) Text field & password field (c) Radio Button & Check Box
Answer:
(a) A text field's text property can hold a single line of text unless it is an HTML text. While a text area's text can hold any number of lines of text depending upon its rows property.
(b) A password field displays the obtained text in encrypted form on screen while a text field displays text in unencrypted form.
(c) Radio Button: Used to get choices from the user where only one can be selected at a time among a group (kept in ButtonGroup).
Check box: Indicates whether a particular condition is on or off, operating independently so any number can be selected at the same time.
In simple words: Text fields are single-line, password fields hide text, radio buttons allow single selection, and checkboxes allow multiple selections.

Exam Tip: Always group JRadioButtons using a ButtonGroup object so exclusive selection works properly.

 

Question 30. What is the significance of following properties of a text area? (a) lineWrap (b) wrapStyleWord
Answer:
(a) lineWrap: Defines wrapping feature enable/disable. Determines where line wrapping occurs.
(b) wrapStyleWord: Determines whether line wrapping occurs at word boundaries when lineWrap is true. This property is ignored unless lineWrap is set to true.
In simple words: lineWrap wraps long text to the next line, and wrapStyleWord ensures words aren't split in the middle.

Exam Tip: Set both lineWrap and wrapStyleWord to true for neat multi-line text display.

 

Question 31. What is the significance of a button group? How do you create a button group?
Answer: We must add a ButtonGroup control to the frame to group radio buttons or check boxes so that mutually exclusive selection can be enforced. It is created by dragging the button group control from the palette window in NetBeans.
In simple words: Button groups ensure only one radio button can be selected at a time.

Exam Tip: ButtonGroup is a logical container and is not added directly to the visual JFrame layout.

 

Question 32. What do you understand by focus?
Answer: Focus is the ability to receive user input/response through Mouse or Keyboard. When an object or control has focus, it can receive input from user. An object or control can receive focus only if its enabled and visible properties are set to true. Most controls provide FOCUS_GAINED() and FOCUS_LOST() methods in FocusEvent through FocusListener. FOCUS_LOST() is generally used for validation of data. You can give focus to an object at runtime by invoking the requestFocus() method in the code, e.g., jTextBox2.requestFocus();
In simple words: Focus determines which component receives keyboard and mouse input.

Exam Tip: FOCUS_LOST is ideal for real-time text input validation (like checking if an entered email is valid).

 

Question 33. What is meant by scope of a variable?
Answer: In Java, a variable can be declared anywhere in the program but before using them. The area of a program within which a variable is accessible is known as its scope. A variable can be accessed within the block where it is declared.
In simple words: Scope defines the region of code where a variable can be accessed.

Exam Tip: Variables declared inside a block (such as inside an if statement) cannot be accessed outside that block.

 

Question 34. Create a Java Desktop Application to find the incentive (%) of Sales for a Sales Person on the basis of following feedbacks: Maximum Sales: 10%, Excellent Customer Feedback: 8%, Maximum Count Customer: 5%. Note that the sales entry should not be space. Calculate the total incentive as: Sales amount * Incentive. The feedback will be implemented in JCheckBox controls. Using a JButton's (Compute Incentive) click event handler, display the total incentives in a JTextField control.
Answer:
private void btnIncActionPerformed(java.awt.event.ActionEvent evt) {
int sales = 0;
if (!txtSales.getText().trim().equals("")) {
sales = Integer.parseInt(txtSales.getText().trim());
}
double incentive = 0.0;
if (jCheckBox1.isSelected()) {
incentive = incentive + 0.1;
}
if (jCheckBox2.isSelected()) {
incentive = incentive + 0.8;
}
if (jCheckBox3.isSelected()) {
incentive = incentive + 0.05;
}
txtInc.setText("" + Math.round(sales * incentive));
}
In simple words: The code checks selected checkboxes, sums up the incentive percentages, multiplies by sales amount, and displays the result.

Exam Tip: Always trim text inputs and check for empty strings to prevent NumberFormatException.

 

Question 35. Assume the following interface built using NetBeans used for bill calculation of an ice-cream parlor. The parlor offers three varieties of ice-cream - vanilla, strawberry, chocolate. Vanilla ice-cream costs Rs. 30, Strawberry Rs. 35 and Chocolate Rs. 50. A customer can choose one or more ice-creams, with quantities more than one for each of the variety chosen. Write Java code for the following: (a) On click event of Calculate, find and display total bill and rates. (b) Clear button clears all text fields and checkboxes. (c) Close button closes the application.
Answer:
(a) private void jBtncalculateActionPerformed(java.awt.event.ActionEvent evt) {
if(jchkStrawberry.isSelected()==true)
jTxtPriceStrawberry.setText("35");
else {
jTxtPriceStrawberry.setText("0");
jTxtQtyStrawberry.setText("0");
}
if(jChkChocolate.isSelected()==true)
jTxtPriceChocolate.setText("50");
else {
jTxtPriceChocolate.setText("0");
jTxtQtyChocolate.setText("0");
}
if(jChkVinella.isSelected()==true)
jtxtPriceVinella.setText("30");
else {
jtxtPriceVinella.setText("0");
jTxtQtyVinella.setText("0");
}
int r1,r2,r3,q1,q2,q3,a1,a2,a3,gt;
r1=Integer.parseInt(jTxtPriceStrawberry.getText());
r2=Integer.parseInt(jTxtPriceChocolate.getText());
r3=Integer.parseInt(jtxtPriceVinella.getText());
q1=Integer.parseInt(jTxtQtyStrawberry.getText());
q2=Integer.parseInt(jTxtQtyChocolate.getText());
q3=Integer.parseInt(jTxtQtyVinella.getText());
a1=r1*q1;

jTxtAmtStrawberry.setText(""+a1);
a2=r2*q2;
jTxtAmtChocolate.setText(""+a2);
a3=r3*q3;
jTxtAmtVinella.setText(""+a3);
gt=a1+a2+a3;
jTxtTotalAmt.setText(""+gt);
}

(b) private void jBtnClearActionPerformed(java.awt.event.ActionEvent evt) {
jTxtPriceStrawberry.setText("");
jTxtPriceChocolate.setText("");
jtxtPriceVinella.setText("");
jTxtQtyStrawberry.setText("");
jTxtQtyChocolate.setText("");
jTxtQtyVinella.setText("");
jTxtAmtStrawberry.setText("");
jTxtAmtChocolate.setText("");
jTxtAmtVinella.setText("");
jchkStrawberry.setSelected(false);
jChkChocolate.setSelected(false);
jChkVinella.setSelected(false);
}

(c) private void jBtncloseActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
In simple words: This code calculates individual item totals, grand totals, clears fields on reset, and exits on close.

Exam Tip: Validate that quantity fields contain valid numbers before parsing to avoid runtime crashes.

 

Question 36. Read the following case study and answer the questions that follow. TeachWell Public School wants to computerize the employee salary section. Categories: Teaching and Non Teaching. Teaching: PGTs, TGTs, PRTs. Additional pay of 3000 for > 10 years experience. (a) Code to calculate Basic salary, deductions, gross salary, net salary. Add 3000 if experience > 10 years. (b) Exit application. (c) Disable textfields for gross salary, deductions, net salary.
Answer:
(a)
double bs=0, da=0, net=0, ded=0, gross=0, hra=0;
if (rdnon.isSelected()==true) {
bs=12500;
da=(31*bs)/100;
hra=(30*bs)/100;
ded=(12*bs)/100;
}
else if (rdpgt.isSelected()==true) {
bs=14500;
da=(30*bs)/100;
hra=(30*bs)/100;
ded=(12*bs)/100;
}
else if (rdtgt.isSelected()==true) {
bs=12500;
da=(21*bs)/100;
hra=(30*bs)/100;
ded=(12*bs)/100;
}
else if (rdprt.isSelected()==true) {
bs=11500;
da=(20*bs)/100;
hra=(25*bs)/100;
ded=(12*bs)/100;
}
gross=bs+da+hra;
net = gross - ded;
if(chk10.isSelected()==true) {
net=net+3000;
}
tfded.setText(""+ded);
tfgross.setText(""+gross);
tfnet.setText(""+net);
tfbs.setText(""+bs);

(b)
System.exit(0);

(c)
tfgross.setEditable(false);
tfded.setEditable(false);
tfnet.setEditable(false);
In simple words: The code computes salary components based on radio button selections, adds experience bonus if checked, and displays results in read-only fields.

Exam Tip: Use setEditable(false) to make text fields read-only so users cannot tamper with calculated outputs.

 

Question 37. ABC School uses an interface to check student stream eligibility (science, commerce, humanities). User enters total percentage and selects stream. 5% extra marks for NCC. (a) Calc Percentage button code. (b) Result button code (Min %: Science=70, Commerce=60, Humanities=40). (c) Clear button code. (d) Close button code.
Answer:
(a)
private void jBtnCalcPerActionPerformed(java.awt.event.ActionEvent evt) {
int p;
p=Integer.parseInt(jTextField2.getText());
if (jCheckBox1.isSelected())
p=p+5;
jTextField3.setText(Integer.toString(p));
}

(b)
private void jBtnResultActionPerformed(java.awt.event.ActionEvent evt) {
int p;
p=Integer.parseInt(jTextField3.getText());
if(jRadioButton1.isSelected()) {
if (p>=70)
jTextField4.setText("Eligible for all subject");
else
jTextField4.setText("Not Eligible for science");
}
else if(jRadioButton2.isSelected()) {
if (p>=60)
jTextField4.setText("Eligible for Commerce and Humanities");
else
jTextField4.setText("Not Eligible for Science and Commerce");
}
else {
if (p>=40)
jTextField4.setText("Eligible for Humanities");
else
jTextField4.setText("Not Eligible for any subject");
}
}

(c)
private void jBtnClearActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jCheckBox1.setSelected(false);
}

(d)
private void jBtnCloseActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
In simple words: This code calculates net percentage with NCC bonus, checks stream cutoff percentages, clears fields, and exits.

Exam Tip: Nested if-else statements are very useful for checking multiple conditional criteria like stream cutoffs.

 

Unsolved Questions (Solutions)

 

Question 1. Describe the relationship between properties, methods and events.
Answer: Properties define the state and appearance of a GUI component (such as text, color, or enabled status). Methods are functions that define the behavior or actions a component can perform (such as setText() or requestFocus()). Events are occurrences or actions triggered by the user or system (such as a button click), which are handled by methods called event handlers.
In simple words: Properties store data, methods perform actions, and events trigger methods when user interactions happen.

Exam Tip: Properties = Attributes, Methods = Actions, Events = Triggers.

 

Question 2. What is container tag?
Answer: In GUI programming, a container component (or container control) is a Swing component that can hold other GUI components, such as panels, buttons, and labels. Examples include JFrame, JPanel, and JWindow.
In simple words: Container tags or components are components that hold other UI elements inside them.

Exam Tip: Containers manage layouts and component hierarchies in user interfaces.

 

Question 3. What does a getPassword() method of a password field returns?
Answer: It returns a character array (char[ ]) containing the characters typed into the password field.
In simple words: It returns password characters as an array.

Exam Tip: Returning char[] instead of String prevents plain-text password strings from lingering in memory strings pools.

 

Question 4. What will be the contents of jTextArea1 after executing the following statement: jTextArea1.setText("Object\nOriented\tProgramming");
Answer:
Object
Oriented Programming
In simple words: \n moves to a new line and \t inserts a tab space.

Exam Tip: Escape sequences like \n and \t work inside string literals in Java text areas.

 

Question 5. What is difference between jRadioButton and jCheckBox?
Answer: JRadioButton allows only one option to be selected from a mutually exclusive group (when placed in a ButtonGroup). JCheckBox represents an independent on/off option where multiple checkboxes can be selected simultaneously.
In simple words: Radio buttons allow single choice among many, while checkboxes allow multiple choices.

Exam Tip: Always use ButtonGroup with JRadioButtons.

 

Question 6. What does a JList fire when a user selects an item?
Answer: A JList fires a ListSelectionEvent, which is handled by registered ListSelectionListeners implementing the valueChanged() method.
In simple words: JList fires a ListSelectionEvent upon item selection.

Exam Tip: List selection events can fire twice during a selection change (adjusting state), so check getValueIsAdjusting() if necessary.

 

Question 7. What is Layout Manager? Discuss briefly about layout managers offered by NetBeans?
Answer: A Layout Manager is an automated mechanism in Java Swing that governs the positioning and sizing of components within a container. Commonly offered layout managers include:
- FlowLayout: Arranges components in a line, one after another.
- BorderLayout: Divides container into five regions (North, South, East, West, Center).
- GridLayout: Arranges components in a rectangular grid of equal-sized cells.
- CardLayout: Treats components like a deck of cards where only one is visible at a time.
- GridBagLayout: Complex grid layout allowing components to span multiple rows/columns.
In simple words: Layout managers automatically arrange UI components neatly across containers.

Exam Tip: BorderLayout is the default layout for JFrame content panes.

 

Question 8. Name three commonly used properties and methods of the following controls: (a) text field (b) text area (c) label (d) Check Box (e) button.
Answer:
(a) Text Field - Properties: text, font, editable. Methods: getText(), setText(), setEditable().
(b) Text Area - Properties: text, lineWrap, editable. Methods: getText(), setText(), insert().
(c) Label - Properties: text, font, icon. Methods: getText(), setText(), setIcon().
(d) Check Box - Properties: text, selected, font. Methods: isSelected(), setSelected(), getText().
(e) Button - Properties: text, font, icon. Methods: getText(), setText(), setIcon().
In simple words: Controls share common text and font properties along with specific getter/setter methods.

Exam Tip: Memorize standard Swing component properties found in the NetBeans Properties window.

 

Question 9. What is dispose() used for?
Answer: dispose() closes a window (JFrame or JDialog), hides it from the screen, and releases all native system resources allocated to it.
In simple words: dispose() frees memory by closing windows completely.

 


Question 10. What is the difference between (a) Text field & Text area (b) List & Combo (c) Radio Button & Check Box
Answer:
(a) Text field is single-line; Text area is multi-line.
(b) List displays multiple visible items allowing single or multiple selections; Combo box displays a dropdown list taking up single-line space until clicked.
(c) Radio Button permits single choice in a group; Check Box permits multiple independent choices.
In simple words: Each control pair serves different user-input patterns and visual layouts.

Exam Tip: Choose combo boxes for space-saving dropdowns and lists when multiple items should remain visible.

 

Question 11. What is the significance of following properties of a text area? (a) lineWrap (b) wrapStyleWord
Answer:
(a) lineWrap: Wraps text to the next line when it reaches the right boundary of the text area.
(b) wrapStyleWord: Ensures that word wrapping occurs at word boundaries rather than breaking mid-word.
In simple words: These properties format long text neatly inside text areas.

Exam Tip: wrapStyleWord requires lineWrap to be true to function correctly.

 

Question 12. What is the significance of a button group? How do you create a button group?
Answer: A button group logically binds radio buttons together so that selecting one automatically deselects the others. It is created in NetBeans by dragging a ButtonGroup component onto the form and assigning radio buttons to it via their buttonGroup property.
In simple words: Button groups enforce mutually exclusive radio button selections.

Exam Tip: Radio buttons without a ButtonGroup act like independent checkboxes.

 

Question 13. Discuss about some commonly used properties of lists and a combo boxes.
Answer: Common properties include model (for populating items), selectedIndex (numeric position of selection), selectedItem (value of selected item), and prototypeDisplayValue (for sizing). Combo boxes also have editable (allowing custom user typing).
In simple words: Model and selection properties manage list and combo box data.

Exam Tip: Use model methods to dynamically add or remove items at runtime.

 

Question 14. What methods obtains the current selection of a combo box? Give a code example.
Answer: getSelectedItem() or getSelectedIndex().
Example:
String selectedCountry = (String) jComboBox1.getSelectedItem();
int index = jComboBox1.getSelectedIndex();
In simple words: getSelectedItem() gives the selected value, and getSelectedIndex() gives its position number.

Exam Tip: Cast the return value of getSelectedItem() to the appropriate data type (e.g., String).

 

Question 15. The FOR U SHOP has computerized its billing. A new bill is generated for each customer. The shop allows three different payment modes (Cash, Cheque, Credit Card). Discount is given based on payment mode and shopping amount. (a) Code for CmdClear Button to clear all text fields. (b) Code for CmdCalc Button to display Discount Amount and Net Price in TxtDisc and TxtNet.
Answer:
(a) private void CmdClearActionPerformed(java.awt.event.ActionEvent evt) {
TxtShoppingAmt.setText("");
TxtDisc.setText("");
TxtNet.setText("");
buttonGroup1.clearSelection();
}

(b) private void CmdCalcActionPerformed(java.awt.event.ActionEvent evt) {
double amt = Double.parseDouble(TxtShoppingAmt.getText().trim());
double discPer = 0.0;
if (jRadioButtonCash.isSelected()) {
if (amt < 10000) discPer = 0.20;
else discPer = 0.25;
}
else if (jRadioButtonCheque.isSelected()) {
if (amt < 15000) discPer = 0.10;
else discPer = 0.15;
}
else if (jRadioButtonCredit.isSelected()) {
if (amt < 10000) discPer = 0.10;
else discPer = 0.12;
}
double discAmt = amt * discPer;
double netPrice = amt - discAmt;
TxtDisc.setText("" + discAmt);
TxtNet.setText("" + netPrice);
}
In simple words: This code calculates discounts based on payment mode and shopping amount tiers, then computes the net price.

Exam Tip: Use nested if-else structures to handle multi-tier discount tables accurately.

 

CHAPTER-5 JAVA GUI PROGRAMMING REVISION TOUR - III [Methods etc.]

 

Question 1. In java, methods reside in __________. (a) Function (b) Library (c) Classes (d) Object
Answer: (c) Classes
In object-oriented Java programming, all methods must be defined inside a class.
In simple words: Every method in Java lives inside a class.

Exam Tip: Java does not support standalone functions outside of classes.

 

Question 2. The number and type of arguments of a method are known as _____________. (a) Parameter list (b) Calling (c) Definition (d) None of the options.
Answer: (a) Parameter list
The parameter list specifies the variables accepted by a method during its declaration.
In simple words: Parameters define the inputs accepted by a method.

Exam Tip: Formal parameters appear in method definitions, while actual parameters appear in method calls.

 

Question 3. The first line of method definition that tells about the type of return value along with number and type of arguments is called _____________. (a) Class (b) Object (c) Prototype (d) Datatype
Answer: (c) Prototype
The method prototype (or signature) specifies the method name, return type, and parameter list.
In simple words: Method prototypes define the header and signature of a method.

 

Question 4. A member method having the same name as that of its class is called ____________ method. (a) Destructor (b) Constructor (c) Object (d) Variable
Answer: (b) Constructor
Constructors have the exact same name as the class and initialize newly created objects.
In simple words: Constructors share the exact name of their class.

Exam Tip: Constructors are called automatically when using the new keyword.

 

Question 5. A constructor method has __________ return type. (a) float (b) void (c) no (d) int
Answer: (c) no
Constructors do not have any return type, not even void.
In simple words: Constructors never return values, so they have no return type.

 

Question 6. A _________ constructor takes no arguments. (a) Copy constructor (b) Non-Parameterized constructor (c) Parameterized constructor
Answer: (b) Non-Parameterized constructor
A default or non-parameterized constructor accepts zero arguments.
In simple words: Non-parameterized constructors take no inputs.

Exam Tip: Java provides a default no-arg constructor automatically if no other constructors are defined.

 

Question 7. A _________ constructor creates objects through values passed to it. (a) Copy constructor (b) Default constructor (c) Parameterized constructor
Answer: (c) Parameterized constructor
Parameterized constructors accept arguments to initialize object fields with specific values.
In simple words: Parameterized constructors accept input values during object creation.

Exam Tip: Use parameterized constructors to set initial object properties immediately upon instantiation.

 

Question 8. The keyword _________ refers to current object. (a) void (b) goto (c) this (d) null
Answer: (c) this
The this keyword acts as a reference to the currently executing object.
In simple words: 'this' refers to the current object instance.

Exam Tip: 'this' is frequently used to resolve naming conflicts between instance variables and local parameters.

 

Question 9. Define a method. What is method prototype and signature?
Answer: A method is a sequence of statements that perform a specific task. A message to an object is a call to the object's method requesting that it perform some specified action.
Example:
int absval(int a) {
return (a < 0 ? -a : a);
}
The method prototype is the first line of the method definition (e.g., int absval(int a)).
In simple words: Methods are reusable blocks of code, and their prototype defines their header.

Exam Tip: Method signatures include the method name and parameter types.

 

Question 10. How are following passed in Java: (i) primitive types (ii) reference types?
Answer: (i) Primitive types are passed By Value.
(ii) Reference types are passed By Reference (passing object references by value).
In simple words: Primitives pass values, while reference types pass memory addresses.

Exam Tip: Java strictly uses pass-by-value for all arguments, but for objects, the value being passed is the object reference.

 

Question 11. The String objects being reference types are passed by reference but changes, if any, are not reflected back to them. Why?
Answer: String objects are immutable in Java, which means once they are created, their internal state cannot be changed. Therefore, any modification creates a new string object rather than altering the original.
In simple words: Strings cannot be modified after creation, so changes don't affect original variables.

Exam Tip: Use StringBuilder or StringBuffer if you need mutable strings in Java.

 

Question 12. At what time is the constructor method automatically invoked?
Answer: Every time an object is created using the new operator, the constructor method is automatically invoked.
In simple words: Constructors run automatically when an object is instantiated.

Exam Tip: You cannot call a constructor explicitly like a normal method; it runs only during object creation.

 

Question 13. What are Composite and user defined data types?
Answer: Data types that are based on fundamental or primitive data types are known as Composite Datatypes. Since these data types are created by users (such as classes and arrays), they are also known as User-Defined Datatypes.
In simple words: User-defined or composite data types build upon primitive types using classes or arrays.

Exam Tip: Classes, interfaces, and arrays are composite types in Java.

 

Question 14. Can you refer to a class as a composite type/ user-defined type?
Answer: Yes, a class is referred to as a composite type / user-defined type.
In simple words: Classes act as custom user-defined composite data types.

Exam Tip: Classes bundle data members and methods together.

 

Question 15. How is a constructor invoked?
Answer: A constructor is automatically called with the new operator in order to create a new object.
In simple words: Constructors are triggered automatically using the new keyword.

Exam Tip: Syntax: ClassName obj = new ClassName(); invokes the constructor.

 

Question 16. Which method of a class is invoked just once for an object? When?
Answer: The constructor method. It is invoked for initializing values of the object at the time of its creation.
In simple words: The constructor runs once per object during creation.

Exam Tip: Constructors execute before the object reference is returned by the new operator.

 

Question 17. Passing the address means call by value or call by reference?
Answer: Call by reference.
In simple words: Passing memory addresses is known as call by reference.

 

Question 18. What's wrong with the following constructor definition for the class PlayInfo? public void PlayInfo(int sticks) { nsticks = sticks; }
Answer: A constructor cannot have a return type, not even void. Removing void will fix the error.
In simple words: Constructors should not have void or any return type specified.

Exam Tip: Specifying void turns a constructor into a regular method with the same name as the class.

 

Question 19. How many values can be returned from a method?
Answer: Only one value can be returned from a method, though a method can have multiple return statements. Only one gets executed depending on execution flow.
In simple words: Methods can return only a single value at a time.

Exam Tip: To return multiple values, bundle them inside an object or array.

 

Question 20. What do you understand by Class and Object?
Answer: The basic unit of OOP is the Class. It can be described as a blueprint of objects. An Object is an instance of a class having a unique identity, characteristics (properties), and behavior (methods).
In simple words: A class is a blueprint, and an object is an instance created from that blueprint.

 

Question 21. How to declare a class in Java?
Answer: In Java, a class is declared using the class keyword followed by the class name.
Example:
public class Student {
String Name;
int RollNo;
void getAdmission() { }
}
In simple words: Use the class keyword to define a new class.

Exam Tip: Public class names must match the filename in Java.

 

Question 22. What is the difference between instance and static variable?
Answer: Instance variables are created for every object of the class (replicated per object). Static variables are declared once for each class, shared by all objects, with only a single copy maintained in memory.
In simple words: Instance variables belong to specific objects, while static variables are shared across all objects.

Exam Tip: Static variables are accessed using the class name (ClassName.variable).

 

Question 23. What do you understand by constructor in OOP?
Answer: A constructor is a special member method of a class used to initialize an object when it is created (instantiated).
In simple words: Constructors initialize objects upon creation.

Exam Tip: Constructors ensure objects start in a valid state with initial data.

 

Question 24. What are the properties of Constructor?
Answer:
- Must have the same name as the class name.
- Have no return type, not even void.
- Automatically created by Java with default values if not defined explicitly.
In simple words: Constructors share the class name, have no return type, and run automatically.

Exam Tip: Constructors can be overloaded just like normal methods.

 

Question 25. What do you understand by methods? What are the advantages of methods?
Answer: A method is a sequence of statements written to perform a specific job. In OOP, it represents object behavior. Advantages include:
1. Coping with complexity via modularization (divide and conquer).
2. Hiding details (black-box approach).
3. Reusability of code (invoking code from anywhere without rewriting).
In simple words: Methods organize code into reusable blocks, reducing complexity.

Exam Tip: Modular programming makes code easier to test, debug, and maintain.

 

Question 26. How to define a method?
Answer: General form:
[Access specifier] <return_type> <method_name>(<parameters>) {
// body of the method
}
- Access Specifier: public, protected, or private.
- Return Type: int, float, void, etc.
- Method Name: Valid Java identifier.
- Parameters List: Formal parameters or arguments.
In simple words: Methods require an access modifier, return type, name, and parameter list.

Exam Tip: Always include a return statement if the return type is not void.

 

Question 27. What are the ways to pass values to methods in Java?
Answer:
1. Call by Value: Values of actual parameters are copied to formal parameters. Changes do not affect original values.
2. Call by Reference: References (memory addresses) are passed, so changes made to parameters reflect back in the calling function.
In simple words: Primitives use call by value, while objects use references.

 

Question 28. Differentiate between constructor and method.
Answer:
- Constructor initializes objects; Method performs general tasks.
- Constructor has no return type; Method has any return type including void.
- Constructor has the exact name of the class; Method can have any valid identifier name.
- Constructor is called automatically during object creation; Method is called explicitly whenever required.
In simple words: Constructors initialize objects automatically, while methods are called manually for tasks.

Exam Tip: Keep these four key differences in mind for exam questions.

 

Question 29. What is "this" keyword?
Answer: The this keyword is a reference to the currently calling object. It resolves ambiguity when local variables or parameters have the same name as instance variables.
In simple words: 'this' refers to the object currently executing the method.

Exam Tip: Commonly used in constructors as this.x = x; to assign parameters to instance variables.

 

Question 30. How can we use a class as a composite data type?
Answer: A class can bundle various primitive data members to form a user-defined composite data type.
Example:
class Date {
byte dd, mm, yy;
public Date(byte d, byte m, byte y) {
dd = d;
mm = m;
yy = y;
}
void display() {
System.out.println(dd + "/" + mm + "/" + yy);
}
}
Date DOB = new Date((byte)13, (byte)2, (byte)1990);
In simple words: Classes combine multiple primitive variables into a single composite custom type.

Exam Tip: Composite data types group related attributes into a single cohesive object.

 

Unsolved Questions (Solutions)

 

Question 1. How are parameterized constructors different from non-parameterized constructors?
Answer: Non-parameterized constructors take no arguments and initialize objects with default values. Parameterized constructors accept arguments during instantiation to initialize object fields with specific user-defined values.
In simple words: Non-parameterized constructors use defaults, while parameterized ones accept custom initial values.

Exam Tip: You can overload constructors to provide both parameterized and default options.

 

Question 2. List some of the special properties of the constructor methods.
Answer:
1. Must share the exact name of the class.
2. Have no return type (not even void).
3. Called automatically upon object creation with the new operator.
4. Provided with default implementations by Java if omitted.
In simple words: Constructors share class names, have no return type, and run automatically.

Exam Tip: Constructors cannot be inherited by subclasses.

 

Question 3. Differentiate between Instance member and static members of a class.
Answer: Instance members belong to specific object instances and are replicated for every new object. Static members belong to the class as a whole, shared among all instances with only a single memory copy.
In simple words: Instance members are per-object, whereas static members are shared globally across all objects.

Exam Tip: Static methods cannot access non-static instance variables directly without an object reference.

 

Question 4. What do you mean by actual and formal parameters of a method? Explain with an example.
Answer: Formal parameters are variables declared in the method signature to receive inputs. Actual parameters are the actual values or variables passed to the method during a method call.
Example:
int add(int a, int b) { // a and b are formal parameters
return a + b;
}
// Inside main:
int result = add(5, 10); // 5 and 10 are actual parameters
In simple words: Formal parameters are placeholders in method definitions, and actual parameters are values passed during calls.

Exam Tip: Datatypes of actual parameters must match formal parameters.

 

Question 5. Identify the errors in the method skeletons given below: (1) float average (a, b) { } (2) float mult (int x, y) { } (3) float doer (int, float = 3.14) { }
Answer:
(1) Missing data types for parameters a and b.
(2) Missing data type for parameter y (int x, int y is required).
(3) Default argument values (like float = 3.14) are not supported in Java method signatures.
In simple words: Java requires explicit data types for every parameter and does not support default parameter values.

Exam Tip: Always specify data types for every individual parameter in Java.

 

Question 6. Given the method below write an ActionPerformed event method that includes everything necessary to call this method. int thrice (int x) { return (x * 3); }
Answer:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int inputVal = Integer.parseInt(jTextField1.getText().trim());
int result = thrice(inputVal);
jTextField2.setText("" + result);
}
In simple words: The event handler reads text input, calls thrice(), and displays the result in a text field.

Exam Tip: Always parse text inputs into numbers before passing them to mathematical methods.

 

Java Gui Programming Printable Assignments & Solutions for Class 12 Informatics Practices

Revision Assignment: Java Gui Programming (CBSE)

Review targeted chapter assignments for Class 12 Informatics Practices Java Gui Programming. Built according to official CBSE guidelines, these downloadable problem sets help students build accuracy and prepare effectively for school tests.

Why Practice Class 12 Informatics Practices Assignments?

  • Curriculum Standards: Assignments match modern CBSE sample formats to ensure relevant preparation.
  • Thorough Revision: Detailed problem sets reinforce core concepts and eliminate conceptual weak spots.
  • Execution Speed: Timed practice with assignment sets sharpens overall response timing.

Steps to Complete Java Gui Programming Assignments Successfully

  1. Initial Reading: Begin by reading the NCERT book for Class 12 Informatics Practices to build a baseline understanding.
  2. Independent Testing: Attempt assignment questions unassisted, then verify work using provided answer keys.
  3. Supplementary Aids: Leverage revision notes and worksheets whenever you encounter difficult topics.

FAQs

Where can I download the latest CBSE Class 12 Informatics Practices Java Gui Programming assignments?

You can download free PDF assignments for Class 12 Informatics Practices Java Gui Programming from StudiesToday.com. These practice sheets have been updated for the 2026-27 session covering all concepts from latest NCERT textbook.

Do these Informatics Practices Java Gui Programming assignments include solved questions?

Yes, our teachers have given solutions for all questions in the Class 12 Informatics Practices Java Gui Programming assignments. This will help you to understand step-by-step methodology to get full marks in school tests and exams.

Are the assignments for Class 12 Informatics Practices Java Gui Programming based on the 2026 exam pattern?

Yes. These assignments are designed as per the latest CBSE syllabus for 2026. We have included huge variety of question formats such as MCQs, Case-study based questions and important diagram-based problems found in Java Gui Programming.

How can practicing Java Gui Programming assignments help in Informatics Practices preparation?

Practicing topicw wise assignments will help Class 12 students understand every sub-topic of Java Gui Programming. Daily practice will improve speed, accuracy and answering competency-based questions.

Can I download Informatics Practices Java Gui Programming assignments for free on mobile?

Yes, all printable assignments for Class 12 Informatics Practices Java Gui Programming are available for free download in mobile-friendly PDF format.