A Complete Guide of Kotlin for Android Development Enthusiasts

Posted by on

If you ever dreamed of making your own Android application, then now is the right time to address the matter. Early this year in Google’s I/O ’17, Kotlin was announced as an official programming language on Android. If you watched the event, you might have noticed the developer’s great enthusiasm for the announcement.

Guide of Kotlin for Android Development

Here’s a complete guide to exploring the daunting process of Android development. We’ll go through the features that Kotlin offer, as well as how you can learn the language from scratch.

Guide of Kotlin for Android Development Enthusiasts

Overview

If you’re a bit familiar with Android development, you’d know that Java is the most widely used language for the task. There, you might ask yourself, why to learn Kotlin instead of Java.

To answer the question and to start learning, you need to fully understand the strengths and weaknesses of the language.

First of all, Kotlin is fully compatible with Java. You can use the Java frameworks and libraries (code written by other people, so you don’t have to write from scratch) in your Kotlin project. Not only that, but you can also convert the Java code into Kotlin by pasting the code into a Kotlin file.

Consider the image below for a code in Java on the left and the converted code on the right.

https://lh4.googleusercontent.com/4ggBtlQ4_TfgWW3_ocit23jOlkHfcCRKArF4TAL7JmGLXZLV9zgAURPRvtRjiLAGUytbrv3i4syzzU7xaOtZHfaOYNiMR47s4NbVjSvu5LSBvP7cbXIsmfE1gS3hkCsixpEnQoSe

Image source

You might also notice that for instance, Java and Kotlin look very much alike. However, Kotlin does hold advantages over its peer, which makes Android developers so excited about it.

a. Kotlin syntax is clearer than Java’s, which makes debugging much easier. Your project codes would look, at the very least, quite neat.

b. Kotlin is better than Java when dealing with Null values. Null values are usually assigned when you can’t seem to find a proper value. Java throws them all around, which makes it hard to identify crashing reasons, for example.

Kotlin is a statically typed Language, which means that the variables’ types are determined at compilation time. The program is not going to run unless it knows the types either by you telling it, or inferring the type. Kotlin is also a mixture of Object Oriented Programming and functional programming.

Now let’s set the technical analysis aside and get into the learning process.

First Steps

If you’re not familiar with the concepts I mentioned earlier, you can find the best online Kotlin courses and tutorials recommend by Kotlin programming community here: https://hackr.io/tutorials/learn-kotlin

I’d recommend Harvard’s CS50 course, on edx.org. Link: https://www.edx.org/course/apr-computer-science-principles-harvardx-cs50-ap

It’s highly recommended to understand these concepts before you jump on making your first application. It’s not just for better coding, but for a better development cycle as a whole.

Concepts like Data Structures, Algorithms, Databases are crucial to any software development process.

Understanding Syntax

The first thing they teach us in a computer science class is that computers are really dumb. Don’t get tricked by their massive computational power. If you don’t tell them what to do in clear instructions, things might go south real quick. That’s why you have to pay great attention to the syntax and what you’re writing. Syntax is pretty much straightforward, and you can learn it from the references and documentation provided by JetBrains on https://kotlinlang.org/docs/reference/

Here’s our beloved fellow, “Hello World” written in Kotlin.

https://lh3.googleusercontent.com/-uy_Co2dJBcPuaJwvtWfH8G_sjfxeGUd-OV4LDnIJAxlzhlIhw1iACLr3F4nDFJT1wURXoQCOStobyPU-qEc_S8bybWfVapQXWZ9UWm4Xmw8gftYfpN364Um9P3gnhZPMQZGE3qE

You need to start writing code by yourself at this point. Staring at references and tutorials will not pay until you get your hand dirty in the IDE.

Kotlin is a language that was developed for working programmers, and not academic purposes. Kotlin code is quite human-friendly, and it targets your needs as an Android developer.

Expanding your toolbox

After laying down the basics, it’s time to move on. You can’t really build a good Android application with just the syntax. In order to expand your toolkit, you need to understand object-oriented programming. OOP is a widely used concept in many programming languages. It aims to model the software world as a set of objects interacting with each other and having a defined set of responsibilities. This way you’d avoid having floating lines of code and anonymous bugs originating out of nowhere.

You can find Lynda’s course on OOP here: https://www.lynda.com/Java-tutorials/Foundations-Programming-Object-Oriented-Design/96949-2.html

There are also many resources on Mindorks to cover a few concepts you might not have heard about along the way. This will make your Android code stronger and more efficient. Link: https://blog.mindorks.com/a-complete-guide-to-learn-kotlin-for-android-development-b1e5d23cc2d8

I saved functional programming for last because it might be the hardest skill to grasp. Functional programming brings a lot to the table. That along with OOP could create a powerful Android application. We won’t go over the debate of “Functional Programming Vs Object-Oriented Programming” since it might be out of our scope and Kotlin already combines the two paradigms.

I found this course on functional programming rather interesting, as it addresses functional programming for Kotlin. It allows you to see how functional programming would work for Kotlin and compares with Java as the course progresses. Link: https://blog.mindorks.com/a-complete-guide-to-learn-kotlin-for-android-development-b1e5d23cc2d8.

Your First Android Application

Now that you know the theory, you need to understand the application. This is the step where you start to understand what is an Android application and how you can make and test one. There’s an analogy between Android development and Web development in many areas.

First, you need to start working on an emulator and test your code after you finish writing it. The Android studio gives you the power to do that. Also, you need to learn how to divide your program into activities, like a website is divided into pages.

Finally, you’ll want to put that knowledge into action and create multiple activities for your application, design the layout, import images, etc.

For this final stop, you can check https://www.lynda.com/Kotlin-tutorials/Welcome/645031/658157-4.html?autoplay=true for a quick setup.

Final Thoughts

A programmer’s life isn’t all about acquiring new skills and expanding their toolbox. It’s also a mixture of writing real-life code and blowing a fuse while debugging it. If you allow yourself to fall into the loophole of “not-feeling-ready-yet”, you will never get your application done.

Useful Resources:

The best learning practice out there is writing code. Kotlin is quite a fun and intriguing language that would make the task easier and allow developers to focus more on their GUI and design creation. But at the end of the day, we’re talking about a programming language, so the code isn’t going to write itself. The Android development train is heading towards Kotlin in the future, and now is a perfect time to catch it.

Share This Post

Last updated: November 29, 2017

Authored by :

Saurabh has worked globally for telecom and finance giants in various capacities. After working for a decade in Infosys and Sapient, he started his first startup, Lenro, to solve a hyperlocal book-sharing problem. He is interested in the product, marketing, and analytics. His latest venture Hackr.io recommends the best Android tutorial and online programming courses for every programming language. All the tutorials are submitted and voted by the programming community.

Leave a Reply