0% found this document useful (0 votes)
54 views

Primitives Value and Data Types: Fill in The Blanks With Appropriate Word/words

The document discusses Java primitive data types and their characteristics. It provides examples of different data types like integer, floating point, boolean and examples of their usage. It also discusses the differences between primitive and non-primitive data types, implicit and explicit type conversion and need for type casting in some cases.

Uploaded by

Gaurav Mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Primitives Value and Data Types: Fill in The Blanks With Appropriate Word/words

The document discusses Java primitive data types and their characteristics. It provides examples of different data types like integer, floating point, boolean and examples of their usage. It also discusses the differences between primitive and non-primitive data types, implicit and explicit type conversion and need for type casting in some cases.

Uploaded by

Gaurav Mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Primitives Value and Data Types

Fill in the blanks with appropriate word/words


Question 1
Data Type is used to allocate exact space for storage of a value.

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

Integer Constant Floating Constant

Integer Constants represent whole Floating Constants represent


number values like 2, -16, 18246, fractional numbers like 3.14159, -
24041973, etc. 14.08, 42.0, 675.238, etc.

Integer Constants are assigned to Floating Constants are assigned to


variables of data type — byte, short, variables of data type — float,
int, long, char double

(b) Primitive and Non-Primitive data types

Primitive Data Types Non-Primitive Data Types

Non-Primitive Data Types are


Primitive Data Types are Java's
created by using Primitive Data
fundamental data types
Types

Primitive Data Types are built-in data


Non-Primitive Data Types are
types defined by Java language
defined by the programmer
specification

Examples of Primitive Data Types are


Examples of Non-Primitive Data
byte, short, int, long, float, double, char,
Types are Class and Array
boolean
Question 3
Write down the data type of the following:
(a) Integer — int
(b) Character — char
(c) A fractional number — double
(d) A special character — char

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.

 Single precision format uses a total of 32 bits to represent the fractional


number. Out of that 32 bits, 24 are used to represent the significand
and 8 bits are used to represent the exponent. Double precision format
uses a total of 64 bits to represent the fractional number. Out of that 53
bits are used to represent the significand and 11 bits are used to
represent the exponent.
 Double precision format stores fractional numbers at higher accuracy
than single precision format.
 float data type stores a number in single precision format whereas
double data type stores a number in double precision format.
Question 9
A non-primitive data type is also referred to as reference type. Explain Why?
Unlike primitive data type, the allocation of non-primitive data type takes
place in dynamic memory. The accessing of non-primitive data types is
based on their references (addresses). Hence, non-primitive data types are
also referred to as reference type.

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

Return data type is double.


(b)
float m;
p = m/3*(Math.pow(4,3));
System.out.println(p);

Answer

Return data type is double.


Question 12
What are the resulting data type of the following explicit conversions?
int i; float f; double d; short s; char c; byte b;
(a) (float) i/b + d;

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

You might also like