Chapter 3-DataType
Chapter 3-DataType
Chapter 3
1. Variable
2. Literal ✓
3. Identifier
4. Character
Question 2: A word used in a high level language which has a special meaning attached to it is called
1. Class
2. Identifier
3. Keyword ✓
4. Literal
1. Char variable ✓
2. Char type literal
3. String variable
4. String literal
1. ''✓
2. ""
3. ::
4. {}
1. String variable ✓
2. Static variable
3. Boolean variable
4. None
1. 65 - 90 ✓
2. 60 - 85
3. 65 - 91
4. 97 - 122
1. 11.4F/3.2D
2. 13.8F/4.6F;
3. 12/3 ✓
4. None
1. char
2. long
3. object ✓
4. short
1. char
2. double ✓
3. byte
4. String
Question 10: Boolean Data is used to test a particular condition i.e. true or false. Which of the following is a
correct representation?
1. boolean m=true ✓
2. boolean m='true'
3. boolean m="true"
4. none
Question 7: The comma, exclamation, question mark etc., are termed as Tokens in Java language.
Question 8: An element of Java program that is used to identify a class, function or value is called
as identifier.
Question 10: A Java expression that contains all the elements of same data type is pure expression.
Question 1
Data types are used to identify the type of data a memory location can hold and the associated
operations of handling it.
Question 2
A variable represents a memory location through a symbolic name which holds a known or unknown
value of a particular data type. This name of the variable is used in the program to refer to the stored
value.
Example:
int rollNumber = 21; string myName= “UDAN –We are future”;
Question 3
The keyword final before a variable declaration makes it a constant. Its value never changed in the
program.
Example:
final int DAYS_IN_A_WEEK = 7;
Question 4
1. Primitive Datatypes.
2. Non-Primitive Datatypes.
Question 5
A token is the smallest element of a program that is meaningful to the compiler. The different types of
tokens in Java are:
1. Identifiers
2. Literals
3. Operators
4. Separators
5. Keywords
Question 6
1. Name of the variable should be a sequence of alphabets, digits, underscore and dollar sign
characters only.
2. It should not start with a digit.
3. It should not be a keyword or a Boolean or null literal.
Question 7
The process of converting one predefined type into another is called type casting.
Question 8
double pi = 3.142;
(b) Assign the value of (1.732) to a variable with the requisite data type.
double x = 1.732;
Question 9
Distinguish between:
Token Identifier
Escape Sequences can be used to write Only true and false values are allowed
character literals for boolean literals
Question 10
(a) Integer
int
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 12
Primitive data types are the basic or fundamental data types used to declare a variable. Examples of
primitive data types in Java are byte, short, int, long, float, double, char, boolean.
Question 13
Data types tells Java how much memory it should reserve for storing the value. Data types also help in
preventing errors as the compiler can check and flag illegal operations at compile time itself.
Question 14
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 15
Question 16
What do you mean by type conversion? How is implicit conversion different from explicit conversion?
The process of converting one predefined type into another is called type conversion. In an implicit
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. For example:
int a = 21;
float b = 19.5f, d;
d = a + b;
In case of 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 17
In static declaration, the initial value of the variable is provided as a literal at the time of declaration.
For example:
int a = 4;
int b = Math.sqrt(a);
Question 18
Question 19
(i)
int p; double q;
r = p+q;
System.out.println(r);
Answer
(ii)
float m;
p = m/3*(Math.pow(4,3));
System.out.println(p);
Answer
Question 20
What are the resultant data types if the following implicit conversions are performed? Show the result with
flow lines.
int i; float f; double d; char c; byte b;
(a) i + c/b;
Answer
i + c/b;
⇒ int + char / byte
⇒ int + char
⇒ int
f/d + c*f;
⇒ float / double + char * float
⇒ double + float
⇒ double
(c) i + f - b*c;
Answer
i + f - b*c;
⇒ int + float - byte * char
⇒ int + float - char
⇒ float - char
⇒ float
(d) (f/i)*c + b;
Answer
(f/i)*c + b;
⇒ (float / int) * char + byte
⇒ float * char + byte
⇒ float + byte
⇒ float
(e) i + f- c + b/d;
Answer
i + f- c + b/d;
⇒ int + float - char + byte / double
⇒ int + float - char + double
⇒ float - char + double
⇒ float + double
⇒ double
Answer
i/c + f/b
⇒ int / char + float / byte
⇒ int + float
⇒ float