Home Android Tutorial Creating Basic Data Types in Kotlin

Creating Basic Data Types in Kotlin


Data type (basic type) refers to type and size of data associated with variables and functions. Data type is used for declaration of memory location of variable which determines the features of data. In Kotlin, everything is an object, which means we can call member function and properties on any variable. Kotlin built in data type are categorized as following different categories:

Number Character Boolean Array String

Kotlin represents character using char. Character should be declared in a single quote like ‘c’. Please enter the following code in our coding ground and see how Kotlin interprets the character variable. Character variable cannot be declared like number variables. Kotlin variable can be declared in two ways – one using “var” and another using “val”.

An integer literal has the type Int if its value fits in an Int, or Long otherwise. Long literals should be suffixed by L for clarity, which will also let you make a Long with a “small” value. There are no literal suffixes for Short or Byte, so such values need an explicit type declaration or the use of an explicit conversion function.

Kotlin is 100% interoperable with Java. In other words, it can be used together with Java in the same project. So you can refactor parts of your Java code to Kotlin and it won’t break. In addition to that, it is concise, expressive, and has great tooling. Kotlin can be used on the back-end (server-side), but it’s getting a lot of attention right now as a language for Android app development. Kotlin is now supported by Google as a first-class language for Android development, so the popularity of Kotlin is set to explode!

In this first tutorial in the Kotlin From Scratch series, you’ll learn about the language basics: comments, variables, simple types, arrays, and type inference.