Page 270 - IT-802_class_12
P. 270
8. What is the need of JVM? [CBSE Sample Paper 2023]
Ans. When the bytecode (also called a Java class file) is to be run on a computer, a Java interpreter, called the Java Virtual
Machine (JVM), translates the bytecode into machine code and then executes it.
9. Which member function of the Integer wrapper class allows access to the int value held in it? [CBSE Sample Paper 2023]
Ans. intValue() member function of the Integer wrapper class allows access to the int value held in it.
10. Sagar has declared an array whose last element is having an index/position as 10. What would be the size of this array?
[CBSE Sample Paper 2023]
Ans. 11
11. In the table teacher, Riya doesn’t want repeated values in column marks. Rewrite the correct command.
select marks from teacher; [CBSE Sample Paper 2023]
Ans. select distinct marks from teacher;
12. What is an exception in java? [CBSE Sample Paper 2023]
Ans. An error situation that is unexpected in the program execution and causes it to terminate unexpectedly is called .an exception
13. How can you write multiline comments in java program? [CBSE Sample Paper 2023]
Ans. Writing the comment between the symbols /* and */.
14. What is the purpose of wait () method in java threads? [CBSE Sample Paper 2023]
Ans. This method is useful when you have multiple threads running but you want one of them to start execution only when
another one finishes and notifies the first one to resume execution.
15. What are the two ways to create a thread in java? [CBSE Sample Paper 2023]
Ans. In Java, threads can be created in two ways
i. By extending the Thread class
ii. By implementing the Runnable interface
16. What is the difference between the following two java statements? [CBSE Sample Paper 2023]
(a) int x=5;
(b) integer y= new integer(50);
Ans. In the first declaration, an int variable is declared and initialized with the value 50. In the second declaration, an object of
the class Integer is instantiated and initialized with the value 50.
Or
The variable x is a memory location and the variable y is a reference to a memory location that holds an object of the class
Integer.
B. Long answer type questions.
1. What are the rules for naming a variable?
Ans. Following are the rules for naming a variable:
Ð Variable names can begin with either an alphabetic character, an underscore (_), or a dollar sign ($). However, convention
is to begin a variable name with a letter. They can consist of only alphabets, digits, and underscore.
Ð Variable names must be one word. Spaces are not allowed in variable names. Underscores are allowed. “total_ marks” is
fine but “total marks” is not.
Ð There are some reserved words in Java that cannot be used as variable names, for example – int
Ð Java is a case-sensitive language. Variable names written in capital letters differ from variable names with the same spelling
but written in small letters. For example, the variable name “percentage” differs from the variable name “PERCENTAGE”
or “Percentage”.
Ð It is good practice to make variable names meaningful. The name should indicate the use of that variable.
Ð You can define multiple variables of the same type in one statement by separating each with a comma. For example, you
can define three integer variables as shown: int num1, num2, num3;
2. What are arithmetic operators?
Ans. An arithmetic operator is used for writing codes that perform arithmetical calculations. The assignment operators are
discussed in the table given below:
268 Touchpad Information Technology-XII

