Professional Documents
Culture Documents
Values and Data Types - Q - A
Values and Data Types - Q - A
2. A word used in a high level language which has a special meaning attached to it is called
a) ‘ ’ b) “ ” c) : : d) { }
a) 65 to 90 b) 60 to 85 c) 65 to 91 d) 97 to 122
Ans.
1. b) Literal
2. c) Keyword
3. a) Char variable
4. a) ‘ ’
5. a) String variable
6. a) 65 to 90
7. c) 12/3
8. c) object
9. b) double
7. The comma, exclamation, question mark etc are termed as ______________ in Java language.
8. An element of Java program that is used to identify a class, function or value is called as
_______________
9. Integer type value occupies _________________bytes in the memory.
10. A Java expression that contains all the elements of the same data type is
_____________expression.
Ans.
1. alphabets
2. Unicode
3. ASCII code
4. token
5. literals
6. assignment
7. tokens
8. identifier
9. 4 bytes
10. pure expression [ In pure expressions, all the operands are of the same data type]
Ans. Data types specify the size and type of values that can be stored in a variable.The data type of
variables must be specified by the programmer to ensure optimum utilisation of memory space. For
example, when we declare float y, it means that the variable y will store floating type values.
Ans. A variable is a named memory location which holds a data value of a particular data type. The
value of a variable can change depending on the circumstances in the program. In Java programming,
variables, class names, function names etc are generally called as identifiers. For example consider the
statement, float k=120; Here k is the variable and it stores the value 120.
Ans. The quantities which remain fixed(do not change) throughout the discussion of the program are
called constants or literals. Java literals may be classified as follows:
Ans. Token can be defined as each individual component of a Java statement that carries some
meaning and takes part in the effective execution of the program. The various types of tokens
available in Java are :
Ans.
Ans.
It is a type conversion in which one data type gets converted to another data type depending on the
user’s choice. This means that the user demands the system to give the result in the desired data type.
Since it involves user’s intervention, it is known as explicit type conversion or type casting. Type
casting is generally used to convert the higher data type to a lower data type.
Example :
float x=25.34;
int n = 30 + (int) x;
Result of the addition, 30 + x will be in float data type due to implicit conversion. But because of
explicit conversion / type casting x is forced to get converted to int data type. Hence the result is
obtained in int data type.
a) Assign the value of pi (3.142) to a variable with the requisite data type.
b) Assign the value of (1.732) to a variable with the requisite data type.
Ans.
a) double pi = 3.142;
b) float y=1.732;
9. Distinguish between
Ans.
A variable declared as integer type contains a whole number. The number may be a positive or
negative number, but without decimal point whereas a Floating point constant is used to store a
fractional number.
Token
i) A token can be defined as each individual component of a Java statement that carries some
meaning and takes part in the effective execution of the program. Example: keywords, identifiers,
literals, operators etc.
ii) Every token may not be an identifier.
Identifiers
i) Identifiers (variable names, class names, function names etc) are also called variables in Java. A
variable is a named memory location which holds a data value of a particular data type.
Character constant
ii) A character constant is a single character enclosed within single quotes. e.g. ‘s’, ‘f’ .
String constant
ii) A String constant may be a single character or set of characters enclosed within double quotes.
Character literals
ii) Character literals cannot be used in a Java program to check whether a given logical condition is
satisfied or not.
Boolean literals
i) Boolean literals can be either true or false which is not enclosed in any quotes.
ii) Boolean literals can be used in a Java program to check whether a given logical condition is
satisfied or not.
a) Integer
b) Long Integer
c) A fractional number
d) A special character
Ans.
a) int
b) long
d) char
11. What do you understand by boolean data type? Explain with an example.
Ans. It is a special data type in which a variable contains a constant as either true or false, These are
non-figurative constants. The default value of boolean data type is false. Single or double quotes
should not be used for boolean literals, true/false.
12. What do you understand by primitive data type? Give two examples.
Ans. The data types which are independent of any other data type are known as primitive data types.
They are also called as basic data types or predefined data types or inbuilt data types because the
system developers of Java have defined them.
Example: byte, short, int, long, float, double, char and boolean [write any two]
Ans. A compiler contains a phase called storage assignment phase. During this phase, memory is
allocated for different variables used in a program. In order to ensure optimum utilisation of memory
space, it becomes necessary for the programmer to select the appropriate data type for variables.
Ans.
In a mixed type expression , the data type of the result automatically gets converted into the higher
most data type available in the expression without any user intervention. This type of conversion is
known as implicit type conversion or Coercion.
Example
int a;
long b , c;
c = a + b;
In this example, the variable ‘a’ is automatically upgraded to long data type.
It is another type conversion in which one data type gets converted to another data type depending
on the user’s choice. This means that the user demands the system to get the result in the desired
data type.
Example:
int a = 10;
double c = 34.257
int y = a + (int)c;
The above expression is evaluated as 10+34 instead of 10+34.257 since the user has explicitly
converted the variable ‘c’ into int data type.
Ans.
In a mixed type expression, the data type of the result automatically gets converted into the higher
most data type available in the expression without any user intervention. This type of conversion is
known as implicit type conversion or Coercion.
16. What do you mean by type conversion? How is implicit conversion different from explicit
conversion?
Ans. In a mixed expression, the result must be obtained in a specific data type. For this purpose the
data type needs to be converted into the required type. This is known as type conversion.
In an implicit type conversion, the result of a mixed mode expression is obtained in the higher most
data type of the variables in the expression without any intervention of the user.
e.g.
int a;
float b,c;
c = a+b;
In case of explicit type conversion, the data gets converted to another type as per the user’s choice
and requirement. This means that the user demands the system to get the result in the desired data
type.
e.g.
int a;
float b;
double c;
b = (float) (a * c);
Ans.
Static declaration
i) During static declaration the variable gets initialized at the time when it is declared (before its actual
use in the programming logic)
Dynamic declaration
i) During dynamic declaration, a variable gets initialised at runtime, i.e. during the execution of the
program.
ii) In dynamic declaration, a variable is assigned the outcome of any arithmetical operation or logical
function.
iii) e.g.
m = ob.nextDouble( );
In the above example, the value of d can be initialised only during runtime. Hence it is a dynamic
declaration.
18. What do you mean by non-primitive data type? Give examples.
Ans.
They are basically defined as derived data types and are directly or indirectly dependent on primitive
data types. They store data values with reference to the addresses or locations. So, they are called
‘reference data types’ .Examples: classes, arrays, interfaces etc.
i) int p; double q;
r=p+q;
System.out.println(r);
ii)float m;
p=m/3* (Math.pow(4,3));
System.out.println(p);
Ans.
ii) double
20. What are the resultant data types if the following implicit conversions are performed? Show
the result with flow lines.
*********************