Deck 2: Programming Building Blocks- Java Basics
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/57
Play
Full screen (f)
Deck 2: Programming Building Blocks- Java Basics
1
There are __________ bytes in a long integer data type.
8
2
User-defined words in Java:
A) are used as identifiers.
B) consist of keywords used in Java instruction.
C) are not case-sensitive.
D) include two special data values, true and false.
A) are used as identifiers.
B) consist of keywords used in Java instruction.
C) are not case-sensitive.
D) include two special data values, true and false.
A
3
Blocks are required for class and concrete method definitions. They consist of 0, 1, or more statements, start with a left curly brace, and end with a right curly brace.
True
4
Any of Java's reserved words can be used as identifiers.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
5
Which of the following is a primitive data type in Java?
A) Byte
B) Float
C) Char
D) All of these are correct.
A) Byte
B) Float
C) Char
D) All of these are correct.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
6
Which of the following is not true about assigning values?
A) Assigning a value is optional when the constant is defined.
B) You must assign a value before the constant is used in a program.
C) A constant's value can be reassigned three times or fewer in a program.
D) Attempting to change the value of a constant will generate a compiler error.
A) Assigning a value is optional when the constant is defined.
B) You must assign a value before the constant is used in a program.
C) A constant's value can be reassigned three times or fewer in a program.
D) Attempting to change the value of a constant will generate a compiler error.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
7
Variables need to be declared twice so they can be used in your program: once at the beginning and then at the end of the program.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
8
Because Unicode characters are encoded as unsigned numbers using 16 bits, a char variable is stored in two bytes of memory.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
9
What is operator precedence?
A) A set of rules to determine the order in which the operations should be performed
B) Operands used to perform a function
C) A variable or a constant having a data type compatible with the value of the expression
D) A system that recognizes the importance of the programmer in designing the operands
A) A set of rules to determine the order in which the operations should be performed
B) Operands used to perform a function
C) A variable or a constant having a data type compatible with the value of the expression
D) A system that recognizes the importance of the programmer in designing the operands
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
10
Division with two integer operands is performed in the Arithmetic Logic Unit (ALU), which can only calculate an integer result.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
11
It is legal to assign a float value to a double. Which of these statement pairs is not valid?
A) float salesTax = .05f;
B) double taxRate = .05;
C) float salesTax = taxRate;
D) double taxRate = salesTax;
A) float salesTax = .05f;
B) double taxRate = .05;
C) float salesTax = taxRate;
D) double taxRate = salesTax;
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
12
How can you create a String literal that includes a newline character?
A) Java provides a set of escape sequences that can be used to include a special character within String and char literals.
B) Declare the variables before you use them.
C) Use the + operator.
D) Use /*.
A) Java provides a set of escape sequences that can be used to include a special character within String and char literals.
B) Declare the variables before you use them.
C) Use the + operator.
D) Use /*.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
13
If you specify that a data item is a double (a double-precision floating-point number), then the compiler will allocate 16 bytes of memory and store its value as an IEEE 754 floating-point number.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
14
The arithmetic operation 7x + 2y can be written without using parentheses.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
15
A boolean data type can hold only one value: true.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
16
Java is case-sensitive, so although True is a reserved word, true is not.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
17
Java identifiers must start with a(n) _________ and may contain any combination of letters and digits, but no spaces.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
18
______ is reserved as a special code for "not a character."
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
19
The mod operator % returns the __________ of the division between two numbers.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
20
In addition to having the same name as the class name, each Java source code file must have a(n) _________extension.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
21
Which one of these is not a primitive data type?
A) int
B) double
C) bool
D) long
E) char
A) int
B) double
C) bool
D) long
E) char
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
22
The result of 3 / 2 is:
A) 1.
B) 1.5.
C) 3.
D) 2.
E) 0.
A) 1.
B) 1.5.
C) 3.
D) 2.
E) 0.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
23
The result of 9 % 2 is:
A) 1.
B) 4.5.
C) 4.
D) 2.
E) 0.
A) 1.
B) 4.5.
C) 4.
D) 2.
E) 0.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
24
The result of 3.0 / 2 is:
A) 1.
B) 1.5.
C) 3.
D) 2.
E) 0.
A) 1.
B) 1.5.
C) 3.
D) 2.
E) 0.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
25
The result of (double) ( 3 / 2 ) is:
A) 1.0.
B) 1.5.
C) 3.0.
D) 2.0.
E) 0.0.
A) 1.0.
B) 1.5.
C) 3.0.
D) 2.0.
E) 0.0.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
26
The result of (double) 3 / 2 is:
A) 1.0.
B) 1.5.
C) 3.0.
D) 2.0.
E) 0.0.
A) 1.0.
B) 1.5.
C) 3.0.
D) 2.0.
E) 0.0.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
27
helloWorld is a valid identifier.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
28
int9 is a valid identifier.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
29
char is a valid identifier.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
30
2008taxRate is a valid identifier.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
31
tax Rate is a valid identifier.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
32
A double is more precise than a float.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
33
* is a unary operator.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
34
The Java keyword for a constant is __________.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
35
The two floating point data types are __________ and float.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
36
char values are surrounded by __________ quotes.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
37
String literals are surrounded by __________ quotes.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
38
A Java escape sequence starts with a(n) __________.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
39
The division operator / returns the __________ of the division between two numbers.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
40
Describe two ways to introduce a comment.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
41
Compare and contrast single-precision and double-precision floating-point data types.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
42
When you declare a variable, with an assignment operator (=) with the following syntax:
dataType variableName = initialValue;
How would you read the sentence?
dataType variableName = initialValue;
How would you read the sentence?
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
43
Would it be better to use doubles or floats for calculations to scale up recipes to feed three times as many people as the recipes are written to serve?
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
44
What are three ways to add 1 to an int variable named number?
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
45
Assuming number is an int variable, write a statement using a shortcut operator equivalent to this one:
number = number * 5;
number = number * 5;
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
46
Rewrite the following into one statement:
int age;
age = 32;
int age;
age = 32;
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
47
You want to insert the comment "Java is better than ice cream." Identify two ways to include this comment in your code.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
48
What are some advantages of using variables?
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
49
Compare the variable identifiers numberOfStudentsPassing and winners. Describe which would be preferable in a program that evaluates success of a teaching program.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
50
Sam wants to calculate whether his students simply passed or failed. He uses a char variable, because student grades are A through F. Is this the best data type to use? Why or why not?
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
51
One way to specify an initial value for a variable (variable 1) is to assign the variable the value of another variable (variable 2). Explain why it is not valid to assign variable 1 as a double and variable 2 as a float.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
52
What will happen if your String literal is longer than one line?
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
53
List two errors in the following statement:
System.out.println( "Remember the slogan "Click It or Ticket" and buckle
your seatbelt before driving your car." );
System.out.println( "Remember the slogan "Click It or Ticket" and buckle
your seatbelt before driving your car." );
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
54
How would you create an indented poem in a String literal statement?
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
55
Would it be better to write PI or 3.14159 in an arithmetic expression?
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
56
In which order should the computer do the following calculation? Solve the expression.
int dimes = 2 * 20 + 5 * 10 + 3 * 5;
int dimes = 2 * 20 + 5 * 10 + 3 * 5;
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
57
What does the shortcut ++ do?
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck