Kotlin: A RoadMap

·

5 min read

Kotlin: A RoadMap

Kotlin is a programming language which was introduced by JetBrains ten years ago with the idea to make programming easy for the programmer and also fun. It has a rich syntax form along with the many libraries that are easy to use and beginner friendly. Another perk of using it, is that you can easily transfer your Java knowledge to it and you are given allowed to use the Java libraries in your projects easily.

In this article, I will be going over a roadmap you can follow to help you learn Kotlin but will only introduce you to the important thing that you need to know to help you in your learning journey; either for Android Development, web development or just because you want to learn to it for the fun of it.

RoadMap

1. Kotlin Basics
2. Functions
3. Arrays
4. Conditional Statements & Loops
5. Classes & Objects
6. Lambda

Kotlin Basics

The basics include you learning about the reserved words such as var, val, class. It also involves you learning about the different data types that Kotlin offers you; these include: Int, String, Byte, Short, Float, Double, IntRange and how you can use them.

An example of how you can use the IntRange data type is when you want to declare a range of values, giving a starting point and an ending point. This makes it easy for you to perform a certain task with the values generated.

In the basics, you need to also to make sure you understand how the Kotlin complier works as well as the DO’s and DON’Ts that are allowed as well as the best practices developed for the Kotlin developers. This will make your learning experience that much smoother and easier.

Functions

Just like in any programming language, you will find functions in Kotlin as well and you need to understand how they work, how to call them, parameters and arguments. They are used to organise your code and help in code reuse. If you already have a background in another programming language, you can easily grasp the fundamentals.

Let’s take this quick example that shows a function called getUserNames. The main purpose of this function is simply to get the first, and last name of the user and that’s it. It doesn’t return anything.

Alt text

When you fully understand how to use functions in Kotlin, you are well on your way to implementing some of OOD principles in your projects.

Arrays

Arrays are something you will encounter on your journey to learning Kotlin. Though they may seem a little challenging at first, they are actually quite easy and fun when you get used to them. They are mutable meaning that you change their contents but you cannot however change their size after declaration.

Something to remember is that when declaring arrays, you use the arrayOf before defining the array’s content. However, there are many ways in which you can define an array but I’ll only give an example of how to use the arrayOf.

Alt text

Conditional Statements & Loops

Conditional statements help you when making decisions. If not A then B, this is where the famous if/else statements are found. However, instead of you having the infamous switch statement, Kotlin offers you something called a when statement. This works like a switch statement does where you have a test case in the when’s parenthesis followed by the cases or conditions you are testing for in the body of the when statement. It is important to note that the when statement can also go with an else to handle all the cases that are not catered for by the test cases.

Alt text

Loops on the other hand help you in avoiding repetition by writing the same line of code over and over again. There are three types of loops which are the while, do while and for loops. Each of these have a similar syntax a in other programming languages except for the for loop which has a different syntax.

Alt text

Both of these declarations have a similar but yet different meaning. The for loop is one of the loops that you will mostly use for your coding so make sure you fully understand it and know how to use it in the correct way.

Classes & Objects

A class is a collection of related objects that defines data members and methods. It is basically a blueprint for something in the real world while an object is what brings that blueprint to life. Or in a more technical term, an object is an instance of a class and that has data members and methods that operate on it. One class can have multiple objects that perform different tasks but have the same variables and methods defined on them.

You will also learn about initialisation blocks, what they are and how you can use them as well as getters and setters (accessors and mutators).

Knowing all about how to manipulate and work with classes and objects is very important as now you begin to move to the more object-oriented part of Kotlin and leave the functional/structural part of it.

Alt text

Lambda

A lambda or lambda expression is a block of code that can be passed the same way as an object. It helps you write more flexible and powerful code. You will hear a lot about lambda as you go deeper and deeper into learning Kotlin.

Conclusion

Learning a new technology or programming language for the first time if always daunting and most times you will find so many resources but not know where to start. Learn the fundamentals first and make sure you fully understand them before you can move to the more complex aspects of it. Whether you want to learn Kotlin for Android development, web development, or just for the fun of it, you can apply this roadmap to your learning.

Connect with me on Twitter