Page 53 - CA_Blue( J )_Class10
P. 53
21 st #Experiential Learning
E. Case-based questions. Century
Skills
In Java, data types are divided into two categories: primitive and non-primitive. Primitive data types include int, byte, short, long,
float, double, char, and boolean. These types are predefined by the language and named by a reserved keyword. They are stored
directly in memory locations. Non-primitive data types, also known as reference types, include String, arrays, classes, interfaces,
and more. These are created by the programmer and not predefined by Java. Reference types store references to the actual data
rather than the data itself.
Values in Java are assigned to variables. A variable's type determines what kind of values it can hold. For instance, an int variable
can hold whole numbers, a double variable can hold floating-point numbers, and a boolean variable can hold true or false. When
performing operations involving different data types, Java sometimes converts one type to another to match the operation
context. This can happen implicitly (automatic type conversion) or explicitly (type casting).
Implicit type conversion, also known as type promotion, happens automatically when the two types are compatible and the
target type is larger than the source type. For example, an int can be implicitly converted to a double. Explicit type conversion,
or casting, requires the programmer to manually convert one type to another using the cast operator. This is necessary when
converting a larger type to a smaller type, which can lead to loss of precision or data.
1. What are the two main categories of data types in Java?
a. Primitive and fundamental b. Primitive and reference
c. Basic and advanced d. Numeric and textual
2. Which of the following is a primitive data type in Java?
a. String b. Array
c. int d. Class
3. What does a reference type store in Java?
a. The actual data b. A reference to the actual data
c. A copy of the actual data d. None of these
4. Which primitive data type is used to store floating-point numbers in Java?
a. int b. double
c. char d. boolean
5. What happens during implicit type conversion in Java?
a. The programmer manually converts one type to another
b. The conversion happens automatically when types are compatible
c. It is always accompanied by loss of data
d. It converts a larger type to a smaller type
6. When is explicit type conversion required?
a. When converting a smaller type to a larger type
b. When converting between incompatible types
c. When converting a larger type to a smaller type
d. When no data conversion is needed
7. Which of the following statements is true about explicit type conversion?
a. It is also known as type promotion b. It can lead to loss of precision or data
c. It happens automatically d. It only converts between primitive types
8. What keyword is used to define a primitive data type in Java?
a. new b. class
c. int d. import
9. In Java, what type of variable can hold the value true?
a. int b. double
c. boolean d. char
10. Which data type should be used for a variable that needs to hold textual data in Java?
a. int b. boolean
c. String d. double
Ans. 1. b 2. c 3. b 4. b 5. b 6. c 7. b 8. c 9. c 10. c
51
Values and Data Types 51

