Kotlin • It isa modern, statically typed programming language used for android development. • It is made by JetBrains. • It is object oriented and functional language. • 100% Interoperable with Java(Java code can call Kotlin and vice versa). • It is Open Source. • It is concise, safe and powerful.
3.
History • February 15,2016: Kotlin 1.0 was released. • January 04, 2017: Spring introduced Kotlin support in Spring 5. • At Google I/O 2017, Google announced first-class support for Kotlin on Android. • On 7 May 2019, Google announced that Kotlin the preferred language for Android app developers. • June 2022: Kotlin 1.7 was released with the version of the new K2 compiler
4.
Core Kotlin • Insteadof println we use Log.d() or update a TextView • We Won’t use main() in Android
7.
Variables • Kotlin hasimmutable (val) and mutable (var) variables. • val → read-only (like final in Java) • var → can be reassigned • Android use • val button=findViewById<Button>R.id.btnClick • button.text=“Click Me”
9.
DataTypes • There arethe following different types of primitive data types in Kotlin: • Boolean • Byte • Char • Double • Float • Int • Long • Short
11.
Boolean • In Kotlin,Boolean can hold either true or false. To declare a boolean variable, the var or val keyword can be used, followed by the variable name, and the assigned boolean value: • val isTrue: Boolean = true • val isFalse: Boolean = false • A boolean can be used to determine the outcome of if...else statements:
12.
fun main(){ val condition:Boolean = true if (condition) { // Code that gets executed if the variable is true } else { // Code that gets executed if the variable is false } } Sometimes you specify the type manually: