Types Flashcards

1
Q

What is a type?

A

Data types are restrictions on the values allowed for a variable. Some variables can only reference numbers, others reference text, and others reference custom data types defined by a developer.

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

Distinguish between value types and reference types.

A

Primitive data types have values that fit inside a computing word. (We can think of a word as a single “slot” of computer memory.) Variables with primitive data types point directly to a value. CPUs have built-in instructions for primitive type operations.

Reference data types have values that are too big to store in a single word. Their values span multiple words.

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

What is a primitive(or simple) type?

A

Primitive data types have values that fit inside a computing word. (We can think of a word as a single “slot” of computer memory.) Variables with primitive data types point directly to a value.

In Java, a primitive type is a data type whose data fits in one or two computer words. Primitive types are fast. That’s why Java differentiates between primitive types and reference types. CPUs have built-in instructions for primitive type operations.

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

How many bytes in an int?

A

4 bytes

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

How do you declare an unsigned int in Java?

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

How many bytes in a float, a double?

A

Float: 4 bytes

Double: 8 bytes

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

How do ints and doubles differ?

A

An integer represents a whole number, no decimals, that can be positive or negative.

A double is a number with a decimal point. May start with 0.

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

What is a static type system?

A

Statically typed languages perform type checking at compile time. If a script written in a statically-typed language (such as Java) contains errors, it will fail to compile until the errors have been fixed.

Statically-typed languages require you to declare the data types of your variables before you use them.

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

Can Java use dynamic types?

A

No

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

Is BigDecimal a value or reference type? How about LocalDate?

A

BigDecimal: Reference type

LocalDate: Temporal type

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

Which value type is safe for financial math?

A

BigDecimal

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