CS110 Java Practice Quiz #2
The Basics of a Java Program
Choose the best alternative:
Java
A computer program
consists of a list of instructions written in a computer language.
One example of a computer language is
Excel
Java
A line that begins with // is a(n)
comment
error message
int
is a primitive data type.
TRUE
FALSE
Describe the syntax used for commenting multiple lines.
A
variable
comment
is used to explain various aspects of the program to a human reader.
Click on those of the following which are
legal
identifiers
Temp_X
Site-Num
Tax%
T1
1T
int
A variable is an object that is
dynamic
static
.
The keyword
final
describes an object that is
dynamic
static
.
A variable of
int
type can hold the value
34.5
345
In the assignment statement below,
x
is a(n)
variable
expression
x = 6 * 7 + 3;
In any given assignment statement, the
expression
must always appear on the
left
right
side
In the assignment statement below,
item * .17
is the
variable that is assigned a value.
expression that is evaluated.
tax = item * .17;
What output is produced by the segment of code shown below:
int tax = 7 * 3;
System.out.println(tax);
What output is produced by the code segment below?
int X = 7;
int Y = 6;
X = Y;
System.out.println(X);
Answers
A computer program. Java is a computer programming language.
Java. Excel is an example of a software application written in a computer language.
comment. Two slashes are used to comment (document) your code.
TRUE. Keywords are reserved and cannot be used in Java for other purposes.
/* */
comment. A comment is used to document code and explain what is going on.
Yes. You may include underscores in Java identifiers.
No. You may NOT include dashes in Java identifiers.
No. Puncuation characters are not allowed in Java identifiers.
Yes. An identifier may include numbers after the first character.
No. Identifiers MUST begin with a letter.
No. Java keywords are reserved and cannot be used as identifiers.
dynamic. A variable is dynamic because its value can change.
The keyword
final
refers to an object that is static because its value remains unchanged.
345 in an integer. 34.5 is a real number.
variable.
x
is a variable in this example and
6 * 7 + 3
is the expression.
right. A single variable appears on the left side in an expression statement.
expression that is evaluated. Tax is the variable that is assigned the value of the expression Item * .17;
21. The expression 7 * 3 is evaluated at 21, which is assigned to Tax and output.
6. X is re-assigned the value of Y (which is 6).