![]() |
VOOZH | about |
The most fundamental data type in Kotlin is the Primitive data type and all others are reference types like array and string. Java needs to use wrappers (java.lang.Integer) for primitive data types to behave like objects but Kotlin already has all data types as objects.
There are different 4 data types in Kotlin:
These data types contain integer values.
Data Type | Bits | Min Value | Max Value |
|---|---|---|---|
| byte | 8 bits | -128 | 127 |
| short | 16 bits | -32768 | 32767 |
| int | 32 bits | -2147483648 | 2147483647 |
| long | 64 bits | -9223372036854775808 | 9223372036854775807 |
Let's write a program to represent all the integer data types and their min and max values.
Output:
My integer 35
My long integer 23
Smallest byte value: -128
Largest byte value: 127
Smallest short value: -32768
Largest short value: 32767
Smallest integer value: -2147483648
Largest integer value: 2147483647
Smallest long integer value: -9223372036854775808
Largest long integer value: 9223372036854775807
These data types are used to store decimal values or fractional parts.
Data Type | Bits | Min Value | Max Value |
|---|---|---|---|
| float | 32 bits | 1.40129846432481707e-45 | 3.40282346638528860e+38 |
| double | 64 bits | 4.94065645841246544e-324 | 1.79769313486231570e+308 |
Let's write a program to represent both the floating-point data type and its min and max value.
Output:
My float value 54.0
Smallest Float value: 1.4E-45
Largest Float value: 3.4028235E38
Smallest Double value: 4.9E-324
Largest Double value: 1.7976931348623157E308
Boolean data type represents only one bit of information, either True or False. The Boolean type in Kotlin is the same as in Java. These operations, disjunction (||) or conjunction (&&), can be performed on boolean types.
Data Type | Bits | Data Range |
|---|---|---|
| boolean | 1 bit | true or false |
Let's write a program to represent the Boolean data types.
Output:
Yes,true is a boolean value
Character data type represents the small letters(a-z), Capital letters(A-Z), digits(0-9), and other symbols.
Data Type | Bits | Min Value | Max Value |
|---|---|---|---|
| char | 16 bits | '\u0000' (0) | '\uFFFF' (65535) |
Let's write a program to represent character data type.
Output:
C is a character : true
String Data type represents sequence of characters. For example : "GFG".
Output:
I love geeksforgeeks
Array is a collection of elements of same type or its sub-type, which stores in a contiguous memory locations.
Output:
I
Love
GFG
To know more about Array refer this article: Kotlin Array