Data Type and Value

 

Data Type and Value

 

         

Question 1:

Write the memory capacity (storage size) of short and float data types in bytes.

 

Answer:

short memory capacity is 2 bytes(16 bits)

float memory capacity 4 bytes(32 bits)

 

 

Question 2:

State the data type and value of res after the following is executed:

char ch = '9';

res = Character.isDigit(ch);

 

Answer:

data type:boolean

value:true

 

 

Question 3:

Write the return data type of the following functions:

 

(i) startsWith()

Answer: boolean

 

(ii) random()

Answer: double

 

 

Question 4:

Classify the following as primitive or non-primitive data types:

 

(i) char

Answer:  primitive data type.

 

(ii) arrays

Answer:  non-primitive data type.

 

(iii) int

Answer : primitive data type.

 

(iv) classes

Answer:  non-primitive data type.

 

Question 5:

Write the return data type of the following functions:

 

(i) endsWith()

boolean

 

(ii) log()

double

 

 

Question 6:

State the number of bytes occupied by char and int data types.

 

Answer:

char-2 bytes

int-4 bytes

 

 

Question 7:

Name of the following:

Any one reference data types.

 

Answer:

String

 

 

Question 8:

State the data type and value of res after the following is executed:

char ch = 't';

res = Character.toUpperCase(ch);

 

Answer:

Data type is char.

Value is ‘T’.

 

 

Question 9:

Write one difference between primitive data types and composite data types.

 

Answer:

Primitive data types are independent basic data type and are part of the language.

Example: boolean, char, int etc.

 

Composite data types are dependent on primitive data types. They are formulated from

primitive data types. Example class, Interface and Array.

 

 

Question 10:

Write the return type of the following library functions:

 

(i) isLetterOrDigit(char)

Answer  boolean

 

(ii) replace(char, char)

Answer: String

 

 

Question 11:

What are the default values of the primitive data type int and float?

 

Answer:

Default value of int is 0.

Default value of float is 0.0F.

 

 

Question 12:

Arrange the following primitive data types in ascending order of their size:

(i) char (ii) byte (iii) double (iv) int

 

Answer:

byte, char, int, double

(byte-8bit char-16bit int-32bit double-64bit)

 

 

Question 13:

State the data type and value of y after the following is executed:

char x = '7';

y = Character.isLetter(x);

 

Answer:

Data type of y is boolean.

Value of y is false.

 

 

Question 14:

Name the primitive data type in Java that is:

 

(i) a 64-bit integer and is used when you need a range of values wider than those

provided by int.

Answer: long

 

(ii) a single 16-bit Unicode character whose default value is ‘\u0000’.

Answer: char

 

 

Question 15:

State one difference between floating point literals float and double.

 

Answer:  The floating point literal occupies 32 bits i.e 4 byte whereas the

double literal occupies 64 bits i.e 8 byte.

 

Question 16:

List the variables from those given below that are composite data types.

(i) static int x;                                      (ii) arr[i] = 10;

(iii) obj.display();                 (iv) boolean b;

(v) private char chr;                           (vi) String str;

 

Answer:

(i) x                                                       (ii) arr[i] = 10;

(iii) obj.display();                                  (vi) String str; are composite data type.

(v) No variables                                    (vi) No variables

 

 

Question17:

What is the data type returned by the library functions:

(i) compareTo()

Answer: int

 

(ii) equals()

Answer:  boolean

 

 

Question 18:

What is the data type that the following library functions return?

(i) isWhitespace(char ch)

Answer: boolean

 

(ii) Math.random()

Answer: double

 

 

Question 19:

Give one example each of a primitive data type and a composite data type.

 

Answer:  

Primitive data type: boolean

Composite data type: array

 

Question 20:

State the data type and values of a and b after the following segment is executed:

String s1 = "Computer", s2 = "Applications"

a = (s1.compareTo(s2));

b = (s1.equals(s2));

 

Answer:

Data type: a is int and b is boolean

Value: a is 2 and value of b is false.

 

 

Question 21:

State the purpose and return data type of the following String functions:

(i) indexOf()

 

Answer:

Purpose: to find the index of the first occurrence of a specific character or

substring in a string.

Return data type: int

 

(ii) compareTo()

 

Answer:

Purpose: to compare the contents of two strings lexicographically.

Return data type: int

 

No comments:

Post a Comment