Monday, 24 February 2020

Kotlin Introduction


Why did Google replace Java with Kotlin, and why only Kotlin but not other languages?


I'm going to give you a different answer. I believe it isn't the beauty of Kotlin that inspired Google to replace Java and only Java. There are many things to consider.

  1. Google has to get rid of Java, sooner or later. Since the time Oracle took control of Java and observed Google’s use of JAVA API in Android, it has been bombarding Google. The last lawsuit was about the commercial use of Java API: Oracle goes for appeal against Google. and Oracle Won: Happy as Larry: Why Oracle won the Google Java Android case. Java has become the Achilles heel for Google. Until the replacement, it’s going to be a very painful experience and spending millions of dollars on lawyers to hold on to something that may be lost anytime, NOT AN OPTION!!!
  2. Java has an ecosystem that is almost unmatched. Android programmers have been using Java and millions and millions of lines have already been developed. They can accept a new language but not accept losing the ecosystem. Augmenting that is the fact that the huge Android SDK is in Java, porting is more expensive than using a bridge so the language choices are limited to the ones that are either binary compatible with JAVA or can utilize the existing JAVA code in some way. Go, Dart languages which were made in Google’s kitchen are out!
  3. Scala, Closure run on the same JVM as Java and they can use existing JAVA code to some extent. However, JAVA is a procedural language while these other JVM languages support a different paradigm of programming, Functional. No matter how much die-hard fans tout about it, Functional programming is not the mainstream, adopting it is even more difficult with a very steep learning curve. Scala and Closure are out! and so is Groovy with it’s outlandish syntax and DSL style programming.
  4. A new language perhaps? Designing a new language is something Google didn’t find success with. Go and Dart got a poor reception from the programming community. In addition to that, designing new languages, its ecosystem, its supporting tool is a big endeavor, takes a lot of effort and time (Android Studio still needs many versions to be fully stable).
So Google has to find a permanent solution to this oracle Java problem. Once that let's them keep using Java and its ecosystem without any liabilities or worries. Enter the scene, Kotlin!!!, a shy, rugged clothed, and struggling procedural language that runs on JVM trying to make its presence known, for a few years, but nobody was listening.

Kotlin:

  • Kotlin is an Android-compatible language that is concise, expressive, and designed to be type- and null-safe. It works with the Java language seamlessly.
  • In Kotlin 1.1, we officially released the JavaScript target, allowing you to compile Kotlin code to JS and to run it in your browser. In Kotlin 1.2, we’re adding the possibility to reuse code between the JVM and JavaScript. Now you can write the business logic of your application once, and reuse it across all tiers of your application – the backend, the browser frontend, and the Android mobile app.
  • Kotlin helps concise the syntax and the user can concentrate on writing logics instead of syntax.

Advantages and Disadvantages

The following are some of the advantages of using Kotlin for your application development.

Easy Language − Kotlin is a functional language and very easy to learn. The syntax is pretty much similar to Java, hence it is very easy to remember. Kotlin is more expressive, which makes your code more readable and understandable.

Concise − Kotlin is based on JVM and it is a functional language. Thus, it reduces lots of boilerplate code used in other programming languages.

Runtime and Performance − Better performance and small runtime.

Interoperability − Kotlin is mature enough to build an interoperable application in a less complex manner.

Brand New − Kotlin is a brand new language that gives developers a fresh start. It is not a replacement of Java, though it is developed over JVM. It is accepted as the first official language of android development. Kotlin can be defined as - Kotlin = JAVA + extra updated new features.

The following are some of the disadvantages of Kotlin.

Namespace declaration − Kotlin allows developers to declare the functions at the top level. However, whenever the same function is declared in many places of your application, then it is hard to understand which function is being called.

No Static Declaration − Kotlin does not have usual static handling modifiers like Java, which can cause some problems to the conventional Java developer.

Happy Learning!!


Reference:
I was figuring out on the google and found the above content from various websites.

Visibility Modifier In Kotlin

Visibility Modifier The visibility modifier basically defines a scope from where it can be visible and accessible. There are four visi...