Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

KOTLIN:

>This is a language used for building of android apps.

>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.

> Apps that use kotlin are less likely to crash.

Kotlin too is an object oriented language like java which uses classes.

Basic example of kotlin code:

fun main( ) {

println("1st kotlin program")

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.

//In kotlin, there is no need to mention the semi-colon.

DATATYPES IN KOTLIN:

String , Int , Double , Float , Boolean.

Similar to other languages... Float datatype have f or F at the end of number like
(5.0f or 5.0F)

An expression is a small unit of code that has a value. It can be made of


variables, function calls

For declaring any variable,


val name : datatype = value
val is the keyword used for declaration.
name is the variable name

Eg: fun main() {


val a: Int =10
println(a)
}
Now to print variables in string, we use '$' symbol.This is called template
expression. And the string is called "template string".
fun main() {
val a: Int =10
println("Value of a is $a")
}
Output: Value of a is 10

Updating the variable:


In order to update any variable,we use the keyword "var".

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

String: This datatype is used for storing text.

To include quotations, we insert \" text "\ to print the statements.

Functions:

fun main() {
//code
}
fun hello() {
//code
}

**UNIT**
This is used for returning no value. It is similar to void in C and Java.

**INT** : This is used for returning integer value.


**STRING** : This is used for returning string value.

You might also like