In our last tutorial about “Getting started with Kotlin…” we have learned about setting the environment to work with Kotlin in Android Studio. In this Tutorial, we are going to know how to convert java application or java class to Kotlin. We can convert from java to kotlin very easily whether it is a single class or complete application. We can convert it very easily in android studio by just on some click.
Step 1. Create your project
Project Creation process will be same for both whether you are using Java or Kotlin as explained in our earlier pos
File > New > New Project and select the default Main Activity as per your requirement. By default, all activity will be created in java
Step 2. Convert your project from Java to Kotlin
For converting the Java app into Kotlin application click on the main app folder the click on code menu and then click on convert java file to Kotlin option.
You will see a configure option at right top corner of android studio window as given in below screen shots. We have to click on configure option and follow the rest of the steps as given below.
Then select all Module and press ok. It will take some time and start converting the application. Here, as you can see in below screen shots we can select the all module of single files for conversion.
Now your Java Application is converted into Kotlin. The important thing is that we don't need to any thing with our layout XML files and it can be used as it are getting used with Java
If have and query or question then please fill free to add your comment below.
If you have any suggestion or any topic which you think need to included then also leave your comment below we will try to make it available at earliest.