chapter 2 Flashcards

1
Q

constant

A

data type that cannot be changed when program is running

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

literal constant

A

value taken literally at each use, e.g. numeric or boolean

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

unnamed constant

A

no identifies associated with it

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

variable

A

a named memory location
Used to store a value
Can hold only one value at a time
Its value can change

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

Data type

A

A type of data that can be stored
How much memory an item occupies
What types of operations can be performed on data

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

Primitive data type

A

a simple data type, 8 of these exist:

byte, short, int, long, float, double, char, booleon

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

Reference types

A

more complex data type such as string

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

Name variables

A

named memory locations used for legal class identifiers

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

variable declaration

A

a statement that reserves a named memory location, this includes:
Data type
Identifier
Optional assignment operator and assigned value
Ending semicolon

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

Assignment operator

A

The equal sign (=)

The value to the right is assigned to the variable on the left

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

Initialization

A

An assignment made when declaring a variable

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

Assignment

A

An assignment made after a variable is declared

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

Associativity

A

The order in which operands are used with operators

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

Whats the difference between declaring variables of the same type vs variables of a different type

A

variables of the same type may be declared on a single line whereas variables of different types must be declared on separate lines

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

Named constant

A
  • Should not change during program execution
  • Has a data type, name, and value
  • Has a data type preceded by the keyword final
  • Can be assigned a value only once
  • Conventionally is given identifiers using all uppercase letters
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Why use named constants

A
  • Make programs easier to read and understand
  • Enable you to change a value at one location within a program
  • Reduce typographical errors
  • Stand out as separate from variables
  • Eliminates magic numbers
17
Q

Scope

A
  • The area in which a data item is visible to a program, and in which you can refer to it using its simple identifier
  • A variable or constant is in scope from the point it is declared
  • Until the end of the block of code where the declaration lies
18
Q

What is a booleon

A

a true or false value

19
Q

what is a relational operator

A

an operator that compares two item

20
Q

what is a char data type

A

a data type which holds a single character

21
Q

what is a String

A
  • built in class
  • stores and manipulates character strings
  • string constants are written between double quotes “”
22
Q

what is the issue of using a numeric scanner such as nextInt()

A

Keyboard buffer:

  • This is a location in memory that stores all keystrokes, including enter
  • As a result if the first scanner is an Integer scanner it may not pickup the enter keystroke from the buffer
  • Then a scanner that registers enter may pick it up and register it as a keystroke and as a result not pick up any useful input
  • To solve this you can add an extra nextLine() in order to retrieve and abandoned Enter key strokes following numeric or next() inputs
23
Q

dialog box

A

register user input i.e. entering something via keyboard or confirming something

24
Q

Input dialog box

A

asks question

provides text field for user response

25
Q

showinputdialog() method

A

-six overloaded versions
-returns a string representing the user response
One version requires:
Parent component
Message
Title
Type of dialog box

26
Q

Type-wrapper classes

A
  • Primitive data types have corresponding classes contained in java, lang package
  • These include methods to process primitive values e.g.
  • Integer.parseInt()
  • Double.ParseDouble()
27
Q

What five arguments are needed to confirm a dialog box

A
  • Parent component
  • Promp message
  • Title
  • Integer that indicated which option button to show
  • Integer that describes the kind of dialog box
28
Q

Standard Arithmetic operators

A

preform calulations with values in programs

29
Q

operand

A

a value used either side of an operator

30
Q

integer division

A

two integers are divided and the result is also an integer meaning any fractional part of the result is lost,

31
Q

What is operator precedence

A

rules for the order in which mathematical expressions are evaluated
Multiplication, division, remainder (modulus), additon or subtraciton

32
Q

What are the rules of Type conversion

A
  • Artithmetic variables or constants of same type return results of the same variable/constant type
  • Arithmetic operations with unlike operands will return a result of a unifying type which Java chooses, basically java converts the values to a common type in order for it to work
33
Q

Automatic Type conversion

A

the automatic conversion of nonconforming operands into a unifying operand type

34
Q

what is the order of establishing unifying types betweeen two variables from highest to lowest

A

Double
Float
Long
Int

35
Q

what is type casting

A

forcing a value of one data type to be usef as value of another data type

36
Q

how do you use a cast operator

A

place desired value in parentheses

using a cast operator is an example of an explicit conversoin

37
Q

when do you not need to use a cast operator

A

when assigning a value to a higher unifying type e.g. Float to Double