Kotlin & Java are 100% Compatible

 

Android Studio 3.0.0 has the support for Kotlin Programming Language. This platform is fully compatible to Kotlin & Java together.

Key Notes

  1. Java can call to Kotlin function or visa versa is also true.
  2. If you don’t how to write Kotlin code then it’s still very easy to convert Java code to Kotlin code by just copying java functions to Kotlin file. One confirmation pop-up will be appeared, once you accept then java code will be converted to Kotlin easily.

    kotlin
    Do you want to convert Java Code to Kotlin?
  3. There is no “extends” keyword.
  4. There is no semi colons (;) to terminate the statements.
  5. Functions will be starting with “fun” keyword.Let’s share my thoughts through an code example below:

HelloActivity.kt

 

Some points:

  1. Copied getName() and processPrime() methods from java and pasted to Kotlin file.
  2. Kotlin and Java both have same two methods, only signature is different. Now you can compare it easily.

 

HelloJava.java

 

Output

 

If you have some doubt then I recommend you to have a look on above video for more better understanding. You can put your question also in the comment section below.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.