Values and Data Types

ICSE Class 10 Computer Applications · Logix Computer Applications · 60 solved questions

Exercise
Marks
11 Mark · Multiple Choice Questions

Java uses ........... character set.

Show SolutionHide Solution↓
  • Unicode ✓
  • 21 Mark · Multiple Choice Questions

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

    Show SolutionHide Solution↓
  • American Standard Code for Information Interchange ✓
  • 31 Mark · Multiple Choice Questions

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

    Show SolutionHide Solution↓
  • 7-bit set of codes ✓
  • 41 Mark · Multiple Choice Questions

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

    Show SolutionHide Solution↓
  • 8-bit set of codes ✓
  • 51 Mark · Multiple Choice Questions

    The smallest individual component in a program is called ...........

    Show SolutionHide Solution↓
  • Token ✓
  • 61 Mark · Multiple Choice Questions

    Which of the following is not a token?

    Show SolutionHide Solution↓
  • Procedure ✓
  • 71 Mark · Multiple Choice Questions

    Which of the following is a keyword?

    Show SolutionHide Solution↓
  • break ✓
  • 91 Mark · Multiple Choice Questions

    Which of the following is a default value of float data type?

    Show SolutionHide Solution↓
  • 0.0f ✓
  • 101 Mark · Multiple Choice Questions

    Which of the following is a default value of boolean data type?

    Show SolutionHide Solution↓
  • false ✓
  • 111 Mark · Multiple Choice Questions

    Which of the following is an invalid integer?

    Show SolutionHide Solution↓
  • 222 22 ✓
  • 121 Mark · Multiple Choice Questions

    Which of the following is not a character literal?

    Show SolutionHide Solution↓
  • "n" ✓
  • 131 Mark · Multiple Choice Questions

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

    Show SolutionHide Solution↓
  • ; ✓
  • 141 Mark · Multiple Choice Questions

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

    Show SolutionHide Solution↓
  • class ✓
  • 151 Mark · Multiple Choice Questions

    What is the size of a long data type in Java?

    Show SolutionHide Solution↓
  • 64 bits ✓
  • 161 Mark · Multiple Choice Questions

    What is the size of a boolean data type in Java?

    Show SolutionHide Solution↓
  • 8 bits ✓
  • 171 Mark · Multiple Choice Questions

    Single line comments can be added using ...........

    Show SolutionHide Solution↓
  • Both A and B ✓
  • 181 Mark · Multiple Choice Questions

    Which of the following changes a variable declaration into a constant?

    Show SolutionHide Solution↓
  • final ✓
  • 191 Mark · Multiple Choice Questions

    The ASCII codes of A-Z are represented by decimal range ...........

    Show SolutionHide Solution↓
  • 65-90 ✓
  • 201 Mark · Multiple Choice Questions

    Which of the following is a primitive data type?

    Show SolutionHide Solution↓
  • boolean ✓
  • 1State whether the given statements are True or…

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

    Solution not available in the source paper.

    2State whether the given statements are True or…

    The ASCII code for character 'Z' is 90.
    True

    Solution not available in the source paper.

    3State whether the given statements are True or…

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

    Solution not available in the source paper.

    4State whether the given statements are True or…

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

    Solution not available in the source paper.

    5State whether the given statements are True or…

    In an escape sequence, a character is preceded by a backward slash (\).
    True

    Solution not available in the source paper.

    6State whether the given statements are True or…

    In Java, an identifier can begin with a $ sign.
    True

    Solution not available in the source paper.

    7State whether the given statements are True or…

    The boolean data type is used for storing logical values.
    True

    Solution not available in the source paper.

    8State whether the given statements are True or…

    Java offers five types of tokens.
    True

    Solution not available in the source paper.

    9State whether the given statements are True or…

    Identifiers in Java may be of any length.
    True

    Solution not available in the source paper.

    10State whether the given statements are True or…

    The char data type reserves 8 bits in memory.
    False

    Solution not available in the source paper.

    11State whether the given statements are True or…

    Default value of reference data type is null.
    True

    Solution not available in the source paper.

    12State whether the given statements are True or…

    To designate a literal constant of the type float, you must append the letter L to it.
    False

    Solution not available in the source paper.

    13State whether the given statements are True or…

    Default value of char data type is '\u0000'.
    True

    Solution not available in the source paper.

    14State whether the given statements are True or…

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

    Solution not available in the source paper.

    15State whether the given statements are True or…

    A variable can be used in a Java program even if it has not been declared.
    False

    Solution not available in the source paper.

    1Assignment Questions

    Why does Java use the Unicode character set?

    Show SolutionHide Solution↓

    Unicode can represent nearly all languages of the world like English, Hindi, Bengali, Kannada, Arabic, Japanese, etc. Java uses unicode so that applications developed using Java can support a wide range of languages rather than just being limited to English.

    2Assignment Questions

    What are escape sequences in Java? Give three examples.

    Show SolutionHide Solution↓

    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.

    3Assignment Questions

    What is the result of evaluating the following expression?
    (3 + 6 * 7) / 3 + 2

    Show SolutionHide Solution↓

        (3 + 6 * 7) / 3 + 2
    ⇒ (3 + 42) / 3 + 2
    ⇒ 45 / 3 + 2
    ⇒ 45 / 3 + 2
    ⇒ 15 + 2
    ⇒ 17

    4Assignment Questions

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

    Show SolutionHide Solution↓

    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 five tokens in Java.

    5Assignment Questions

    Why can a keyword not be used as a variable name?

    Show SolutionHide Solution↓

    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.

    6Assignment Questions

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

    Show SolutionHide Solution↓

    class, public, int, long are Java keywords.

    7Assignment Questions

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

    Show SolutionHide Solution↓

    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.
    8Assignment Questions

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

    Show SolutionHide Solution↓

    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.

    9Assignment Questions

    Which of the following are invalid identifiers?

    i. ten
    ii. "Hello"
    iii. 5678
    iv. Coffee
    v. $dollar
    vi. 4Variables
    vii. _var

    Show SolutionHide Solution↓
    • "Hello" is invalid as identifiers cannot contain double quotes.
    • 5678 is invalid as identifiers cannot start with a digit.
    • 4Variables is invalid as identifiers cannot start with a digit.
    10Assignment Questions

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

    Show SolutionHide Solution↓

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

    11Assignment Questions

    Distinguish between the following:

    i. Token and Identifier

    Show SolutionHide Solution↓
    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

    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

    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

    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
    12Assignment Questions

    Distinguish between "A" and 'A'.

    Show SolutionHide Solution↓

    "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.

    13Assignment Questions

    What is wrong with the following statement?
        float flt = 7895.0345;

    Show SolutionHide Solution↓

    This statement is trying to assign a double literal to a float variable so it will result in a syntax error of incompatible types (possible lossy conversion from double to float). To fix it we need to a f or F at the end of the double literal to make it a float literal as shown below:
        float flt = 7895.0345f;

    14Assignment Questions

    Describe primitive data types in Java.

    Show SolutionHide Solution↓

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

    15Assignment Questions

    List the size of primitive data types in Java.

    Show SolutionHide Solution↓
    Data TypeSize in Bytes
    byte1
    short2
    int4
    long8
    float4
    double8
    char2
    boolean1
    16Assignment Questions

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

    Show SolutionHide Solution↓

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

    17Assignment Questions

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

    Show SolutionHide Solution↓

    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'
    18Assignment Questions

    Provide the declaration for two variables called xCoordinate and yCoordinate. Both variables are of type int and both are to be initialised to zero in the declaration.

    Show SolutionHide Solution↓
    int xCoordinate = 0;  
    int yCoordinate = 0;

    OR

    int xCoordinate = 0, yCoordinate = 0;  
    19Assignment Questions

    Write a Java assignment statement that will set the value of the variable interestAmount to the value of the variable balanceAmount multiplied by the value of the variable rate. The variables are of type double.

    Show SolutionHide Solution↓
    double interestAmount = balanceAmount * rate;
    20Assignment Questions

    Explain the statement, "a well-documented code is as important as the correctly working code".

    Show SolutionHide Solution↓

    Writing fully commented code is a good programming style. The primary purpose of comments is to document the code so that even a layman can understand the purpose of the written code. Hence, a well-documented code is as important as the correctly working code.

    21Assignment Questions

    How can you write single line comments in Java?

    Show SolutionHide Solution↓

    Single line comments in Java can be written using //. For example:

    // This is an example of single line comment.
    22Assignment Questions

    Write a Java constant declaration that gives the name TAX_RATE to the value 15%.

    Show SolutionHide Solution↓
    final int TAX_RATE = 15;
    23Assignment Questions

    If you want to change the precedence of operations in an expression, which symbols do you use?

    Show SolutionHide Solution↓

    Brackets — () can be used to change operator precedence.

    24Assignment Questions

    What are symbolic constants? How are they useful in writing programs?

    Show SolutionHide Solution↓

    Memory locations whose values cannot be changed within a program are called constants or symbolic constants. The advantages of symbolic constants are:

    1. It improves the readability of the program and makes it easier for someone to understand the code.
    2. Any unintentional changes to such variables are flagged by the compiler.
    3. Later, if there is a change in the value of such variables (e.g. interest rate changed), you just need to modify its value at one place and all the other occurrences will be taken care of automatically.
    25Assignment Questions

    What is the output produced by the following lines of program code?

    char x, y;
    x = 'y';
    System.out.println(x);
    y = 'z';
    System.out.println(y);
    x = y;
    System.out.println(x);
    Show SolutionHide Solution↓

    Below is the output produced by this code:

    y
    z
    z

    Variable x is assigned a value of character y so the first println prints y. Variable y is assigned a value of character z so the second println prints z. After that variable x is assigned the value of variable y which is the character z so last println prints z.

    Press ↓ to reveal a solution and move to the next question. Back to Logix Computer Applications.

    Free sample bank