How kotlin program is executed internally:
- Kotlin and Java are both JVM (Java Virtual Machine) languages, which means that their programs are executed on the Java Virtual Machine. This means that the process of executing a Kotlin program is similar to the process of executing a Java program.


- Here is a high-level overview of the process:
- The Kotlin code is compiled by kotlin compiler (present inside JDK ) into bytecode using the Kotlin compiler.
- The bytecode is loaded by the Java Virtual Machine.
- The Java Virtual Machine interprets and executes the bytecode.
Variables:
- Variables that can be reassigned use the
var keyword.
var x = 5 // `Int` type is inferred
x += 1
println(x::class) // prints the class whether it is a int, string, double etc
- Read-only local variables are defined using the keyword
val . They can be assigned a value only once.
val a: Int = 1 // immediate assignment
val b = 2 // `Int` type is inferred
val c: Int // Type required when no initializer is provided
c = 3 // deferred assignment
DataTypes:
- Kotlin doesn't have primitive type (I mean you cannot declare primitive directly). It uses classes like Int , Float as an object wrapper for primitives. When kotlin code is converted to jvm code, whenever possible, "primitive object" is converted to java primitive.
fun main() {
var name = "Donn"
var age = 32
println("Hello $name, your age is $age and your name is ${name.tength} characters long.")
// use {} to include method
Nullable Types:
var demo1 : String= "balu"
demo1 = null // error
// To make a variable accept null value add ?
var demo2 : String? = "Balu"
demo2 = null
Conditionals:
// no need of swicth statements
when (n) {
1 -> {
print("First")
// run your code
}
2 -> print("Second")
3, 4 -> print("Third or Forth") // check multiple conditions for same code
in 1..100 -> print("Number is in the range")
else -> {
print("Undefined")
}
}
Loops: