Primitives Value and Data Types: Fill in The Blanks With Appropriate Word/words
Primitives Value and Data Types: Fill in The Blanks With Appropriate Word/words
Question 2
The data size of byte type ranges from -128 to 127.
Question 3
A character type data is enclosed within single quotes.
Question 4
A double is the higher most data type.
Question 5
A set of characters is assigned to String variable.
Question 6
The ASCII codes of upper case letters ranges from 65 to 90.
Question 7
The data type for the values true/false are called boolean type data.
Question 8
Resulting data type of expression 11.4f /2.0d will be double.
Question 9
Class is an example of non primitive data type.
Question 10
Byte is lower data type than short.
Write Short Answers
Question 1
State two categories of data types.
Primitive and Non-Primitive data types.
Question 2
Distinguish between:
(a) Integer and Floating constant
Question 4
What is meant by boolean type data? Explain with an example.
A boolean data type is used to store one of the two boolean values — true or
false. The size of boolean data type is 8 bits or 1 byte.
Example:
boolean bTest = false;
Question 5
What do you understand by type conversion?
The process of converting one predefined type into another is called type
conversion.
Question 6
Define the following with an example each:
(a) Implicit type conversion
In implicit type conversion, the result of a mixed mode expression is
obtained in the higher most data type of the variables without any
intervention by the user. Example:
int a = 10;
float b = 25.5f, c;
c = a + b;
(b) Explicit type conversion
In explicit type conversion, the data gets converted to a type as specified by
the programmer. For example:
int a = 10;
double b = 25.5;
float c = (float)(a + b);
Question 7
Explain the need to use suffix L in a long type data.
The default data type of integer literals is int. So if I try to assign a value to a
variable of long type like this:
//Will result in Compilation Error
long worldPopulation = 7780000000;
This will result in a compilation error of "integer number too large". The
reason for this error is that Java compiler is treating the number
7780000000 as an int and as this value is outside the range of int so we are
getting this error. To fix this, we need to explicitly tell the compiler to treat
this number as a long value and we do so by specifying L as the suffix of the
number. The case of L doesn’t matter, both capital and small L are
equivalent for this. The correct way to write the above statement using the
suffix L is this:
//Correct way to assign long value
long worldPopulation = 7780000000L;
Question 8
Differentiate single precision and double precision data value.
Question 10
Explain the term type casting.
The process of converting one predefined type into another is called type
casting.
Question 11
Predict the return data type of the following:
(a)
int p; double q;
r = p+q;
System.out.println(r);
Answer
Answer
Answer
(float) i/b + d
⇒ float / byte + double
⇒ float + double
⇒ double
(b) (int)f*d + c/s;
Answer
(int)f*d + c/s
⇒ int * double + char / short
⇒ double + short
⇒ double
(c) (char)i + f - b*d;
Answer
(char)i + f - b*d
⇒ char + float - byte * double
⇒ char + float - double
⇒ double
(d) (double) (f/i)*c + s;
Answer
(double) (f/i)*c + s
⇒ (double) (float / int) * char + short
⇒ double * char + short
⇒ double + short
⇒ double
(e) (char) d + b/i - f*s;
Answer
(char) d + b / i - f * s
⇒ char + byte / int - float * short
⇒ char + int - float
⇒ float