CS110 Java Practice Quiz #2

The Basics of a Java Program




  Choose the best alternative:
  1. consists of a list of instructions written in a computer language.

  2. One example of a computer language is

  3. A line that begins with // is a(n)

  4. int is a primitive data type.

  5. Describe the syntax used for commenting multiple lines.

  6. A is used to explain various aspects of the program to a human reader.


    Click on those of the following which are legal identifiers

  7. Temp_X
  8. Site-Num
  9. Tax%
  10. T1
  11. 1T
  12. int

  13. A variable is an object that is .

  14. The keyword final describes an object that is .

  15. A variable of int type can hold the value

  16. In the assignment statement below, x is a(n)
    x = 6 * 7 + 3;

  17. In any given assignment statement, the expression must always appear on the side

  18. In the assignment statement below, item * .17 is the
    tax = item * .17;

  19. What output is produced by the segment of code shown below:
    int tax = 7 * 3;
    System.out.println(tax);

  20. What output is produced by the code segment below?
    int X = 7;
    int Y = 6;
    X = Y;
    System.out.println(X);



Answers
  1. A computer program. Java is a computer programming language.
  2. Java. Excel is an example of a software application written in a computer language.
  3. comment. Two slashes are used to comment (document) your code.
  4. TRUE. Keywords are reserved and cannot be used in Java for other purposes.
  5. /* */
  6. comment. A comment is used to document code and explain what is going on.
  7. Yes. You may include underscores in Java identifiers.
  8. No. You may NOT include dashes in Java identifiers.
  9. No. Puncuation characters are not allowed in Java identifiers.
  10. Yes. An identifier may include numbers after the first character.
  11. No. Identifiers MUST begin with a letter.
  12. No. Java keywords are reserved and cannot be used as identifiers.
  13. dynamic. A variable is dynamic because its value can change.
  14. The keyword final refers to an object that is static because its value remains unchanged.
  15. 345 in an integer. 34.5 is a real number.
  16. variable. x is a variable in this example and 6 * 7 + 3 is the expression.
  17. right. A single variable appears on the left side in an expression statement.
  18. expression that is evaluated. Tax is the variable that is assigned the value of the expression Item * .17;
  19. 21. The expression 7 * 3 is evaluated at 21, which is assigned to Tax and output.
  20. 6. X is re-assigned the value of Y (which is 6).