Chapter 2. Kenya Types

Tristan Allwood

Table of Contents

Kenya Primitive Types
Kenya Class Types
Kenya Built In Types Example
Kenya Array Types

Kenya Primitive Types

Table 2.1. Kenya Primitive Types

NameDescriptionRange of valuesDefault value
booleanRepresents an elementary truth value.One of the literals true or falseThe literal false
charRepresents a single character literal. This is stored as a 16bit number.Numerically: 0 to 65535 (but see notes below)Numerical 0 or as a literal ( see below ) '\0'
intRepresents an integer (whole) number. This is stored as a 32bit 2's complement number.-2147483648 to 21474836470
doubleRepresents a floating point number to "double precision". This is stored as a 64bit number.4.9E-324 to 1.7976931348623157E3080

Since the primitive types are built into Kenya, there is special syntax for declaring their 'values' in your programs.

A boolean has only one of two values, true or false, and so you can write true or false directly in your source code.

A character is technically a number, but usually you use it to store a single character, like A, B etc. To facilitate this, you can include a single character ( in the ASCII range ) directly in your source code by surrounding it in ' marks. You may also wish to include some special characters (like a newline or tab), and this is done using special escape sequences, these are explained in the table below:

Table 2.2. Kenya Character Escape Sequences

Escape SequenceDescription
'\0'The character with the numeric value of 0
'\b'Represents backspace
'\t'Represents a tab character
'\n'Represents a linefeed character (newline)
'\f'Represents a formfeed character
'\r'Represents a carriage return character
'\"'Represents a double quote symbol (")
'\''Represents a single quote symbol (')
'\\'Represents a backslash symbol (\)

Because char's, int's and double's all represent numbers, it is possible in certain circumstances to use one to represent another. Without any extra syntax, you can use a char anywhere where you would need an int or double, or an int anywhere where you would need a double. This is called a widening conversion and happens automatically. To go the other way, use the round, ceil, floor, and toChar functions that are built into Kenya.