Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Data Types & Variables

The most fundamental aspect of any programming language is how it represents data.

Kotlin provides a range of built-in data types similar to those you’ve seen already in C and Python, but with some important differences.

Variables in Kotlin are defined differently from how they are in C and Python. Unlike C, we often don’t need to specify the type of a variable, thanks to type inference.

Another important point is that Kotlin recognizes the different roles of variables in a program. It allows us to distinguish between those that are updated during program execution and those that are not.

After completing this section, you will be able to recognize the range of scalar (single-valued) data types that Kotlin provides. You will also be able to create variables of these different types.

Note

We will not be covering all of Kotlin’s fundamental data types in this section. For example, we’ll say relatively little here about strings.

In general, during this part of the module we expect you to do your own additional research into Kotlin’s features to achieve a complete understanding of how to use the language effectively.