Chapter 2 PDF Flashcards

1
Q

What is the typical program structure

A

Input some data
Perform some processing on the data
Output the results

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Describe what could happen in each execution of the program

A

The data might be different

Instructions will be the same

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What do all Java Application programs consist of

A

All programs consist of at least one class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are identifiers used to name

A

Classes, variables and methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are some identifier rules

A

Must start with a Java Letter
Can contain essentially any number of java letters and digits but no spaces
Case sensitive
Cannot be keywords or reserved words

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Is this identifier valid: taxRate

A

yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Is this identifier valid: char

A

No. Char is a keyword

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Is this identifier valid: intNumber

A

Yes, the keyword int is embedded but the identifier is not identical to a keyword

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Is this identifier valid: 2008Taxrate

A

No. The identifier starts with a digit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Describe the statement in a program building block

A

Performs some action
Terminates with a semicolon;
Can span multiple lines

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Describe the block in the program building block

A

0,1, or more statements
begins and ends with curly braces {}
Can be used anywhere a statement is allowed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are white space characters. Describe them

A
  • Space, tab, and newline are white space characters.
  • At least one white space character is required between a keyword and identifier.
  • Any number of white space characters are permitted between identifiers, keywords, operators, and literals.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are comments used for

A

Comments explain the program to yourself and others.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you comment a line

A

Begin with /* and end with */

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a requirement for all data

A

That you assign a name and a data type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the purpose of a data type

A

How much memory to allocate
How to store the data
The types of operations you will perform on the data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are the eight primitive data types

A
byte
short
int
long
float
double
char
boolean
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How many values can a variable hold

A

Variables hold one value at a time, but the value can change as the program executes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Describe the naming convention for variable names

A

First letter is lowercase

Embedded words begin with an uppercase letter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What are boolean values used for

A

Boolean values are used for decision making or as flag variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Describe what putting an assignment operator does to variables

A

Value on the right of the operator is assigned to variable on the left

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What can the variable on the right be

A

A literal, another variable, or an expression

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is a literal

A

Text representing a specific value

24
Q

What is an expression

A

A valid combination of variables, operators and constants

25
Describe the literal int, short, byte
Optional initial sign (+ or -) followed by digits 0-9 in any combination
26
Describe the literal long
Optional initial sign (+ or -) followed by digits 0-9 in any combination, terminated with an L
27
What are interger literals that begin with 0 considered
They're considered to be octal values
28
What are integer literals that begin with 0x considered to be
They're considered to be hexadecimal values
29
Describe the float in floating point literals
Optional initial sign (+, or -) followed by a floating-point number in fixed or scientific format, terminated by a F
30
Describe the double in floating point literals
Optional initial sign (+ or -) followed by a floating point number in fixed or scientific format
31
what is a common error with integer or floating point literals
Commas, dollar signs, and percent signs (%) cannot be used in integer or floating point literals
32
What is a char
Any printable character enclosed in single quotes
33
What is rule 1 of assigning the values of other variables
Variable 1 needs to defined before this statement appears in the source code
34
What in rule 2 of assigning values of other variables
Variable 1 and variable 2 need to be compatible data types; in other words, the precision of variable 1 must be lower than or equal to that of variable2
35
What is a common error trap with variables
You need to declare a variable only once. After a variable is declared, its data type cannot be changed. After a variable is declared, its data type cannot be changed.
36
What is a string
String is a class not a basic data type.
37
What is a string variable
String variables are objects
38
What do String Concatenation Operator do
Combines String literals with other data types for printing
39
What is the common error trap with string literals
String literals must start and end on the same line
40
What is important to do with long strings to avoid common errors
Break long strings into shorter strings and use the concatenation operator
41
How do you include a special character in a string
You use an escape sequence
42
In what situation would you use a constant
Sometimes you know the value of a data item, and you know that its value will not change during program execution. Then you would define it as a constant.
43
Whats the convention for naming a constant
use all capital letters for constants and separate words with an underscore
44
What is an expression
Operators and operands that evaluate to a single value,
45
What happens to the single value (as a result of an expression)
The value is then assigned to a target
46
What is the requirement for a target (in relation to a single value as a result of an expression)
The target must be a variable or a constant and the value must be compatible with target's data type
47
When is operator precedence used
If more than one operator is used in an expression, the order of evaluation is determined using an operator precedence.
48
What is the order used in operator precedence
Expressions in parentheses are evaluated first | Multiplication, division, and modulus are performed before addition and subtraction
49
How would you evaluate an expression that has multiple arithmetic operators of the same precedence
They are evaluated left to right. An assignment is performed last and is performed right to left.
50
What happens when two integers are divided
The quotient is an integer | Any fractional part is truncated (discarded).
51
How do you get a remainder when you divide two intergers
Use the modulus operator with the same operands
52
Whats the result in floating point division( by 0) if the dividends not 0
The result is infinity
53
What is the result in floating point division( by 0) if the dividend and divisor are both 0
Nan (not a number)
54
What occurs when you perform calculations with operands of different data types
Lower precision operands are promoted to higher precision data types, then the operation is performed..
55
What is special about implicit type casting
Promotion is effective only for expression evaluation; not a permanent change