Hey Mi Fans,
I'm sure many of you guys want to develop Android Apps and Games. Ever since Google announced Kotlin as the official language for Android development at Google I/O in 2017, programmers who want to become Android developers are in a dilemma. The big question in front of them is whether they should learn Kotlin or Java. But, the answer to this question is not any simpler. Why is it? Because Kotlin is now the Official language for Android Development but Java is dominating the Industry from past many years. So, Let's dig into it further!
Kotlin was introduced in 2011 by JetBrains (maker of IntelliJ IDEA, PyCharm, and many other top IDEs) who at the time were using almost entirely Java. They created Kotlin because, "First and foremost, it’s about our own productivity". So, Kotlin was created explicitly to be better than Java, but JetBrains wasn’t about to rewrite their IDEs from scratch in a new language. Which is why they made Kotlin 100% interoperable with Java. Kotlin runs on the JVM and compiles down to Java bytecode; you can start tinkering with Kotlin in an existing Java or Android project and everything will work just fine.
Java_vs_Kotlin_for_Android_Development.png (28.83 KB, Downloads: 1)
2018-04-20 15:04:22 Upload
Above is an example of Kotlin and Java code. As Kotlin looks more concise and clear
Creating a Card Class:
Let's say we need a class to represent the state of a playing card. It would need 3 properties-
Here's what it looks like in Kotlin:
33 lines down to 1! Not bad, right? But it gets better.
In Java, if you want to test for equality between objects you need to override the 'equals' method:
And if you want to see something useful when you print the object, you need to override the 'toString' method:
But in Kotlin, all you have to do is add the word ‘data’ in front of your class:
We’ve now got 48 lines of Java, and still just 1 line of Kotlin!
Impressive? Yeah, it is!!!
If you are a complete beginner who wants to learn Android development, then my answer is Java. When I say beginners should start with Java, you may be thinking, "What the heck? Kotlin is much more productive, less boilerplate code, and now the official language of Android development, and this guy is suggesting learning Java. I am not gonna fall for it..."
If you’re completely new to programming, start with Java first. Most of the Android code is still written in Java, and at the least, understanding Java will be a boon for understanding the docs. Once you’ve got the basics of Java, you'll be able to pick up Kotlin that much faster and will have a greater appreciation for the benefits that Kotlin brings. On the other hand, if you’re an experienced developer then should definitely learn Kotlin because it really improves productivity and it has so many advantages over Java.
Do you like this thread? Please let me know in the comments!
In order to fulfill the basic functions of our service, the user hereby agrees to allow Xiaomi to collect, process and use personal information which shall include but not be limited to written threads, pictures, comments, replies in the Mi Community, and relevant data types listed in Xiaomi's Private Policy. By selecting "Agree", you agree to Xiaomi's Private Policy and Content Policy .