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

Data Type Important Question

Uploaded by

meghapetkar24
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Data Type Important Question

Uploaded by

meghapetkar24
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

DATATYPES

IMPORTANT QUESTIONS AND ANSWERS

R.PUNITH KUMAR
KODNEST® | BENGALURU
KODNEST® WWW.KODNEST.COM PH:8095000123

IMPORTANT QUESTIONS AND ANSWERS ON DATATYPES

1.In what format is Integer data stored in memory unit?


(base-2 format)

2.In what format is real number data stored in memory unit?


(IEEE format)

3.Which data types in Java are used to handle Integer data?


(byte, short, int and long)

4. What is the real number data by default treated in Java?


(double)

5.What is the range of data that can be stored in long data type?
(-9223372036854775808L to 9223372036854775807L) )

9. How many bytes are allocated for short data type in Java?
(2 bytes)

10. Does Java follow ASCII or UNICODE ? Why? (UNICODE.


Because UNICODE supports all the symbols of all the languages
across the world)

11. How many bytes are allocated for long data type in Java? (8
bytes)

12. How many bytes are allocated for float data type in Java? (4
bytes)

pg. 1
KODNEST® WWW.KODNEST.COM PH:8095000123

13. What is the range of data that can be stored in byte data type?
(-128 to +127)

15. What is the range of data that can be stored in short data type?
(-32768 to +32767)

16. How many bytes are allocated for char data type in Java?
Why? (2 bytes, because java follows UNICODE)

17. Is zero a positive number or negative number in


programming? Why? (Zero is a positive number, because the most
significant bit in the positive number is zero)

18. Why does Java provide primitive data types in spite of the fact
that it makes it only 99% OOP? (Because primitive data types are
fast in execution when compared to wrapper classes)

19. What is the range of double? (-1.7e to the power -308 to +1.7e
to the power +308)

20. What is the range of float? (-3.4e-038 to +3.4e+038)

21. Why should data be stored in form of 0s and 1s in the


memory? (because every memory device can store only 0’s and
1’s)

22. What are the different primitive data types in Java? (byte,
short, int, long, float, double, boolean, char)

pg. 2
KODNEST® WWW.KODNEST.COM PH:8095000123

23. How is data stored in the memory unit? (in the binary form)

24. Which data types in Java are used to handle real number
data? (float and double)

25. In what format is character data stored in memory unit?


(UTF-16 or UTF-32)

26. Why did UNICODE come into existence? (Because ASCII did
not support symbols of all the languages in the world)

27. What is the range of data that can be stored in int data type?( -
2147483648 to 2147483647)

28. How can you convert double data type to float data type in
Java? (By explicit typecasting (float=(float)24.17; or by putting
suffix f(24.17f;))

29. How many bytes are allocated for byte data type in Java? (1
byte)

30. How many bytes are allocated for double data type in Java? (8
bytes)

40. How many bytes are allocated for int data type in Java? (4
bytes)

41.Which special characters may be used as the first character of


an identifier? (_ and $)

pg. 3
KODNEST® WWW.KODNEST.COM PH:8095000123

41. Which characters may be used as the second character of an


identifier, but not as the first character of an identifier? (digits.
t6emp=25; temp6 is valid but 6temp is invalid)
How many bit format is ASCII exactly? (7 bit format)

42. Why is ASCII format forcefully stored as 8-bit format?


(Because minimum memory that is allocated is 1 Byte i.e. 8bits)

43. What is UTF? (Universal Translational Format)


44.What is UTF-16? When is it used normally? (UTF-16 is used
whenever all the symbols of all the commonly spoken languages
across the world are required in the project)

45. Are true and false keywords? (yes)

46. What is numeric promotion? (When data of a smaller


magnitude is placed within a memory location of a larger
magnitude, it is called as numeric promotion. Implicit typecasting
is also called as numeric promotion.)

47. What are the rules associated with the usage of underscore in
a literal? (Refer class notes)

48.What is meant by “Java is a strongly typed language”? (Every


variable in java must have an associated data type and also a value
which is compatible with the data type.)

49. Give the implicit upcasting chart or numeric promotion chart?

pg. 4
KODNEST® WWW.KODNEST.COM PH:8095000123

50.Which Java operator is right to left associative? (Assignment


operator (=))
Can a double value be cast to a byte? (Yes.)

51. Express double a = 123.45 in scientific notation? (double a =


1.2345E+2)

52. What is the difference between char literal and string literal?
(character literal is data which is enclosed within single quotes
where as String literal is data which is enclosed within double
quotes)

53. Can we use underscore in a literal? (Yes.)

54. What is the difference between declaring a variable and


defining a variable? (int a; declaring,
int a=100; defining)

55. Can we create binary literals in Java? (Yes. Using a prefix 0b)

56. How do we make a project coded in Java a pure OOP project?


(Using wrapper classes)

57. What is the role of wrapper classes in Java? (To code purely
objected oriented projects.)

pg. 5
KODNEST® WWW.KODNEST.COM PH:8095000123

58. What happens if a larger magnitude data is assigned to a value


of a data type which cannot handle it? (Overflow or loss of
precision occurs)

59.Should numeric promotion be performed explicitly? (No)

60.Does numeric promotion reduce the precision of the data?


(No)

61.What is the role of formats in data types? (It is used to convert


real world data in its original form into 0s and 1s so that it can be
stored in the memory unit)

62.What is a variable? (It is a reserved memory location into


which a value can be stored)

63.How is a negative number stored in Byte data type? (2’s


compliment base 2 format)

64.How is a negative number stored in short data type? (2’s


compliment base 2 format)

65.How is a negative number stored in int data type? (2’s


compliment base 2 format)

66.How is a negative number stored in long data type? (2’s


compliment base 2 format)

67.What is the range of char? (0 to 65535)

pg. 6
KODNEST® WWW.KODNEST.COM PH:8095000123

68.What is a literal? (It is a fixed value which is assigned to a


variable)

69.What does a prefix 0 indicate in a literal? (Octal)

70.What does a prefix 0x indicate in a literal? (Hexadecimal)

71.What is the default value of long? (0L)

72.What is the default value of double? (0.0)

73.What is the default value of char? (‘\u0000’)

74.How is a binary literal created in Java? (Using the prefix 0b)

75. Identify valid and invalid literals? (Assignment for you)

long debitcardnumber= 1234_5678_9012_3456L;


long ssn = 999_99_9999L;
float pie = 3.14_15F;
long kod = 0xFF_EC_DE_5E;
long kodn = 0xCAFE_BABE;
long kodne = 0x7fff_ffff_ffff_ffffL;
byte kodnes = 0b0010_0101;
long kodnest = 0b11010010_01101001_10010100_10010010;
// Invalid: cannot put underscores
// adjacent to a decimal point
float pie2 = 3_.1415F;
// Invalid: cannot put underscores
// adjacent to a decimal point
float pie3 = 3._1415F;

pg. 7
KODNEST® WWW.KODNEST.COM PH:8095000123

// Invalid: cannot put underscores


// prior to an L suffix
long socialSecurityNumber1 = 999_99_9999_L;

// OK (decimal literal)
int a1 = 5_2;
// Invalid: cannot put underscores
// At the end of a literal
int a2 = 52_;
// OK (decimal literal)
int a3 = 5_______2;

// Invalid: cannot put underscores


// in the 0x radix prefix
int a4 = 0_x52;
// Invalid: cannot put underscores
// at the beginning of a number
int a5 = 0x_52;
// OK (hexadecimal literal)
int a6 = 0x5_2;
// Invalid: cannot put underscores
// at the end of a number
int a7 = 0x52_;

pg. 8

You might also like