Chapter Table of Contents

Ch. 3 Data

Section Table of Contents

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/52185bce-e940-4f4b-aee7-6719fcef939c/Untitled.png

Primitive data types are the most basic types of data. They are stored by value, which means that when you declare a variable of a primitive type, the value of that variable is stored at that place.

Non-primitives (aka objects, which we will learn more about in Ch. 12), on the other hand, are more complex types of data that often build off of primitives. For example, a String is a non-primitive, which is made up of multiple characters (char), which is a primitive. Unlike primitives, non-primitives are stored by reference, which means that when you declare a non-primitive variable, it points to another location in memory which stores the value of the variable.

<aside> 💡 All primitives are lowercase.

</aside>

Here is a diagram that might help you visualize how primitives and non-primitives are stored differently:

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/0a37575e-da96-4736-ab5e-374d4160fab9/Untitled.png

The variable age is a primitive with the value 5, which is stored by value. The variable name is a non-primitive, which is stored by reference, where the variable points to a location in memory where the value is stored.

For now, you won’t need to worry too much about the difference between store by value and by reference (just keep it in mind). The important part is that you recognize that there are 2 types of data: primitives and non-primitives.

Below are a few commonly used primitive types.

Boolean

Booleans can store only 2 values: true or false. This is because when you wind it all down, a computer is built from binary code (1s and 0s, on or off, true or false). These variables, along with logical operators (see Ch. 5), are what are going to allow you to make decisions in your programs.