Informatics Practices Class 12 Important Questions Chapter 3 Java Programming Fundamentals is part of Informatics Practices Class 12 Important Questions. Here we have given Informatics Practices Class 12 Important Questions Chapter 3 Java Programming Fundamentals.
Informatics Practices Class 12 Important Questions Chapter 3 Java Programming Fundamentals
1 Mark Questions
Question 1.
Distinguish between / and ‘%’ operators. (Delhi 2014; All India 2014)
Answer:
‘/‘ is division operator which when applied on two operands returns the result of division. ‘%‘ is the modulus operator which when applied to two integer operands returns the remainder of division operations.
Question 2.
Is a string containing a single character same as a Char? (All India 2014)
Answer:
No, a string containing a single character is not same as a char.
E.g., X is a string which is stored as X/O” in memory whereas ‘X’ means single character ‘X’ only.
Question 3.
Write a statement in Java to declare a String type variable with a name City. (All India 2014)
Answer:
String City.
Question 4.
Write one difference between IF statement and SWITCH statement? (All India 2014C)
Answer:
If statement used to select among two alternatives whereas, switch statement used to select among multiple alternatives.
Question 5.
Write the value of sum1 after execution of the following WHILE loop:(All India 2014C)
int i = 1, suml=0; while(i<10) { suml=suml+i; i=i+2; }
Answer:
The value sumi after execution of the given code is 25.
Question 6.
Write statement to increase the value assigned to variable z by 5 and then to display the value. (All India 2014C)
Answer:
int z: z=5; System. out.println(z) :
Question 7.
What is the difference between the use of JTextField and JPasswordField in a form? (AllIndia 2013)
Answer:
JTextField The JTextField is used to display a text box. In this text box, the user can input or edit the data.
JPasswordField does not directly display its content. Infact it uses a single character (usually an ASTERISK) to represent each character that it contains so that it is possible to see how many characters have been typed, but not what they are. As its name suggests, JPasswordField is intended to be used as a simple way to accept a users password, JPasswordField is derived from JjextField.
Question 8.
Observe the following code carefully and find which statement will never get executed in the code?
int t = 1; // statement 1 do // statement 2 { // statement 3 if(t>13) // statement 4 jTextFi eldl.setTextt“Something”); // statement 5 else // statement 6 jTextFieldl.setTextC“Pass”); // statement 7 t+=3; // statement 8 } // statement 9 whi1e(t<=15); // statement 10
Answer:
statement 5
Question 9.
“The variable/expression in the switch statement should either evaluate to an integer value or string value.” State True or False. (Delhi 2013)
Answer:
True
Question 10.
While making a form in NetBeans, Ms. Jaya Laxminathan wants to display a list of countries to allow the users to select their own country. Suggest her to choose most appropriate control out of ListBox and ComboBox. (Delhi 2012; All India 2012)
Answer:
ComboBox will be most appropriate because user is allowed to select his own country which could be one only.
Question 11.
What is the purpose of break keyword while using switch case statement? Illustrate with the help of an example. (DelhI 2012; All IndIa 2012)
Answer:
The break statement is used to transfer the control out of the switch structure. In a switch statement when the break is not included then it will execute all the options after finding a match.
E.g.,
switch(option) { case 1: System.out.println(“One”); break; case 2: System.out.println(“Two”); break; default : System.out.println (“Other than One or Two”); }
Question 12.
List two purposes of ‘+’ operator in Java. (Delhi 2012C)
Answer:
Two purposes of ‘+’:
(i) ‘+’ is used to add two numbers.
(ii) ‘+’ is used to concatenate strings.
Question 13.
Write the output of the following code in Java. (Delhi 2012C)
int x=O; whiie(x<=1) { System.out.println(”x”); x=x+1; }
Answer:
Output
x
x
Question 14.
What happens if we do not include BREAK statement with a CASE in a SWITCH statement? (HOTSDeIhI2O12C)
Answer:
If we do not include BREAK statement, then the CASE that matches with SWITCH gets executed as well as all the other statements of all the remaining CASES after the matching CASE also gets executed.
Question 15.
What will be the value of variables ‘m’ and ‘n’ after the execution of the following code? (DelhI 2012)
int m, n = 0; for(m = 1;m < 4;m++) { n += ni; n--; }
Answer:
The final values of m and n after execution of the given code will be as follows:
m = 5
n = 6
Question 16.
What will be the value of variables and ‘Q’ after the execution of the following code? (All India 2012)
int P, Q = 0; for(P =1;P <= 4;P++) { Q += P; Q--: }
Answer:
The final values of P and Q after execution of the given code will be as follows:
P = 5
Q = 6
Question 17.
While working in NetBeans, Ms. Kanta Surbhi wants to display Cleared or Reattempt, required message depending upon the marks entered in JTextField. Help her to choose more appropriate statement out of if statement and switch statement. (Delhi2011)
Answer:
In such situation, if statement is more appropriate than the switch statement. Because if statement is suitable, when we need to check for a range of values and switch statement is suitable for multiple selection.
Question 18.
While working in NetBeans, Ms. Khurana wants to display Pass or Needs to Reappear message depending upon the marks entered in JTextField. Help her to choose more appropriate statement out of if statement and switch statement. (All India 2011)
Answer:
In such situation, if statement is more appropriate than the switch statement. Because if statement is suitable, when we need to check for a range of values and switch statement is suitable for multiple selection.
Question 19.
Name any two loop control structure provided by Java? (Delhi 2011c)
Answer:
Two loop control structure are:
- For loop
- While loop
Question 20.
What is the significance of default clause in a switch statement? (Delhi 2011c)
Answer:
Default clause is used to handle the case when no match of any case in the switch statement is found.
Question 21.
Write two points of difference between a while loop and a do-while loop. (Delhi2011c)
Answer:
‘while’ loop is an entry controlled loop and ‘do-while’ is an exit controlled loop. Before the execution of the ‘while’ loop the compiler will check the test expression, if the test expression result is TRUE then only the loop executes. There is no check of the test expression before the entry into the ‘do-while’ loop i.e. the loop will execute at least once.
Question 22.
The statement i++; is equivalent to
(i) i = i + i;
(ii) i = i +1;
(iii) i = i -1;
(iv) i –; (CBSE Text Book)
Answer:
(ii) i=i+l;
Question 23.
What will be the value of total after the loop finishes execution?
int total =0; // must be initialised before the for loop for(int count=5;count<=10;count++) { total+=count; } JTextField1.setText("The total is" +total);
(i) 10
(ii) 16
(iii) 45
(iv) 36
Answer:
(iii) 45
Question 24.
What is wrong with the while statement?
while((ctr < 5) && (ctr > 30))
(i) The logical operator && cannot be used in a test condition
(ii) The while loop is an exit condition loop
(iii) The test condition is always false
(iv) The test condition is always true (HOTS; CBSE Text Book)
Answer:
(iii) The test condition is always false.
Question 25.
Consider the following code snippet
int anumber; if(anumber>=10) { if(anumber==10) jLabel 1.setText(“First string”); else jLabel 1.setText("Second string”); jLabel 2.setText(“Third string”); }
What will be the output when anumber=14?
(i) First string
(ii) Second string
(iii) First string Third string
(iv) Second string Third-string (HOTS; CBSE Text Book)
Answer:
(iv) Second string Third string
Question 26.
What will be the output of the program given below? Which number is printed twice? (HOTS; CBSE Text Book)
int sum1=3; sum1++; jTextFieldl.setText(” “+suml); ++sum1; jTextFi el d2 . setText(” “-‘-sumi); jTextField3 .setText(” “+(++surnl)); jTextField4 .setText(” “+surnl++): jTextHeld5 .setText(” “+suml):
Answer:
The output of the given program:
4566 7
The number 6 is printed twice.
Question 27.
If there is more than one statement in the block of a for loop, which of the following must be placed at the beginning and the ending of the loop block?
(i) Parentheses()
(ii) French curly braces ()
(iii) Brackets []
(iv) Arrows <>
Answer:
(ii) French curly braces {}
Question 28.
Given the following information:
int a = 11; int b = 22; int c = 33; int d = 11;
Which of the following statements are true
(i) a == b
(ii) b I = d
(iii) c <= b
(iv) a < c
(v) a == d
(vi) c > a
(vii) a >= c
(a) (i), (iv) and (vii)
(b) (ii), (iv), (v) and (vi)
(c) (ii), (iv), (vi) and (vii)
(d) (iii), (v), (vi) and (vii) (CBSE Text Book)
Answer:
(b) (ii), (iv), (v) and (vi)
2 Marks Questions
Question29.
Write the difference between the following:
(i) A = 10
(ii) lf(A==10) (All India 2014C)
Answer:
(i) The ‘=’ operator is an assignment operator that is used to assign the values from right hand side to left hand side.
(ii) An ‘= = ‘operator is used with a control structure like if statement to compare left hand side and right hand side and return true if both are equal, false otherwise.
Question 30.
The following code has some error(s). Rewrite the correct code underlining all the corrections made (All India 2014C)
int z; z=14; do; z=z-2; System.out.displayln(z); } while Z >= 2;
Answer:
The correct code is:
int z; z = 14; do_ { z=z-2; System.out.println(z); }while(z >= 2);
Question 31.
Rewrite the following program code using if-else-if statement (All India 2014C)
String remarks; int num =lnteger.parselnt (jText Field 1.getText()); switch(num) { case 0: remarks = “You have not won any points”; break; case 1: remarks = “You have won one point”; break; case 2: remarks = “You have won two points”; break; default: remarks= “All the best”; }
Answer:
String remarks; int num =lnteger.parselnt(jTextFieldl .getText()) ; if (num == 0) remarks = “You have not won any points”; else if(num == 1) remarks = “You have won one point”; else if(num == 2) remarks = "You have won two points”; else remarks = “All the best”;
Question 32.
What will be the values of variables sum and sum1 after the execution of the following loops?
Answer:
Loop A
Value of variable sum = 10
Loop B
Value of variable suml = 10
Question 33.
What will be display in jTextAreal after the execution of the following loop?(Delhi 2014)
for (int 1=5; I<=25; I4=5) jTextAreal.setText(jTextAreal.get Text()+"”+Integer.toString(2*I));
Answer:
Output 10 20 30 40 50 will be displayed in the jTextAreal.
Question 34.
What will be the values of variables agg and aggl after the execution of the following loops?
Answer:
After the execution of Loop 1 value of variable agg = 9 After the execution of Loop 2 val ue of variable agg 1 = 9
Question 35.
What will be displayed in jTextAreal after the execution of the following loop? (All India 2014)
for (int 1=5; I>=2; I -- ) jTextAreal.setText(jTextAreal. getText()+"”+Integer.toString(I*I));
Answer:
25 16 9 4 will be displayed in jTextAreal after the execution of the given code.
Question 36.
What will be displayed in jTextFieldl and jTextField2 after the execution of the following code? (Delhi2013)
int Last, First = 3, Second = 5; Last = First + Second++; jTextFieldl.setText(Integer. toString(Last)); jTextField2.setText(Integer. toString(Second));
Answer:
jTextField1 = 8 jTextField2 = 6
Question 37.
What will be the contents of Strl and Str2 after the following code is executed? (Delhi 2013)
String Str2, Strl; Strl=“Dear Friend”; Str2=“Hello”; Strl=Str2. concat(Strl);
Answer:
Content of str1= Hello Dear friend Content of str2= Hello
Question 38.
How many times will the following loops execute? Which one of them is Entry Control and which one is Exit Control?
Answer:
The loops would execute 3 times
Loop 1 is the entry control loop
Loop 2 is the exit control loop
Question 39.
What will be displayed in jTextFieldl and jTextField 2 after the execution of the following loop? (Delhi 2013)
int Sum=0, Last=10; for(int C=1; C<=Last; C+=2) Sum++; jTextFieldl.setText(Integer.toString(Sum)); jTextFie1d2.setText(Integer.toString (C));
Answer:
The given code will give error because variable C cannot be used outside the for loop. However, if we consider C as global variable the output will be as follows;
jTextfieldl would show the value of Sum = 5; jTextfield2 would show the value of C = 11;
Question 40.
What will be the content of the jTextAreal after executing the following code (assuming that the jTextAreal has no content before executing this code)? (Delhi 2012; All India 2012)
for(int i=2;i<=5;i++) { jTextAreal.setText(jTextAreal. getTextO + “ ”+Integer.toString(i*i)); }
Answer:
4 9 16 25 49.
Question 41.
Mr. Kapoor is a programmer at Ekansh Enterprises. He created 5 digit password and stored in a string variable called strPassword. He wants to store the same password in an integer type variable called intPassword. Write an appropriate lava statement to transfer the content from strPassword to intPassword. (Delhi 2012)
Answer:
String strPassword=“12345”; int intPassword=Integer.parselnt (strPassword);
Question 42.
Given a string object named Salary having value as “55000” stored in it. Obtain the output of the following: (Delhi2012)
JOptionPane.showMessageDialog(null, "" +Saiary.length() + Integer.parseInt(Sai ary));
Answer:
After the execution of the given code, the output wi 11 be as follows:
555000
Question 43.
Given a string object named Pay having value as “68000” stored in it. Obtain the output of the following: (Delhi2012)
JOptionPane.showMessageDia 1og(nul1,“ ” +Pay.length!) +Integer. parselnt! Pay));
Answer:
After the execution of the given code, the output will be as follows:
568000
Question 44.
What will be the values of A and B after execution of the following code: (Delhi2011)
int A=100, B; for(B=10;B<=12;B++) { A += B; } JOptionPane.showMessageDia 10 g(this, “A:” +A +" ”+ “B :”+B);
Answer:
The output displayed by the given code will be as follows:
A: 133 B: 13
Question 45.
Rewrite the following program code using switch statement: (HOTS; Delhi 2011)
if(code = =1) day = “Monday”; else if(code = =2) day = “Tuesday”; else if(code = =3) day = “Wednesday”; else if(code = =4) day = “Thursday”; else day = “No Match”;
Answer:
The given code using switch statement will be as follows:
switch(code) { case 1: day = "Monday”; break; case 2; day = “Tuesday”; break; case 3; day ““Wednesday”; break; case 4; day = “Thursday”; break; default: day = “No Match”; }
Question 46.
What will be displayed in jTextFieldl after executing the following code? (AllIndia2011)
int m = 16; - m = m + 1; if(m < 15) jTextField.setText!Integer.toString(m)); else jTextField.setText!Integer.toString (m +15));
Answer:
In jTextFieldl after execution of the given code following output will be displayed:
32
Question 47.
Rewrite the following program code using switch statement: (AllIndia2011)
if (code == 1) month = “January”: else if(code = = 2) month = “February”; else if (code == 3) month = “March”; else if(code == 4) month = “Apri1”; else month = "No Match”;
Answer:
switch(code) case 1: month = “January”; break; case 2: month = “February”; break; case 3: month = "March”; break; case 4: month = “Apri1"; break; default month = "No Match”; }
Question 48.
What will be the values of P and Q after execution of the following code: (Delhi 2013; All India 2011)
int P. Q=100; for(P=10; P<=12; P++) { Q += P; } JOption Pane.showMessageDialog (this, “P: ”+P +“ ”+ “Q :”+Q);
Answer:
The output displayed by the given code will be as follows:
P:13 Q: 133
Question 49.
The following code has some error(s). Rewrite the correct code underlining all the corrections made. (Delhi 2011)
Int P=3, sum=0; { sum=P; P+=3; } whi1e(P=<12) jTextField1(Integer.tostring(sum));
Answer:
int P=3, sum=0; do{ sum=P; P+=3; }whi1e(P<=12); JTextFi eldl(Integer .toString (sum));
Question 50.
The following code has some error(s). Rewrite the correct code underlining all the corrections made. (Delhi 2011)
int Total=0, Jump=5; int I; for(i=0; I=< 5, i++) { Jump+=5; Total+=Jump; } jTextAreal.showText(“ ” + Total);
Answer:
int Total=0, Jump=5; int i; for (i=0; i<=5; i++) Jump += 5; Total+=Jump; } jTextAreal.showText(“ ” + Total);
Question 51.
The following code has some error(s). Rewrite the correct code underlining all the corrections made. (All India 2011)
Int k=2; sum=0; // Declaring k and sum as integer { sum=k; k+=2; } whi1e(k =< 20) jTextFi el dl(Integer.tostring(sum));
Answer:
int k=2, sum=0; // Declaring k //and sum as Integer do { sum=k; k+=2; } whi1e(k<=20); jTextFieldl(Integer.toString(sum));
Question 52.
The following code has some error(s). Rewrite the correct code underlining all the corrections made. (All India 2011)
int sum=0, Step=5; int I; for(i=0; I=<5, i++) { Step+=5; Sum+=Step; } jTextAreal.showText(“ ” + Sum)
Answer:
int Sum=0. Step=5; int I; for(1=0; I<=5, I++) { Step+=5; Sum+=Step; } jTextAreal.showText(" ” + Sum);
Question 53.
What do you mean by IDE?
Answer:
Integrated Development Environment (IDE)
An Integrated Development Environment (also known as integrated design environment, integrated debugging environment or interactive development environment) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of:
- a source code editor
- a compiler and)or an interpreter
- build automation tools
- a debugger.
Sometimes a version control system and various tools are integrated to simplify the construction of a GUI. Many modern IDEs also have a class browser, an object browser and a class hierarchy diagram, for use with object-oriented software development.
Question 54.
What do you mean by Inspector Window?
Answer:
Inspector Window The Inspector window displays on the screen the hierarchy of all components contained in the currently opened form. These could be buttons, labels, panels, menus, etc.
Question 55.
Briefly explain Frame.
Answer:
Frame A frame is a top-level window with a title and a border. A frame is created through JFrame component. The applications created with a Graphical User Interface (GUI), usually include one or more frames.
For adding a form in the application, we have to follow these steps:
- Right click on the project name.
- From the shortcut menu select New.
- Then from the cascading menu select JFrame Form.
Question 56.
Differentiate between parent control and child control.
Answer:
Parent or Container Controls They act as a background for other controls,
E.g.,
Frame. When we delete a parent control, all its child controls also get deleted. When we move a parent control, all its child controls also move along with it.
Child Controls Controls placed inside a container control are called child controls,
E.g.,
TextField. Label, Button, etc.
Question 57.
What do you mean by a literal? What are the different types of literals used in java language?
Answer:
Literals The literais or the constants are those items, whose values cannot be changed during the execution of the program. There are number of literais used in a Java program. These are integer literais, floating literais, boolean literais, character literais, string literais and null literais.
- Integer Literais The integer literais are the whole numbers without any fractional part. We can enter the integers as decimal numbers (base 10), octal numbers (base 8) and hexadecimal numbers (base 16). The decimal number is entered as a number which begins with a nonzero digit (e.g. 35), for an octal number we have to enter the number that begins with a zero (e.g. 026) and a hexadecimal number must start with Ox or OX. (e.g. Ox2B).
- Floating literais The floating literais or the real numbers are those numbers which have fractional part. The numbers can be written either in fractional form or in exponential form. e.g. 35.45. To write &3 x iO, we have to write 5.3E03 or 5.3e03.
- Boolean Literais The boolean type literais can have a boolean type value i.e. either true or false.
- Character Literais The character literai is one character enclosed in a single quotes. e.g. ‘a’.
- String Literais When multiple characters are entered such as a name of a person or a place. The string literais are enclosed by double quotes. e.g. “xyz”.
- Null Literais The null type literal has only null value. It is formed by a literal null.
Question 58.
Briefly explain the numeric integral primitive data types used in Java?
Answer:
Primitive or hitrinsic Data Types The primitive data types are the basic data types of the Java language.
The primitive data type can be divided into following four categories:
- Numeric Integral Primitive Types
- byte The byte type occupies 1 byte of memory space. It can hold a signed integer in range of —128 to + 127.
- short The short type occupies 2 bytes of memory space. It can hold a signed integer in range of —32768 to + 32767.
- mt The integer type occupies 4 bytes of memory space. It can hold a signed integer in range of— 2147483648 to + 2147483647.
- long The long type occupies 8 bytes of memory space. It can hold a signed integer in range of 9223372036854775808 to + 9223372036854775807.
- Fractional Primitive Types
- float The float type occupies 4 bytes of memory space. It can hold a single precision floating number in range of 1.401298464324817E—45 to 3.402823476638528860E+38 (1.4E—45 to 3.4E+38).
- double The double type occupies 8 bytes of memory space. It can hold a double precision floating number in range of ± 4.9 E—324 to ± 1.798E+308.
- Character Primitive Type char The char type is used to hold a single character. In Java unicode, encoding system is used for encoding the characters. It can hold a character variable range from O to 65535.
- Boolean Primitive Type boolean The boolean type is used t represent a boolean value, i.e. true or false. The size of this datatype is not precisely defined.
Question 59.
What do you understand by a variable in Java? How is it differentiated from a literal or constant?
Answer:
A variable refers to an item whose value varies or changes during the execution of a Java program.
Whereas the literals or the constants are those items whose values cannot be changed during the execution of the program.
Question 60.
What do you understand by parse() method? What are the different forms of parse() method which are used in Java language?
Answer:
parse( ) Method Converts String to Numbers from a GUI component. The parse() method is used to convert a string into different numeric types. In Java, there are different types of parse methods are used. Some of them are as follows:
- Byte.parseByte(String s) Used to convert a String s into a byte type value.
- Short.parseShort(String s) Used to convert a String s into a short type value.
- Integer.present(Striflg s) Used to convert a String s into an mt type value.
- Long.parseLong(String s) Used to convert a String s into a long type value.
- Float.parseFloat(String s) Used to convert a String s into a float type value.
- Double.parseDouble(String s) Used to convert a String s into a double type value.
Question 61.
How can you produce a basic dialog box in Java?
Answer:
In Java language to produce a basic dialogbox, we can use the JOptionPane.showMessageDialog() method. This method displays a dialogbox containing the desired information with OK button.
To use the JOptionPane.showMessageDialog() method in a java application, we need to follow these steps:
(i) In the source editor, we need to type the following statement at the top most position
import javax.swing.JOption Pane;
(ii) Then do display the desired message we need to specify the desired text as per following syntax:
JOptionPane.showMessageDialog(Null, "This is a message”);
Question 62.
What is the use of logical operator? What are different logical operators used in Java language?
Answer:
Logical Operators, The logical operators are used to make a decision on two conditions. Logical operators are mainly used to control program flow. There are three logical operators used in Java.
These are as follows:
- AND Operator (&&) This operator combines two given conditions and evaluates the result to true, if both of the given conditions are true.
- OR Operator (II) This operator combines two given conditions and evaluates the result to true, if either of the given conditions or both of the conditions are true.
- NOT Operator (!) The NOT operator is a unary operator. It negates the given condition.
Question 63.
Briefly explain the different GUI output methods used in Java.
Answer:
For displaying output in a Java program, we can use either of two methods, i.e. System.out.print() or System.out.println()
System.out.print() This method displays the text and keeps the cursor in the same line.
System.out.println() This method displays the text and then moves the cursor to the next line.
Question 64.
What are the different constructs of Java program?
Answer:
Constructs of Java Program
In a Java program, the specified statements can be executed either sequentially, selectively or repeatedly.
- Sequence Normally, the statements of a Java program are executed sequentially, i.e. in the same order as they are specified in a program.
- Selection When we need to execute the program selectively, we have to use a conditional statement.
- Iteration When there is a need for executing certain statements repeatedly, we have to use a loop structure or iteration statement.
Question 65.
What is the use of following swing controls in Java
(i) JFrame
(ii) JLabel
(iii) jextField
(iv) JButton
Answer:
Basic Graphical Controls of Swing
Some of the commonly used controls of swing are as follows:
- JFrame The JFrame is used to display a separate window with its own title bar.
- JLabel The JLabel is used to display uneditable text. It means the user cannot change the information.
- JTextField The JTextField is used to display a text box. In this text box, the user can input or edit the data.
- JPasswordField does not directly display its content. Infact it uses a single character (usually an ASTERISK)
to represent each character that it contains, so that it is possible to see how many characters have been typed, but
not what they are, As its name suggests, JPasswordField is intended to be used as a simple way to accept a users
password. JPasswordField is derived from JjextField.
- JPasswordField does not directly display its content. Infact it uses a single character (usually an ASTERISK)
- JButton The JButton displays a push button. The push button is used to generate the associated action event.
- JCheckBox The JCheckBox is used to display a checkbox. The checkbox is used to allow the user to select multiple choices out of given choices. When the user selects a particular choice, a is shown in front of it.
- JList The JList displays a list for the application. We can select multiple elements from this list.
- JComboBox The JComboBox provides a drop-down list of items. We can select an item from this list. Also, we can add a new item in the list. Infact, the combo box is a combination of a list and a text field.
- JPanel The JPanel is used to organise the components in a GUI application. It is a supporting container, which cannot be displayed but can be added to another container.
- JRadioButton The JRadioButton provides the radio buttons for the application. During the execution of a program, we can set these radio buttons either ON or OFF.
Note:
The area on the frame, where GUI components are placed is called content Pane
Question 66.
Why the following swing controls are used in Java
(i) ]CheckBox
(ii) ]List
(iii) ]ComboBox
(iv) ]RadioButton
Answer:
Controls of Swing
Some of the commonly used controls of swing are as follows:
- JFrame The JFrame is used to display a separate window with its own title bar.
- JLabel The JLabel is used to display uneditable text. It means the user cannot change the information.
- JTextField The JTextField is used to display a text box. In this text box, the user can input or edit the data.
- JPasswordField does not directly display its content. Infact it uses a single character (usually an ASTERISK)
to represent each character that it contains, so that it is possible to see how many characters have been typed, but
not what they are, As its name suggests, JPasswordField is intended to be used as a simple way to accept a users
password. JPasswordField is derived from JjextField.
- JPasswordField does not directly display its content. Infact it uses a single character (usually an ASTERISK)
- JButton The JButton displays a push button. The push button is used to generate the associated action event.
- JCheckBox The JCheckBox is used to display a checkbox. The checkbox is used to allow the user to select multiple choices out of given choices. When the user selects a particular choice, a is shown in front of it.
- JList The JList displays a list for the application. We can select multiple elements from this list.
- JComboBox The JComboBox provides a drop-down list of items. We can select an item from this list. Also, we can add a new item in the list. Infact, the combo box is a combination of a list and a text field.
- JPanel The JPanel is used to organise the components in a GUI application. It is a supporting container, which cannot be displayed but can be added to another container.
- JRadioButton The JRadioButton provides the radio buttons for the application. During the execution of a program, we can set these radio buttons either ON or OFF.
Question 67.
What are Jump statements? Briefly describe jump statements used in Java,
Answer:
The jump statements are used to transfer the control of the program unconditionally with in a function. In Java there are mainly two jump statements are used. These are break statement and continue statement:
- break statement The break statement can be used with for loop, while loop, do-while loop or switch. The break statement terminates the loop and moves the control to the next statement after the loop structure. The remaining statements of the loop will not be executed.
- continue statement The continue is a jump statement. It will cause to skip the remaining statements in the loop and moves the control to the beginning of the loop for next iteration.
Question 68.
What is the difference between unary, binary and ternary operators?
Answer:
Operators can also be divided into three parts, on the basis of number of operands:
- Unary Operator An unary operator requires only one operand. Example of unary operators are unary ÷, unary —, + + and –. This operator performs task only on a single operand.
- Binary Operator A binary operator requires two operands. Examples of binary operators are +, -, *, / and%.
- Ternary Operator A ternary operator requires three operands. Example of ternary operator is ?: (the conditional operator).
Question 69.
A phone number, consisting of 10-digits, s stored in a string variable strPhone. Now, it is required to store this phone number in long type variable Long Phone. Write a Java statement to do this.
Answer:
The Java statement to store the content of strPhone (which is in String form) in long phone variable in long type format will be as follows:
long long phone =long.parseLong(strPhone)
Question 70.
What is RAD?
Answer:
RAD stands for Rapid Application Development. It describes the methods of developing software through the use of pre-programmed visual tools and wizards.
Question 71.
What do you mean by a keyword? Can we use keywords as identifiers?
Answer:
Keywords are the words, which are defined in the compiler itself. These keywords convey a special meaning to the language compiler. These cannot be used as identifier name.
Question 72.
What is an identifier? Mention the rules for forming the identifier.
Answer:
Identifiers are used for naming the different parts of the program like variables, objects, classes, functions, arrays, etc.
The rules of identifier are as follows:
- Starts with an alphabet or an underscore( _).
- Can have alphabets, numbers, underscore and dollar($) sign.
- Can be of any length and cannot start with a digit.
Question 73.
What do you mean by primitive and reference data types?
Answer:
The data types used in Java can be divided into two categories:
- Primitive or Intrinsic Data Types
There are eight primitive data types in Java language. These are byte, short, int, long, float, double, char and boolean. - Non-Primitive or Reference Data Types
These data types are constructed from primitive data types. These are classes, arrays and interfaces.
Question 74.
Write down the two forms of increment and decrement operators?
Answer:
In Java for increment and decrement, two operators are used. These are + +, which increases its operand by 1 and — which decreases its operand by 1. Both of these operators can be used in two forms namely prefix form and postfix form.
(i) Prefix Form In this form first change then use rule is followed.
E.g.,
int a, b=5; a = ++b; System.out.println(a); System.out.print!n(b);
It shows the output as 6 and 6. (i.e. the value of variable a and b respectively).
(ii) Postfix Form In this form first use then change rule is followed.
E.g.,
int a, b=5; a—b++; System.out.println(a); System.out.println(b);
It show the output as 5 and 6. (i.e. the value of variable a and b respectively).
Question 75.
Briefly describe about implicit and explicit type conversion?
Answer:
Implicit Type Conversion The implicit type conversion is performed by the compiler in an expression where different data types are used, so that the information is not lost.
E.g.,
int a=4; float b=6.5, c; c=a+b; System.out.println(c);
In this expression, a will be automatically converted to float type.
Explicit Type Conversion The explicit type conversion is a user defined conversion to a specific data type.
E.g.,
int x=4, y=8; float z; z=(float)(x/y); System.out.printl n(z);
Question 76.
Differentiate between entry controlled loop and exit controlled loop.
Answer:
There are two types of loops used in Java language, these are entry controlled loop and exit controlled loop.
- Entry Controlled Loop In an entry controlled loop, the test condition is evaluated before entering into the loop.
E.g., the while loop is an entry controlled loop. - Exit Controlled Loop In an exit controlled loop, the test condition is evaluated after the execution of the loop statements one time.
E.g., the do-while loop is an exit controlled loop.
Question 77.
Why are the iteration or looping statements are used? Name the iteration statements used in Java.
Answer:
The iteration or looping statements are used in Java to execute a part of program containing some instructions repeatedly until certain given condition is satisfied.
In Java language, there are four types of loops are used, these are:
- for loop
- while loop
- do-while loop
- nested loop
Question 78.
Define term case sensitive? Is Java case sensitive?
Answer:
The term case sensitive refers to the different treatment of lowercase letters and uppercase letters. Java is a case sensitive language.
E.g.,
System.out.println() cannot be used as system.out.println() or SYSTEM.OUT.PRINTLN();
Question 79.
What is a unary operator? Briefly explain.
Answer:
Unary Operator An unary operator requires only one operand. Example of unary operators are unary + unary -, + + and –. This operator performs task only on a single operand.
Question 80.
What is the use of modulus (%) operator?
Answer:
The modulus operator is used to find out the remainder of a division operation,
E.g.,
int a=10, b=4, c; c=a%b; System.out.println(c):
Here, the output will be 2, i.e. the remainder of the division of 10 with 4.
Question 81.
What will be the result of following two expressions if initially x = 15?
(i) x++<=15
(ii) ++x<=15
Answer:
(i) True
(ii) False
We hope the Informatics Practices Class 12 Important Questions Chapter 3 Java Programming Fundamentals help you. If you have any query regarding Informatics Practices Class 12 Important Questions Chapter 3 Java Programming Fundamentals, drop a comment below and we will get back to you at the earliest.
The post Informatics Practices Class 12 Important Questions Chapter 3 Java Programming Fundamentals appeared first on Learn CBSE.