Android
Wordpress

In this post i have write some use full information about Kotlin and the reason why you should learn Kotlin ?

https://www.programmingschool.io

Kotlin is a programming language that can be used for developing Android Apps, server side code and instead of JavaScript in web clients. It claims to be 100% interoperable with Java or Android. Android Studio 3.0 added support for Kotlin and made it a first-class supported language for Android.

I recently started exploring Kotlin for Android App development. In this blog, we discuss whether it is a good idea to learn Kotlin.

Why it is good

It is interoperable with Java. You can use both Java and Kotlin together to develop an Android app. You can easily call Java methods from Kotlin and Kotlin methods from the Java code.

How it is better than Java

Null Safety

This is one of the best features if like all Android developers, you are tired of your Android App throwing Null Pointer Exceptions.

If you have used Swift for developing iOS apps, you will be familiar with the syntax –

Lambda expressions

A lambda expression is a “function literal”, i.e. a function that is not declared, but passed immediately as an expression.

Extension functions and properties

With this, you can easily extend a class with new functionality without having to inherit from the class. The functions or properties are accessed statically.

No checked exceptions

For checked exceptions, you always have to add a try-catch block. In Java, some exceptions are checked, while some are unchecked. In it, all exceptions are unchecked — the compiler will never prompt you to add a try catch block. This reduces the lines of code and increases code readability. You can go through the many discussions and debates on the internet on this point to understand more about the pros and cons of checked exceptions.

Data Classes and Class properties

Data classes are special classes whose main function is to hold data. The compiler automatically generates useful functions such as equals(), toString(), copy() which we often need — once we write the primary constructor.

Properties in this can be mutable(var) or read-only(val). These can be directly accessed in it. The getter setter methods are generated behind the scenes to ensure smooth interoperability with Java.

Difficulties adopting Kotlin

It is still a relatively new language and has a smaller community than Java for Android. This means there aren’t many libraries in Kotlin — although since it is interoperable with Java, you can use the existing libraries without much difficulty.

There are also far lesser tutorials and active communities that will help you while developing in Kotlin.

Kotlin, Gradle and Android Studio will take some time to work well together. There are still a few issues seen and Android Studio 3.0 is the first stable version to accept Kotlin. (This will not be the case for long. IntelliJ Idea which is the base for Android Studio is designed by the same company that designed Kotlin — JetBrains)

You will still have to use Swift for iOS. And you will still need to know Java for Android development — for maintaining/improving existing Android Apps and interfacing with libraries. Kotlin will just be another language you need to learn.

Who should learn and adopt

If you are just getting started with Android, its better to stick to Java. There are a lot more tutorials in Java that will help you get started quicker.

If you are an experienced programmer — feel free to delve into Kotlin. You will very likely pick it up quickly and then you can decide for yourself if you like it enough to stick with it.

Conclusion

It is easier to learn if you are already familiar with Java and Swift. It is easy to get started — you can start of by writing just a part of the code in Kotlin — since it is completely interoperable with Java. The support and active community for it continues to grow and it is even expected to overtake Java for development of Android Apps. Give it a try!

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here