KnowledgeBoat Logo
OPEN IN APP

Chapter 4

Values and Data Types

Class 9 - Logix Kips ICSE Computer Applications with BlueJ



Multiple Choice Questions

Question 1

ASCII stands for ...........

  1. American Standard Code for Information Interchange ✓
  2. American Simulated Code for Information Interchange
  3. American Standard Code for Interchange of Information
  4. American Standard Code for Interaction of Information

Question 2

ASCII is ...........

  1. 6-bit set of codes
  2. 8-bit set of codes
  3. 7-bit set of codes ✓
  4. 16-bit set of codes

Question 3

Extended ASCII is ...........

  1. 6-bit set of codes
  2. 8-bit set of codes ✓
  3. 7-bit set of codes
  4. 16-bit set of codes

Question 4

Which of the following is not a token?

  1. Keyword
  2. Identifiers
  3. Operators
  4. Procedure ✓

Question 5

Which of the following is a keyword?

  1. character
  2. break ✓
  3. object
  4. attribute

Question 6

Which of the following is not a legal identifier?

  1. _age
  2. $Amount
  3. 9thClass ✓
  4. nullValue

Question 7

Which of the following is an invalid integer?

  1. 1999
  2. 1999999
  3. 199 99 ✓
  4. 199

Question 8

Which of the following is not a character literal?

  1. '\t'
  2. "t" ✓
  3. 't'
  4. All of these

Question 9

Which of the following punctuator is the statement terminator in Java?

  1. ; ✓
  2. .
  3. ,
  4. All of these

Question 10

Which of the following is not a primitive data type in Java?

  1. boolean
  2. short
  3. float
  4. class ✓

Question 11

Which of the following is the size of a long data type in Java?

  1. 32 bits
  2. 64 bits ✓
  3. 48 bits
  4. Long data type is not supported in Java.

Question 12

Which of the following is the size of a boolean data type in Java?

  1. 1 bit
  2. 16 bits
  3. 8 bits ✓
  4. Boolean data type doesn't take any space in memory.

State whether the given statements are True or False

Question 1

Java supports the use of the ASCII character set only.
False

Question 2

The smallest unit in a Java program is known as token.
True

Question 3

The Unicode character set uses 8 to 32 bits per character.
True

Question 4

In an escape sequence, a character is preceded by a forward slash (/).
False

Question 5

In Java, an identifier cannot begin with a $ sign.
False

Question 6

The boolean data types are used for storing logical values.
True

Question 7

Java offers five types of tokens.
True

Question 8

The char data type reserves 8 bits in memory.
False

Question 9

If a literal constant contains a decimal point, then it is of the type double by default.
True

Question 10

The modifier final can be applied to a variable declaration to ensure that the value stored in the variable cannot be changed after the variable has been initialised.
True

Assignment Questions

Question 1

What are escape sequences in Java? Give three examples.

Answer

An escape sequence is a set of characters that has a special meaning to the Java compiler. In the escape sequence, a character is preceded by a backslash (\). Some examples of escape sequences are \n, \' and \t.

Question 2

What is the result of evaluating the following expression?
  (1 + 2 * 2) / 2 + 2

Answer

    (1 + 2 * 2) / 2 + 2 ⇒ (1 + 4) / 2 + 2
⇒ (5) / 2 + 2
⇒ 2 + 2
⇒ 4

Question 3

What is a token in Java? Name the tokens available in Java.

Answer

All characters in a Java program are grouped into symbols called Tokens. As you know, a computer program consists of a set of instructions called statements. A statement is composed of various components. Each individual component of a programming statement is referred to as a token. Keywords, identifiers, Operators, Separators and literals are three tokens in Java.

Question 4

Why can't you use a keyword as a variable name?

Answer

Keywords are reserved words that have a special meaning to the Java compiler. As Java compiler reserves these words for its own use so they are not available as names for variables or methods.

Question 5

Which of the following are Java keywords?
    input, class, public, int, x, y, radius

Answer

class, public, int are Java keywords.

Question 6

What are identifiers in Java? List three identifier formation rules.

Answer

Identifiers are used to name different parts of a program such as variables, methods, classes, objects, etc. Three identifier formation rules are:

  1. An an identifier can be a sequence of alphabets, digits, underscore and dollar sign characters only.
  2. Identifiers cannot start with a digit.
  3. An identifier must not be a Keyword or a Boolean or null literal.

Question 7

Explain the following statement — "In Java, total, Total, ToTaL, and TOTAL are all different identifiers."

Answer

Java is a case sensitive language. total, Total, ToTaL, and TOTAL have the same set of letters but they differ in the case of these letters. Therefore, Java considers each of them as a different identifier.

Question 8

How would you print characters like \, ' and " in Java?

Answer

We can print characters like \, ' and " using escape sequences i.e. preceding it with a backslash (\) symbol.

Question 9

Distinguish between the following:

i. Token and Identifier

Answer

TokenIdentifier
Each individual component of a programming statement is referred to as a token.Identifiers are fundamental building blocks of the program and are used to name different components of a program such as variables, methods and objects.
Tokens in Java are categorised into 5 types — Keywords, Identifiers, Literals, Punctuators, Operators.Identifier is a type of token in Java.

ii. Keyword and Identifier

Answer

KeywordIdentifier
Keywords have a special meaning for Java compiler.Identifiers are used to name different components of a program such as variables, methods and objects.
Keywords are reserved by the compiler for its own use.An identifier must not be a Keyword.

iii. Character and String Constant

Answer

Character ConstantString Constant
Character Constants are written by enclosing a character within a pair of single quotes.String Constants are written by enclosing a set of characters within a pair of double quotes.
Character Constants are assigned to variables of type char.String Constants are assigned to variables of type String.

iv. Integer and float Constant

Answer

Integer ConstantFloat Constant
Integer Constants represent whole number values like 2, -16, 18246, 24041973, etc.Float Constants represent fractional numbers like 3.14159, -14.08, 42.0, 675.238, etc.
Integer Constants are assigned to variables of data type — byte, short, int, long, charFloat Constants are assigned to variables of data type — float, double

Question 10

Distinguish between "A" and 'A'.

Answer

"A" is a string literal of length 1 containing the letter A in uppercase whereas 'A' is a character literal having value of A in uppercase.

Question 11

Describe primitive data types in Java.

Answer

Primitive data types are fundamental data types that are an integral part of the Java language and are used to declare a variable.

Question 12

List the size of primitive data types in Java.

Answer

Data TypeSize in Bytes
byte1
short2
int4
long8
float4
double8
char2
boolean1

Question 13

Which integer and floating point data types take up the same number of bits in computer's memory?

Answer

Both, int and float take up 32 bits in memory. Similarly, both long and double take up 64 bits in memory.

Question 14

What is variable initialisation in Java? What are the default values of the following type of variables:
short, int, long, float, double, and char.

Answer

Variable initialisation means assigning value to a variable for the first time. Below are the default values of the different data types:

Data TypeDefault Value
short0
int0
long0L
float0.0f
double0.0d
char'\u0000'

Video Explanations

PrevNext