ST.
MARY’S ENGLISH SCHOOL
CLASS –IX
SUBJECT – Computer Application
Ch-3
TOPIC: Values and Data types
Choose the correct answer:
1. Which among the following encoding system can represent 65536 characters?
a. ASCII
b. Unicode
c. Both a and b
d. None of these
Ans. b. Unicode
2. Which among the following is not a Token?
a. Keywords
b. Literals
c. Identifiers
d. Data Type
Ans. d. Data Type
3. Which among the following is a keyword but not a literal?
a. for
b. null
c. true
d. false
Ans. a. for
4. Which among the following is a valid float literal?
a. 12.36f
b. 12.36F
c. 12.36
d. Both a and b
Ans. d. Both a and b
5. Which among the following is a valid octal integer literal?
a. 0178
b. 675
c. 0675
d. 0X675
Ans. c. 0675
6. Which among the following is a valid method of initialising?
a. boolean f=true;
b. boolean f=True;
c. boolean f=’true’;
d. None of these
Ans. a. boolean f= true;
Page1|5
7. Which among the following is not a punctuator?
a. ; semicolon
b. , comma
c. : colon
d. . dot
Ans. c. : colon
8. Which among the following is not a primitive data type?
a. int
b. float
c. String
d. char
Ans. c. String
9. What is the largest possible value that can be stored in short data type?
a. 215-1
b. 231-1
c. 27-1
d. 263-1
Ans. a. 215-1
10. If a is of type int and b is of type float what would be the resultant data type of a+b?
a. int
b. float
c. double
d. short
Ans. b. float
Very short answer type questions
1. Identify the mistake in each of these lines and correct it:
a. int goto=5;
Ans. The identifier goto is invalid, as it is an identifier.
Correction: int g=5;
b. float a=12.3;
Ans. The float literals should be suffixed with ‘f’.
Correction: float a=12.3f;
c. doubles b=15;
Ans. The data type is wrongly spelled.
Correction: double b=15;
d. long b=1536458888397632;
Ans. The long literal should be suffixed with an ‘L’.
Correction: long b=1536458888397632L;
e. String s= ‘Computer’;
Ans. String literals should be enclosed in double quotes.
Correction: String s= “Computer”;
2. State with reasons why are the following variable names invalid:
a. for
Ans. Invalid, as for is a keyword.
b. book list
Ans. Invalid, as a space cannot be present in a variable name.
c. 2ndTerm
Ans. Invalid, as a variable name cannot begin with a digit.
d. hash#
Page2|5
Ans. Invalid, as a variable name cannot have a special character like #.
e. sick@always
Ans. Invalid, as a variable name cannot have a special character like @.
3. What is the resultant data type of the following mathematical expression?
a+b*c-d
a. Where a is int, b is int, c is float and d is float type
Ans. float
b. Where a is float, b is long, c and d are of int type
Ans. float
c. Where a is of double and b,c and d are of int type.
Ans. double
d. Where a is char and b,c and d are of int type
Ans. int.
e. Where a, b, c and d are of int type, however the expression is slightly modified as (a+b*c-d)/7.0
Ans. Double
Short answer type questions
State with reasons why are the following initializations incorrect:
a. int a=5;
short b=a;
Ans. The short b=a; is invalid as an int cannot be initialised to a short type variable.
b. double a=5.3;
float b=a;
Ans. The float b=a; is invalid as a which is of double type cannot be initialised to a variable of float
type.
c. int a=01238;
Ans. The int a =01238; is invalid as an starting with a 0 is considered to be of octal data type and
therefore cannot have a digit 8.
d. float a=17.36f;
int b=a;
Ans. The int b=a; is invalid as a is of float type, that cannot be initialised to a variable b of int type.
e. boolean a=true;
int b=a;
Ans. The int b=a; is invalid as the assignment is of incompatible type.
Answer the following questions.
1. What is Character Set?
Ans. A character set is a set of alphabets, letters and some special characters that are valid in Java
language.
2. What are keywords?
Ans. A keyword is a reserved word that have a special significance to the compiler and cannot be
used anywhere else other than what it is intended for.
3. What are Identifiers? State the rules while using Identifiers.
Ans. Identifiers are the names of variables, methods, classes, packages and interfaces.
While using identifiers the following set of rules are to be kept in mind.
1. It can have any alphabet (capital or small), digits, underscore and dollar sign characters. For
example, a, b, cat, mat123, cost_price, Topaz$ are all example of valid identifier.
2. It should not begin with digits or should not contain any special character. For example
2ab, ab#c, top@, etc, are invalid identifiers as it either begins with a digit or contain special
Page3|5
characters (like #, @).
3. It cannot have a space between it. For example, simple interest or selling price are invalid
identifiers as it contains a space.
4. It must not be a keyword. For example, for, while, do are invalid identifiers as they are
keywords and are assigned some special function for the language.
5. It can be of any length. Even though Java gives you the flexibility to provide a huge length for
an identifier a very long name is impractical and difficult to manage.
4. What is a literal? What are the different types of literals available in Java?
Ans. Literal is a constant value that can be assigned to a variable.
The different types of literals in Java are:
1. Integer-literal or Fixed point-literal
2. Floating point-literal
3. Boolean-literal
4. Character-literal
5. String-literal
6. Null-literal
7. Class literal
5. State the difference between a boolean literal and a character literal.
Ans. A boolean literal may be either true or false and character literal are always enclosed within
single quotes.
[Link] any two escape sequences used in Java.
Ans. For newline :\n
For tab: \t
7 .What are the different punctuators available in Java?
Ans. There are 9 punctuators available in Java. They are:
(){}[];,.
8 .What are Tokens?
Ans. Token is the fundamental building block of a program that represents a single element of a
programming language.
9. State the difference between token and identifier.
Ans. Token is the fundamental building block of a program that represents a single element of a
programming language. Identifier on the other hand is a token that is used to name different
parts of a program.
10. State the two kinds of data types.
Ans. Primitive data type and Composite data type.
11. How are floating point numbers represented in Java?
Ans. It should be suffixed with f or F.
12. What are variables? How are variables initialized?
Ans. Variables are names given to memory location. Variables are initialised during declaration. For
example,
int a=25;
Page4|5
13. How are symbolic constants represented in Java?
Ans. Symbolic constants are prefixed with the final keyword during declaration. For example,
final int a =100;
14. What are separators?
Ans. Separators are special symbols used to separate statements, data elements or mark blocks in
Java and is therefore also called separators. There are 9 punctuators available in Java. They are:
(){}[];,.
15. What is Type Conversion? Name the two type conversions in Java.
Ans. In a mathematical expression containing operands of more than one data type necessitates to
know the resultant data type of an expression. The resultant data type of an expression can be
categorized into two segments.
• Implicit type conversion
• Explicit type conversion
16. Name two keywords which are also literals in Java.
Ans. They are null, true and false.
17. What do you understand by variable scope?
Ans. Variable scope is the area in which a variable is accessible or have its life.
28. What are the three types of integer literals that can be represented in Java?
Ans. Decimal Integer Literal, Octal Integer Literal and Hexadecimal Integer Literal
Page5|5