Posts Things to know for your interview of Kotlin
Post
Cancel

Things to know for your interview of Kotlin

What are the things that are asked at Interview?

Basically, In interview you are asked how much knowledge do you have in the field. And Do you know the things that are essential of that field.

So what are the essential things?

Skills Required • Experience in Kotlin/ Java (extensions, data classes, sealed classes, objects and basics of coroutines, Lambda & higher order functions) • Strong knowledge of MVC, MVVM, Architecture component and memory management • Strong knowledge of ROOM models and define relationships, access dates using DAO’s • Experience with offline storage, threading, and performance tuning • Experience with Android Studio, Android Components and UI Component, Animation & Design Guidelines • High-caliber proficiency in Android SDK and experience with third-party SDKs and APIs • Strong coding and analytical skills  Skills Preferred • Understanding of Android Coding Architecture & Patterns • Strong knowledge of Problem breakdown into multiple functions • Strong knowledge of SQLLite and able to perform CRUD operations, JOINs and proficient in RDBMS. • Experience with Testing & Debugging (unit testing, UI testing and automation) • Experience with RESTful web services and parsing JSON/XML • Fluency with XCode, JIRA, GIT and other common software development tools • Strong software engineering skills, can design and implement software projects from the ground up. • Understanding of the full mobile development life cycle • Good understanding of OOPS concepts, and Design patternss

First I would like to say, Kotlin is an awsome language.

Its been a while I have had heard Go programming language is also good which compiler is awsome and it is like C programming language.

Ok lets start learning Kotlin.

Extension Function

First of all Extension function. To be frank this is the first time I heard and just finished this documentation studying. And I am suprised that extension function are awsome too.

Ok lets see example first.

1
2
3
fun List<String>.getLongestString() {
      // code to check which is Longest string
}

So this .getLongestString() is the Extension function. Which adds new property to List. Lets see how to use.

1
2
3
4
fun main() {
    val list = listOf("red", "green", "blue")
    list.getLongestString()
}

Such an amazing feature of Kotlin.

Data class

Data class are just like the normal class but with some extra features are also added on build of the file. Getter and Setter, toString(), equals(), hashCode() and following features:

  • equals()/hashCode() pair;
  • toString() of the form “User(name=John, age=42)”;
  • componentN() functions corresponding to the properties in their order of declaration;
  • copy() function (see below).

copy() is what I liked after reading documentation. Lets see example:

1
2
3
4
5
6
data class User(val name: String = "", val age: Int = 0)
// copy is generated by compiler
fun copy(name: String = this.name, age: Int = this.age) = User(name, age)
val jane = User("Jane", 35) 
val (name, age) = jane
println("$name, $age years of age") // prints "Jane, 35 years of age"

Isn’t it awsome, Cloning a object. Wow

Sealed Class

So Sealed class is the a abstarct class but which can only be inherited by classes created inside it. Also documentation says they are just like enum classes. Lets see the example:

1
2
3
4
sealed class Expr {
      data class Const(val number: Double) : Expr()
      data class Sum(val e1: Expr, val e2: Expr) : Expr()
}

Companion Object

Companion object is the object that are accessed using Class. We don’t need to create instance of the class. There are like @staticmethod in Python. Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Car(val horsepowers: Int) {
    companion object Factory {
        val cars = mutableListOf<Car>()

        fun makeCar(horsepowers: Int): Car {
            val car = Car(horsepowers)
            cars.add(car)
            return car
        }
    }
}

val car = Car.makeCar(150)
println(Car.Factory.cars.size)

See easy pizy japanizy. You can learn more in this documentaiton

Coroutines

Coroutines are one of the best advantage of Kotlin and I love using in Android App development. I like the way the can switch Thread Context.

So Coroutines are the Threads which work Asynchronusly.

1
2
3
4
5
6
7
8
9
10
println("Start")

// Start a coroutine
GlobalScope.launch {
    delay(1000)
    println("Hello")
}

Thread.sleep(2000) // wait for 2 seconds
println("Stop")

I will describe about this later. So stay tuned.

Lambdas in Kotlin

Official Documentation

Lambda function in kotlin for List are many and some are .filter, .sortBy. NOTE: lambda function don’t have () but instead it has { } for the implementation.

Lets see the skeleton:

1
val lambdaName : Type = { argumentList -> codeBody }

Example:

1
2
val square = { number: Int -> number * number }
val nine = square(3)

…………………………….

Third party SDK

Third party SDK’s provides you a set of functionality in just one package.

Facebook, Google Play Games Services, HeyZap etc are the third party SDK’s.

Jira, GitHub

Jira is used for issue tracking and project management.

Github is an version control system.

This post is licensed under CC BY 4.0 by the author.