Kotlin Tutorial

Kotlin Variable

In Kotlin variable can be declared using var and val provided below.

var a = 10
val b = 12

The difference between val and var is var is mutable where as val is immutable. The value of val can not be changed in future but the value of var can be changed later.

Kotlin Data Type

Like other programming language the below data types ara availeble in Kotlin also

  • Number
  • Character
  • String
  • Array
  • Boolean

The below Kotlin built in functions are used to convert from one date type to another

  • toChar()
  • toByte()
  • toShort()
  • toInt()
  • toLong()
  • toFloat()
  • toDouble()

Kotlin Operator

In Kotlin the below operators are mostly used

  • Arithmetic
  • Relational
  • Assignment
  • Unary
  • Bitwise
  • Logical

Kotlin Input Output

The println() function is used for output and readLine() function is used for taking input. To make better understand please see the below code

fun main() {
    println("Enter your Name") // For Output
    val name = readLine()      // For Input
    println("Enter your roll")
    var roll: Int =Integer.valueOf(readLine())
    println("Your name is $name")
    println("Your roll number is $roll")
    /* Hopefully you are enjoying the code. 
      Happy code!!*/

Note that ‘//’ is used for single line comment and /* */ is used for multiline comment

Kotlin condition

Kotlin Function

Kotlin Object Class (OOP)

1 thought on “Kotlin Tutorial

Leave a Reply

Your email address will not be published.