Monday, May 18, 2020

Kotlin basics

Kotlin tutorial :-

Extraordinary Features :-

Support Null Pointer Exception
Support Immutability


Basic Program :-

fun main (args : Array<String>) {
println("Hello World")
}

Comment :-

//This is inline comment

/* multiple line comment 1
    multiple line comment 2  */

Variable :-

var  -  mutable
val - Immutable

String Interpolation :-

class person { }

main()
var personobj = person()

//String Interpolation
println("name of person ${personobj.name}")
}

Datatypes:-

var age : Int = 10

//age  =  variable names
//Int = data type

1. Numbers – Byte, Short, Int, Long, Float, Double
2. Boolean – True, false
3. Characters
4. Arrays
5. Strings

//Depends upon the Size

String Interpolation :-    (More Example)

eg-1

val  a = 20
val b = 10

println("Sum ${a+b}")

eg-2

class rectangle {
rec.len : Int = 0
rec.bre : Int = 0 }

main()

var rec=rectangle()
rec.len = 5
rec.bre =9

println("lenght of rectangle is ${rec.len} and breadth of rectangle is ${rec.bre}
              and Area is ${rec.len * rec.bre})







   



No comments:

Post a Comment

Null Safety , Lazy Keyword and LateInit Keyword

Null Safety :- Safe call  ( ? )    use it if you don't mind getting null values Not Null Insertion ( !! )  use if you are sure that val...