Scalar Data Types
Scalar types are the built-in types that a language provides for representing single values. Kotlin supports a range of scalar types similar to other languages.
Take numbers, for example. Integers can be represented using the
Byte, Short, Int and Long types, whereas floating-point values are
represented by the Float and Double types.
There is generally a close correspondence to types in Java, which shouldn’t be a surprise given that we typically compile Kotlin code down to Java bytecode, for execution on a JVM. However, there are some differences too.
For example, Kotlin has a set of types for representing unsigned integers:
UByte, UShort, UInt, ULong. An unsigned integer shifts the range
of representable values so that only positive values are represented. Thus
a Byte can be a value in the range -128 to 127, whereas a UByte can
be in the range 0–255.
Some languages provide support for unsigned integer types while others do not. For example, C, C++ and Kotlin do, whereas Java and Python do not.
As regards text, Kotlin provides Char, to represent an individual
Unicode character, and String, to represent a sequence of
those characters. As in C, the single quote is the delimiter for literal
Char values, and the double quote is the delimiter for literal String
values. Like Python, Kotlin also supports triple-quoted strings, for easy
representation of multiline text.
We will encounter other built-in data types later in the module.