Professional Documents
Culture Documents
Basic Kotlin
Basic Kotlin
>Programs written in kotlin contain less number of lines making it more efficient
for app development and robustness make it more used language in app development.
Kotlin too is an object oriented language like java which uses classes.
fun main( ) {
fun is the keyword for the declaration of function followed by the name of the
function . The syntax is similar to java and other prog languages.
DATATYPES IN KOTLIN:
Similar to other languages... Float datatype have f or F at the end of number like
(5.0f or 5.0F)
val: Use when you expect the variable value will not change.
var: Use when you expect the variable value can change.
fun main() {
var cartTotal = 0
cartTotal = 20
println("Total: $cartTotal")
}
Double: This datatype is used more precisely than float. Used for storing decimal
values.
Syntax is val name= value or val name: datatype=value
Functions:
fun main() {
//code
}
fun hello() {
//code
}
**UNIT**
This is used for returning no value. It is similar to void in C and Java.