Types Flashcards
What is a type?
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.
Distinguish between value types and reference types.
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.
What is a primitive(or simple) type?
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 many bytes in an int?
4 bytes
How do you declare an unsigned int in Java?
How many bytes in a float, a double?
Float: 4 bytes
Double: 8 bytes
How do ints and doubles differ?
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.
What is a static type system?
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.
Can Java use dynamic types?
No
Is BigDecimal a value or reference type? How about LocalDate?
BigDecimal: Reference type
LocalDate: Temporal type
Which value type is safe for financial math?
BigDecimal