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
Q

Describe the literal int, short, byte

A

Optional initial sign (+ or -) followed by digits 0-9 in any combination

26
Q

Describe the literal long

A

Optional initial sign (+ or -) followed by digits 0-9 in any combination, terminated with an L

27
Q

What are interger literals that begin with 0 considered

A

They’re considered to be octal values

28
Q

What are integer literals that begin with 0x considered to be

A

They’re considered to be hexadecimal values

29
Q

Describe the float in floating point literals

A

Optional initial sign (+, or -) followed by a floating-point number in fixed or scientific format, terminated by a F

30
Q

Describe the double in floating point literals

A

Optional initial sign (+ or -) followed by a floating point number in fixed or scientific format

31
Q

what is a common error with integer or floating point literals

A

Commas, dollar signs, and percent signs (%) cannot be used in integer or floating point literals

32
Q

What is a char

A

Any printable character enclosed in single quotes

33
Q

What is rule 1 of assigning the values of other variables

A

Variable 1 needs to defined before this statement appears in the source code

34
Q

What in rule 2 of assigning values of other variables

A

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
Q

What is a common error trap with variables

A

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
Q

What is a string

A

String is a class not a basic data type.

37
Q

What is a string variable

A

String variables are objects

38
Q

What do String Concatenation Operator do

A

Combines String literals with other data types for printing

39
Q

What is the common error trap with string literals

A

String literals must start and end on the same line

40
Q

What is important to do with long strings to avoid common errors

A

Break long strings into shorter strings and use the concatenation operator

41
Q

How do you include a special character in a string

A

You use an escape sequence

42
Q

In what situation would you use a constant

A

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
Q

Whats the convention for naming a constant

A

use all capital letters for constants and separate words with an underscore

44
Q

What is an expression

A

Operators and operands that evaluate to a single value,

45
Q

What happens to the single value (as a result of an expression)

A

The value is then assigned to a target

46
Q

What is the requirement for a target (in relation to a single value as a result of an expression)

A

The target must be a variable or a constant and the value must be compatible with target’s data type

47
Q

When is operator precedence used

A

If more than one operator is used in an expression, the order of evaluation is determined using an operator precedence.

48
Q

What is the order used in operator precedence

A

Expressions in parentheses are evaluated first

Multiplication, division, and modulus are performed before addition and subtraction

49
Q

How would you evaluate an expression that has multiple arithmetic operators of the same precedence

A

They are evaluated left to right. An assignment is performed last and is performed right to left.

50
Q

What happens when two integers are divided

A

The quotient is an integer

Any fractional part is truncated (discarded).

51
Q

How do you get a remainder when you divide two intergers

A

Use the modulus operator with the same operands

52
Q

Whats the result in floating point division( by 0) if the dividends not 0

A

The result is infinity

53
Q

What is the result in floating point division( by 0) if the dividend and divisor are both 0

A

Nan (not a number)

54
Q

What occurs when you perform calculations with operands of different data types

A

Lower precision operands are promoted to higher precision data types, then the operation is performed..

55
Q

What is special about implicit type casting

A

Promotion is effective only for expression evaluation; not a permanent change