Category: 06. Kotlin
-
Functions
Kotlin is a statically typed language, hence, functions play a great role in it. We are pretty familiar with function, as we are using function throughout our examples in our last chapters. A function is a block of code which is written to perform a particular task. Functions are supported by all the modern programming languages and…
-
Ranges
Kotlin range is defined by its two endpoint values which are both included in the range. Kotlin ranges are created with rangeTo() function, or simply using downTo or (. .) operators. The main operation on ranges is contains, which is usually used in the form of in and !in operators. Example Both the ends of the range are always included in the range which means that the 1..4…
-
Arrays
Arrays are used to store multiple items of the same data-type in a single variable, such as an integer or string under a single variable name. For example, if we need to store names of 1000 employees, then instead of creating 1000 different string variables, we can simply define an array of string whose capacity…
-
Strings
The Kotlin String data type is used to store a sequence of characters. String values must be surrounded by double quotes (” “) or triple quote (“”” “””). We have two kinds of string available in Kotlin – one is called Escaped String and another is called Raw String. Example When you run the above Kotlin program, it will generate…
-
Booleans
Many times we come across a situation where we need to take decision in Yes or No, or may be we can say True or False. To handle such situation Kotlin has a Boolean data type, which can take the values either true or false. Kotlin also has a nullable counterpart Boolean? that can have the null value. Create Boolean Variables A boolean variable can be created using Boolean keyword and this…
-
Operators
An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. Kotlin is rich in built-in operators and provide the following types of operators: Now let’s look into these Kotlin Operators one by one. (a) Kotlin Arithmetic Operators Kotlin arithmetic operators are used to perform basic mathematical operations such as…
-
Data Types
Kotlin data type is a classification of data which tells the compiler how the programmer intends to use the data. For example, Kotlin data could be numeric, string, boolean etc. Kotlin treats everything as an object which means that we can call member functions and properties on any variable. Kotlin is a statically typed language,…
-
Variables
Variables are an important part of any programming. They are the names you give to computer memory locations which are used to store values in a computer program and later you use those names to retrieve the stored values and use them in your program. Kotlin variables are created using either var or val keywords and then an equal…
-
Keywords
Kotlin keywords are predefined, reserved words used in Kotlin programming that have special meanings to the compiler. These words cannot be used as an identifier (variables names, package names, function names etc.) and if used then compiler will raise an exception. Kotlin uses fun keyword to define a function, so if we we will try to use…
-
Comments
A comment is a programmer-readable explanation or annotation in the Kotlin source code. They are added with the purpose of making the source code easier for humans to understand, and are ignored by Kotlin compiler. Just like most modern languages, Kotlin supports single-line (or end-of-line) and multi-line (block) comments. Kotlin comments are very much similar…