Some Important Questions with Answers
Some Important Questions with Answers
1. Which window is used to designed the form.
Ans: Design window
2. Which window contains the Swing Controls components.
Ans: Palette window
3. What is the most suitable component to accept multiline
text.
Ans : Text Area
4. What will be the output of the following command?
Learning.concat("Java")
Ans : Error
5. What will be the output of the following command?
"Learning".concat("Java")
Ans: LearningJava
6. Name the different list type controls offered by Java Swing.
Ans: (i) jListBox
(ii) jComboBox
7. Name any two commonly used method of ListBox.
Ans: getSelectedIndex() and getSelectedValue()
8. Write code to add an element (“New Course”) to a list
(SubList) at the beginning of the list.
Ans: SubList.add(0,”New Course”);
9. Describe the three common controls. Also give some of
their properties.
Ans:
(i) jButton text,icon
(ii) jLabel text,border
(iii) jTextField text,font
10. By default a combo box does not offer editing
feature.How would you make a combo box editable.
Ans: By setting its editable property to
false.
11. Write Name the component classes of Swing API for the
following components-
(a) frame (b) button
Ans:(a)JFrame(b)JButton
12. What is the name of event listener interface for action
events ?
Ans: ActionPerformed
13. What does getpassword() on a password field return ?
Ans: a character array
14. What is event driven programming?
Ans:This programming style responds to the user
events and is driven by the occurrence of user events.
15. What are containers? Give examples.
Ans: Containers are those controls inside them
e.g., frame (JFrame), Panel (JPanel), label (JLabel)
etc. are containers.
16. Which method of list is used to determine the value of
selected item, if only one itm is selected.
Ans: getSelectedValue()
17. Which type of storage is provided by variables.
Ans: temporary
18. What will be the output of the following code segment:
String firstName = "Johua ";
String lastName = "Yacomo";
String fullName = firstName + lastName;
jTextField1.setText("Full Name: ");
jTextField2.setText (fullName);
Ans: Full Name:
JohuaYacomo
19. Which expression is used to print the value of a
variable "x" of type int.
Ans: jTextField1.setText("x = " +
x);
20. The statement i++; is equivalent to
Ans :i=i+1
21. Name the primitives datatypes in java.
Ans: Numeric type , Fractional type, Character
type and Boolean type.
22. Which events gets fired when a user click a JButton and
JRadioButton.
Ans: ActionPerformed
23. Which of the following is a selection construct ?
a. do while Loop b. for Loop c. while Loop d. None of these
Ans: none of these
24. What will be used if there are two or more possible
options.
Ans: is else if and switch
25. Name the loop that never ends.
Ans: infinite loop
26. Which braces is used to enclose statements in a block
statement.
Ans: { } Curly braces
27. Which of the following is an exit controlled loop?
a. for loop b. do while Loop
c. while loop d. none of these
Ans: do while loop
28.Which process is used to translate a task into a series
of commands that a
computer will use to perform that task.
Ans: Project design
29. 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
Ans: List and combo box
30. Which construct will be used to find the sum of the
first 10 natural numbers?
Ans: for loop
31. Which of the following is not a good programming
guideline?
Ans : Using text fields to accept input of
marital status