The primitive data type is the basic building block of data. They hold one single value. They represent a string, number, or boolean.
Your key takeaways are:
- The basic building blocks of data are the primitives
- hold a single value
- representation for string, number, and boolean
- Each language has these building blocks
All data types are built off of the primitive types, so we’ll start with these.
Different Data Representations
What patterns do you see in the following table? Why are patterns important?
Patterns tell you a story. Patterns give you clues. Start watching for patterns.
How can patterns help you?
- writing code
- building solutions for your customers
|boolean||literal truth-value state||true, false|
|char||a single character||‘A’, ‘z’, ‘&’, ‘!’, ‘_’, ‘1’|
|string||a grouping of characters||“Hello World”, “123”|
|byte||signed 8-bit two’s complement integer||84, -17|
|short||signed 16-bit two’s complement integer||872, -304|
|integer||signed 32-bit two’s complement integer||-69,723|
|long||signed 64-bit two’s complement integer||8,030,167,904,852|
|float||signed 32-bit floating-point value||-1826.001|
|double||signed 64-bit floating-point value||5.17 x10300|
Patterns for the Data Types
- Numbers, strings, and booleans – these are your primitives
- Hold a single piece of information – one piece of data
- Memory size is dependent upon the data type
- Knowing the difference between data types will help you craft the right solution. For example, if the system you’re building only needs a float, but you use a double, you’re allocating more memory than needed.
- Primitive Data Type
Simple Primitive Data Types
Notice the similarities between the different languages?
Your functions are bloated. Put them on a diet. Think "skinny" and "as few lines as possible."
Total Lab Runtime: 00:48:33