Skip to main content

Featured

What is Coroutine in Android?

Coroutines are available for the Kotlin language. Coroutines are simply cooperative functions.   Our Android applications often have multiple concurrent and interdependent functionalities. We provide instructions to the system through code, also known as a program, to perform a set of sequential instructions.  During the execution of these instructions, a specific instruction may take longer than expected, causing the next line of code to wait until the previous line of code has completed its execution. This scenario is known as blocking program execution. To avoid blocking program execution, the code must be executed on a separate thread. A thread is a single sequential flow of control. However, creating and handling multiple threads can be difficult and expensive in terms of OS operations and memory usage. To address this issue, we can use Coroutines in Kotlin. Coroutines are cooperative functions that are executed on threads as needed in a cooperative manner. They help manage long-r

Datatypes and Variables in Kotlin

Hello all,
In this post we will come to know different datatypes and how to declare variables in Kotlin.

We can declare variables in two ways :

1. Using var
2. Using val


var language = "English"
val score = 9

What is Difference Between var and val ?
  • var refers to mutable reference which means the value of variable declared can be changed later.
  • val refers to immutable reference which means the value of variable declared can not be changed later.
Different Data Types :

In Kotlin it is not mandatory to specify datatype of variable while declaring as you have seen in above example ,Kotlin will do Implicitly do it for you. 
However you can specify datatype of variable if you wish like this :


var language : String = "English"
var score : Double = 9.8
var flag : Boolean = true

Kotlin supports all the datatypes which are supported in other language like String,Int,Boolean
,Double and more.


var language : String = "English"
var score : Double = 9.8
var flag : Boolean = true



Comments

Popular Posts