Primitive types
As explained in the previous chapter, primitive types can only store their value. Typically they use from 1 to 8 bytes of memory each.
Boolean
The boolean type represents logical values and can only be true or false. Booleans are commonly used in conditional statements and logical operations.
The code above can be read as:
"Declare a variable called isActive of type bool with value true, and declare a variable called hasPermission of type bool with value false"Byte
The byte type stores small integer values ranging from -128 to 127. It uses 1 byte of memory and is useful for efficient storage when working with small numbers.
The code above can be read as:
"Declare a variable called A of type byte with value 65, and declare a variable called B of type byte with value 90"Since zen treats bytes as characters their output will be the letters A and Z respectively, in the next chapters you will learn how to convert them to integers and print their numeric value.
Short
The short type stores medium-sized integer values ranging from -32,768 to 32,767. It uses 2 bytes of memory and provides a balance between range and memory efficiency.
The code above can be read as:
"Declare a variable called year of type short with value 2025, and declare a variable called elevation of type short with value 1500"Integer
The int type stores standard integer values ranging from approximately -2 billion to 2 billion. It uses 4 bytes of memory and is the most commonly used type for whole numbers.
The code above can be read as:
"Declare a variable called population of type int with value 1,500,000, and declare a variable called distance of type int with value -250"Long
The long type stores large integer values ranging from approximately -9 quintillion to 9 quintillion. It uses 8 bytes of memory and is ideal for very large whole numbers.
The code above can be read as:
"Declare a variable called nationalDebt of type long with value 35 trillion, and declare a variable called timestamp of type long with value 1699804800000"Float
The float type stores decimal numbers with single precision. It uses 4 bytes of memory and provides approximately 7 decimal digits of precision.
The code above can be read as:
"Declare a variable called price of type float with value 19.99, and declare a variable called temperature of type float with value 36.6"Double
The double type stores decimal numbers with double precision. It uses 8 bytes of memory and provides approximately 15 decimal digits of precision, making it suitable for scientific calculations.
The code above can be read as:
"Declare a variable called pi of type double with value 3.14159265359, and declare a variable called scientificConstant of type double with value 6.022×10²³"Type comparison
Here's a summary of all primitive types in Zen:
| Type | Size | Range | Use Case |
|---|---|---|---|
bool |
1 byte | true/false | Logical values |
byte |
1 byte | -128 to 127 | Small integers |
short |
2 bytes | -32,768 to 32,767 | Medium integers |
int |
4 bytes | ≈-2 billion to 2 billion | Standard integers |
long |
8 bytes | ≈-9 quintillion to 9 quintillion | Large integers |
float |
4 bytes | ≈7 decimal digits | Decimal numbers |
double |
8 bytes | ≈15 decimal digits | Precise decimals & money |
Activities
Choose the Right Type
Pick the best type for each variable:
Fix the Errors
Each line has a type/value mismatch. Fix them:
Add the Suffixes
Add the correct suffix (b, s, l, f, d) where needed:
Big Numbers
Write these using scientific notation:
Hint: 1e6 = 1,000,000
Memory Quiz
- Which uses more memory:
intorshort? - How many bytes does
doubleuse? - Which is bigger:
floatordouble? - What's the smallest integer type?