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 .
Agree

Tech

[Discussion] Java vs. Kotlin : Which One Should YOU Learn? (Beginners)

2018-04-20 15:46:14
1136 25

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:
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.


Why Kotlin?
  • Kotlin is more concise than Java. While, writing Java code we have to write lots of boiler-plate (boilerplate is a part of a code that has to be included, means it is necessary to write that code. e.g. public static void main(String [] args){} ) code which consumes space and time. Kotlin does not require boilerplate code which makes it a clear, expressive, powerful and concise programming language. Below is an example of the Program:


Above is an example of Kotlin and Java code. As Kotlin looks more concise and clear

  • Now, many of you must be thinking that python is also an alternative if we do not want to write boilerplate code. We like using Java because it runs on JVM (Java Virtual Machine) which produces the bytecode. But, my point is that JVM makes the language platform independent. Similarly, Kotlin also runs on JVM and is platform independent.
  • Kotlin would be having more safety features than Java in the future hence, Kotlin is a better programming language.
  • Kotlin is inter-operable with the existing Android programming languages and runtimes which means you can call into the Java language from Kotlin and Kotlin language from Java.


  • Android Studio is built upon the IntelliJ IDEA and it is built by Jet Brains and the same company built the programming language Kotlin so it is easy for the developers to make features and tools.
  • Kotlin Provides Precise and Reliable Codes.

Creating a Card Class:
Let's say we need a class to represent the state of a playing card. It would need 3 properties-
  • The value of the card
  • The suit of the card
  • Whether or not the card is face up.
Also, since we usually deal cards face down the 'faceUp' property will typically be false, so we shouldn’t need to specify it every time. Here’s what that looks like in Java. We need three fields as well as associated getters/setters, along with two constructors:


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!!!

JAVA:
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..."

Why Java?
  • The first and foremost thing is that Android development is not everything. As a programmer, you may be starting your career with Android development, but if you start with a well-established language like Java, you become a part of the bigger Java community and market, which directly means more job opportunities.
  • The second and more important thing is that there is a huge community of Java programmers, which means you can find answers when you are stuck. This is very important because, as a beginner, you will face a lot of technical problems and you might not know where to head when you are stuck. When you search Google with a Java problem, you are bound to get answers; the same cannot be said for Kotlin.
  • There are also more tutorials, books, and courses out there, both free and paid, which can teach you Android development with Java.
  • Once you know Java, your journey to Kotlin will also be easy and smooth because Kotlin is 100% interoperable with Java. It compiles into Java bytecode and runs on JVM.
  • Any third party open source libraries you use will almost all be written in Java. If you pull them down from GitHub, you're pulling Java source, if you step into them in the debugger, you’ll be stepping into Java code.
  • The JVM layer of the Android OS will still be written in Java, so if you step into that, you’ll be stepping through Java
  • Any existing projects you are called on to maintain will be written in Java. You aren't going to convert them all over to Kotlin because it won’t be a worthwhile investment of time if they’re working just fine in Java, and even if you do port them, you need to understand the Java code you’re porting!


Summary:-
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.

Sources:1 2 3 4

Do you like this thread? Please let me know in the comments!
2018-04-20 15:46:14
Favorites11 RateRate

MIUI Beta Tester

Asha@63. | from MIX

#1

Useful Information
2018-04-20 17:03:06

Master Bunny

Papu Bag | from Redmi Note 4

#2

thanks for the information
2018-04-20 20:42:06

Master Bunny

Godugu Srinivas Mudiraj | from Redmi Note 5 Pro

#3

good information
2018-04-20 21:16:23

Banned

sb2100 | from Mi A1

#4

very useful
2018-04-20 21:34:33

Grandmaster Bunny

naresh0218 | from Redmi 3S

#5

nice........
2018-04-20 22:52:06

It's my pleasure if u found it useful.
2018-04-21 01:23:41
Papu Bag replied at 2018-04-21 06:12:06
thanks for the information

My Pleasure, Have a nice day !
2018-04-21 01:26:06

Thank you :)
2018-04-21 01:26:56

Thank you buddy !!!
2018-04-21 01:28:50

Banned

sb2100 | from Mi A1

#10

Mohammad Enayat
Thank you buddy !!!

welcome bro
2018-04-21 01:30:06
please sign in to reply.
Sign In Sign Up

Mohammad Enayat

Master Bunny

  • Followers

    64

  • Threads

    55

  • Replies

    817

  • Points

    8194

3 Days Check-In
7 Days Check-In
21 Days Check-In
40 Days Check-In
Nov-100 replies in a month
Dec-100 replies in a month
100 ответов в декабре
Android O Tester
Christmas 2017
ThrowBackWithMiCommunity
MIUI Instagram
Mi Community Updater
Color Your Planet
Color Our Planet Game
The Motivator
MIUI 10
Golden Mi Bunny
Go Bunny Medal
MIUI Subscriber
Mi A2
MIUI 8th Anniversary
Go Bunny Master
Eid Mubarak
5 Million Registered Users
Throwback With Mi 2018

Read moreGet new
Copyright©2010-2020 Xiaomi.com, All Rights Reserved
Content Policy
Quick Reply To Top Return to the list