Variables, data types and the assignment operator Flashcards

1
Q

Variable

A

Location in the computer’s memory that is used to store data in a program
Must be declared with an identifier and type

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

Identifier consists of

A
Letters
digits
underscores
dollar signs
It also cannot start with a digit
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Difference between double and single quotes

A

Double - String

Single - Char

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

Number literal

A

Constant number that appears directly on code

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

Local-variable inference

A

Programmer can use var instead of declaring the type of variable

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

When can var be used

A

Local variable declarations with initializers
For loops
Try statements

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

When can var not be used

A

Global variables
Method signature
Any case where the compiler cannot infer type

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

How to fix a logic error in which the computer will not let the user input a second value

A

Extra in.nextLine(); to accommodate “Enter” key in queue

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

Named constants

A

A constant must be declared and intialized in the same statement.

e.g. final double PI = 3.14159;
final int SIZE =3;

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

When is the remainder negative

A

Remainder is only negative when dividend is negative

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

Augmented assignment operators

A

Operators that can be combined with the assignment operator.

e.g. +=; -=; *=; /=

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

++var

A

preincrement: Increment var by 1, and use the new var value in statement

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

var++

A

postincrement: Increment var by 1 but use the original var value in the statement.

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

–var

A

predecrement: Decrement var by 1, and use the new var value in the statement.

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

var–

A

postdecrement: Decrement value by 1 and use the original var value in the statement.

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

What three things we cannot have as an identifier

A

Reserved words
Starting with a digit
Named true, false, null

17
Q

Primitive type

A

Primitive: A primitive data type specifies the size and type of variable values, and it has additional methods.

18
Q

R

A