Typical hello world program with kotlin
fun main(){
// Print Hello Kotlin
println("Hello Kotlin")
// it's time to say, "GOOD BYE SEMICOLON(;)"
/* TOPIC: Variable */
// prototype:
// (var|val) variableName : <datatype> [=value]
// variable declared with *val* keyword can not be reassign.
val varibaleWithValDeclaration: String = "Hello Val, You can't reassign other value to this variable again"
// uncommenting below line cause ERROR!!! because the variable declared with *val* keyword
// varibaleWithValDeclaration = "Val reassignment error"
// variable declared with *var* keyword can be reassign.
var varibaleWithVarDeclaration: String = "Hello Var, You can reassign this variable as many times as you want"
varibaleWithVarDeclaration = "var variable reassigned"
println(varibaleWithVarDeclaration)
/* TOPIC: Variable END */
/* TOPIC: Nullable */
// By default all datatype are not nullable in kotlin.
// Bellow line will show error.
// var nullableString: String = null
// to make it nullable add ? sign after datatype
var nullableString: String? = null
/* TOPIC: Nullable END */
/* TOPIC: if..else */
val age = 14
if(age >= 18){
println("You can vote in elections!!")
}else{
println("You will be allowed to vote when you will 18 !!")
}
/* TOPIC: if..else END */
}