How to convert Java File to Kotlin File

There are two ways to convert your java file to kotlin file.

  1. Use IntelliJ IDEA
    Main menu -> Code -> Convert Java File to Kotlin File
  2. You can use the online
    https://try.kotlinlang.org/ -> Convert from Java

Note : You may work with Java language along side Kotlin.

Use IntelliJ IDEA – Convert Java File to Kotlin File

Following are the steps to convert your Java File to kotlin File :

  1. Open your Project in IntelliJ IDEA, and open the Java file.
    Open Java File in IntelliJ IDEA - Kotlin Tutorial - www.tutorialkart.com

    Open Java File in IntelliJ IDEA

  2. In the main menu bar, click on “Code”. Click on the item “Convert Java File to Kotlin File”
    Main Menu -> Code -> Convert Java File to Kotlin File - Kotlin Tutorial - www.tutorialkart.com

    Main Menu -> Code -> Convert Java File to Kotlin File

  3. If you get a message “Some code in the rest of your project may require corrections after performing this conversion. Do you still want to find such code and correct it too?”, you may click OK.
    Some code in the rest of your project may require corrections after performing this conversion. Do you still want to find such code and correct it too - Click OK - Kotlin Tutorial - www.tutorialkart.com

    Information Message

  4. Finally, your java file is converted to kotlin file. Try running it.
    Java File is converted to Kotlin File - Kotlin Tutorial - www.tutorialkart.com

    Java File is converted to Kotlin File

Try Online “Convert from Java”

  1. Hit the url “https://try.kotlinlang.org/” and click on “Convert from Java”, shown in the below picture
    hit the url https://try.kotlinlang.org/ - Kotlin Tutorial

    Hit the url

  2. Paste you Java Code and click on “Convert to Kotlin”
    Convert to Kotlin Window - Kotlin Tutorial - www.tutorialkart.com

    Convert to Kotlin Window

Also learn to convert Java File in Android application to Kotlin File ?