Unit 4: Fundamental Data Types Flashcards

1
Q

Primitive Data Types

A

Variables of Primitive types store values.
Do not have methods.
Integers are whole numbers (+, -, 0).
Floating numbers are real numbers.

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

Why can’t we just use floating point numbers?

A

Integers require less memory space.
Floating numbers have problems with rounding.
Integers are processed faster.

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

Values of int, & double

A
int = 4 bytes
double = 8 bytes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

int is default integer type in Java

A

stores integer value in range -2,147,483,648 . . . 2,147,483,647.

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

double is default floating-point type in Java

A

stores double-precision.

floating point value in approx. range +- 10^308, with 15 significant decimal digits.

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

boolean

A

stores boolean value: true or false

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

Multiple variables of same type can be declared in one statement

A

EX:
double gpa, price, milesPerGallon;
Bug lady, cricket, ant;

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

Convenient to initialize several variables to same value in one statement

A

EX:
gpa = price = milesPerGallon = 0.0;
Stores to the left.
Read from RIGHT to LEFT.

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

Aliases

A

2 or more object variables refer to same object.

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

Operators

A
5 operators (arithmetic).
Combines 2 or more values or expressions.
\+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo or Remainder
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Integer Division

A

Integer division by integer is ALWAYS integer.

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

Remainder/Modulo

A

Amount leftover after integer division.

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

What happens if we try to change the value of our Constants?

A

COMPILE ERROR!!!

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

Can a double be assigned to an int?

A

No! The decimal portion and 4 of the 8 bytes would have to be discarded.
Java won’t “demote” on it’s own.

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

Can an int be assigned to a double?

A

Yes! To store a 4-byte integer in an 8-byte floating point number, Java just adds a decimal point.

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

Magic Number

A

A number that appears in your code without explanation.

Always use named (symbolic) constants instead of “magic number” in code.

17
Q

Constants

A

Variable that can only be assigned a value once.
Compile Error if attempted to change value after initialized.
Often called “final variable”.

18
Q

Scanner Class

A

package: java.util - imported required.
Supports reading data from keyboard (standard input) and files.
Reads tokens - groups of characters separated by white spaces - or lines.
Converts input to numeric data types automatically.

19
Q

nextLine()

A

Method reads until encounters (new line).

Returns string before and then throws away the new line character.

20
Q

scan.nextInt()

A

Reads an integer, returns as an int

21
Q

scan.nextDouble()

A

Reads in floating-point number, returns as a double

22
Q

scan.next()

A

Reads next token, returns a string