Kotlin
Kotlin
Jetbrains developed softwares like android studio, intellij idea, pycharm etc.
kotlin is a type of modern replacement of java.
in 2011 jetbrain announced the development of kotin and made it open source.
1.0 was the first kotlin live in 2016.
in 2017 google announced that the kotlin was used as for android development.
in 2019 kotlin used as primary language for android.
kotlin was a jvm. for that we install jdk(java development kit)
features of kotlin
statically typed language(means agar koi int type ki variable hai toh int type ka
hi value lega aur ahar int type ka nhi ahi toh phele hi btadega runtime par nhi
jisse errors kam honge)\
object oriented and functional language.
open source
concise(lines of codekam hoga aur hum easily code ko easily samjh sakte hai), safe
and powerful.
instead of java we use kotlin.
var - var is reassigned term (agar hum datatype ke sath var ka use karenge to agar
humne suppose there is a variable a = 12 if we want to change the value of a = 10
then we use var i.e "var a = 12" after in we want to change the value of a then
simply we change the value of a to any other value "var a = 13")
val - val is not reassigned value(in this we we did not change the value of any
variable and if we want to make the variable constant then we use "val a=13")
print - if we use print then we did not shift to the other line
println - if we use println then automatically if we pass next statement it shift
to the next line.
TYPES OF OPERATORS
1. Arithmetic operator
ex-
fun main() {
var i = 13
var j = 2
println(i+j) //15
println(i-j) //11
println(i*j) //26
println(i/j) //6 (it give 6 instead of 6.5 because the variables i and j are
int type variable but if we want to get the output as 6.5 then we use
"println()i.tofloat()/j")21
println(i%j) //1
}
2. relational operator
fun main() {
var i = 13
var j = 2
3. increment/decrement
fun main() {
var a = 10
a++
println(a) // 11
a--
println(a) // 9
}
post increment
println(a++) //10
println(a) //11
pre increment
println(++a) //11
FUN MAIN() {
var i = 10
println(i++ + ++i) //10+12=22
}
4. logical operator
basically there are 3 types of logical operator
a.AND (&&)
b.OR(||)
C.NOT(!)