Best Resources to Learn Kotlin

Kotlin is one of the open-source programming languages with functional and object-oriented features. JetBrains developed Kotlin, and you can find it as a streamlined Java language. Nowadays, Android developers use Kotlin for their app development. Thus, to become one of the successful app developers, you can learn Kotlin from free or paid courses.

Cheat Sheet

Variables

var mutableInt: Int = 100
val immutableInt: Int = 50
val inferredInt = 49

val fifteen = 15 //Int
val threeBillion = 3000000000 // Long
val oneLong = 1L // Long
val oneByte: Byte = 1
val distance = 42.40 // double
val eFloat = 2.7182818284f // Float

val active = true

Null Safety

val name: String? = null
val length: Int = name?.length ?: 0
if (name != null && name.length > 0) {
    val length = name.length
} else {
    val length = 0
}

//safe cast
val nullableStudent: Student? = (input as? Student)

Collections

//list 
val ages = arrayOf(17, 25, 32) //Int array
val names = listOf('Gabriela', 'Solace', 'Imre', 'Rose') //immutable String list
val mutableList = mutableListOf(0, 1, 2) //mutable list

//iterate through list
for (age in ages) {
    print(age)
}

names.forEach {
    print(it)
}

//filter a list
ages.filter { it % 2 == 0 }
ages.any { it % 2 == 0 }
ages.none { it % 2 == 0 }
ages.all { it % 2 == 1 }
ages.first { it % 2 == 0 }
ages.firstOrNull { it % 2 == 0 }

//map
val days = mutableMapOf("Monday" to 0, "Sunday" to 7)

Control Flow

//if
if(a == b){
	print('a is equal to b')
} else if(a > b){
	print('a > b')
} else {
	print('a < b')
}

//for
for (i in 0..5) { } // 1 - 5
for (i in 0 until 5) // 1 - 4
(0..5).forEach { }
for (i in 0 until 3 step 2) // 0, 2


//while
while (i > 0) {
    i--
}

//do-while
do {
    i--
} while (i > 0)

//when
when(number) {
    0 -> println("0")
    1, 2 -> println("good")
    3 -> println("a bot higher")
    4 -> println("Exceeded")
    else -> println("error")
}

Extensions

fun Int.appendDollar(): String =  '$' + this
500.appendDollar() //$500

Class

class Website(val name: String, val publishedYear: Int)
val myWebsite = Website("TL Tplates", 2020)

Tutorials and Courses

  • The Joy of Kotlin – It is another paid option for those who are looking for a professional guide to learn Kotlin. You will find instructions on writing a safe, comprehensive, and easily maintainable program with the language, Kotlin. The course covers optional data, error management, and other topics.
  • Learn Kotlin with Keddit – We have chosen another free course that covers topics on Data Classes, Properties and Fields, Lambda, and Higher-order Functions. However, you must have some knowledge of Java to choose this course. The tutorial relies on the use of different libraries, including Retrofit 2.0, RecyclerView, Dagger 2, and Picasso.
  • Taking Advantage of Kotlin – It is a free Kotlin tutorial, helping you to avoid boilerplate code and Android development pitfalls. Moreover, you will know the way of using Kotlin converter, Android Studio’s Java, and Kotlin syntax. The tutorial also includes instructions on using library functions for better Java functions.
  • Android Kotlin Developer Course– Without any programming skills, you may join this paid online course. You can learn the Android app and game development. Moreover, the course guides you in designing the app with Shape, Color, Style, and Menu. You can deal with New Firebase from Web services and Google.
  • Kotlin Crash Course for Programmers – We have included it as one of the premium Kotlin courses for programmers. The course comprises 25 lessons and 20 quizzes. You will learn about data types, functions, loops, and variable declarations. The guides you on the way of writing Kotlin applications and scripts.

Blog Posts

In Kotlin, the String class represents character strings. Access characters of a String Index access operator can be used. val str = "abCdEf" str[2] //"C" Iterate through a String for...
Some common use cases with number. Add leading zeros to a number val result = String.format("%05d", 2) // "00002" val result2 = "15".padStart(5, '0') // "00015" Convert number to String...

Leave a Comment

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close