Skip to content

Latest commit

 

History

History
103 lines (65 loc) · 3.27 KB

README.md

File metadata and controls

103 lines (65 loc) · 3.27 KB

Basic Info

Name: Kotlin

Creator(s): JetBrains

Date: July 22, 2011

Website: kotlinlang.org

Intro

Kotlin is a cross-platform, statically typed, general-purpose programming language with type inference. Kotlin is designed to interoperate fully with Java, and the JVM version of Kotlin's standard library depends on the Java Class Library, but type inference allows its syntax to be more concise. Kotlin mainly targets the JVM, but also compiles to JavaScript (e.g. for frontend web applications using React) or native code (e.g. for native iOS apps sharing business logic with Android apps). Language development costs are borne by JetBrains, while the Kotlin Foundation protects the Kotlin trademark.

Syntax

To declare a variable in Koltin you can use the keyword var or val followed by the name of the variable, an = sign and the value.

var name = "Jacob"
val number = 42

If/Else statements in Koltin are very much the same as other languages with brackets around the condition and curly braces around the body.

if (true) {
    print("True!")
} else if (false) {
    print("False!")
} else {
    print("WTF?!")
}

Koltin provides a variety of loop types, a simple for loop is shown below. The basic syntax is the same as if/else statements with brackets around the condition and curly braces around the body.

var fruits = arrayOf("Orange", "Apple", "Mango", "Banana")

for (fruit in fruits) {
    println(fruit)
}

Koltin functions are declared with the keyword fun and look very similar to other languages. Brackets are required around the arguments list and curly braces around the body. You can also specify argument types and the return type.

fun sum(a:Int, b:Int):Int {

    var sum = a + b
    println(sum)
    return sum

}

sum(12, 34)

Classes in Koltin are declared with the keyword class. Constructor variables can be declared at class header level and initialization code can be placed inside a special block prefixed with the init keyword.

class Person (val _name:String, val _age:Int) {

    var name:String
    var age:Int

    init {

        this.name = _name
        this.age = _age

        println("Name = $name")
        println("Age = $age")

    }

}

val zara = Person("Zara", 17)
val nuha = Person("Nuha", 11)

Libraries

  • Awesome Kotlin ~ A curated list of awesome Kotlin frameworks, libraries, documents and other resources.

More Info