KnowledgeBoat Logo
OPEN IN APP

Chapter 5 - Unit 1

Primitives Value and Data Types

Class 12 - APC Understanding ISC Computer Science with BlueJ



Fill in the blanks with an 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 ConstantFloating Constant
Integer Constants represent whole number values like 2, -16, 18246, 24041973, etc.Floating Constants represent fractional numbers like 3.14159, -14.08, 42.0, 675.238, etc.
Integer Constants are assigned to variables of data type — byte, short, int, long, charFloating Constants are assigned to variables of data type — float, double

(b) Primitive and Non-Primitive data types

Primitive Data TypesNon-Primitive Data Types
Primitive Data Types are Java's fundamental data typesNon-Primitive Data Types are created by using Primitive Data Types
Primitive Data Types are built-in data types defined by Java language specificationNon-Primitive Data Types are defined by the programmer
Examples of Primitive Data Types are byte, short, int, long, float, double, char, booleanExamples of Non-Primitive Data Types are Class and Array

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

PrevNext