---
title: "How do you convert Java code to Kotlin?"
description: "Android Studio and IntelliJ convert Java to Kotlin automatically. Use Convert Java File to Kotlin File or paste Java into Kotlin, then review nullability."
url: "https://bugsee.com/answers/kotlin/java-to-kotlin/"
---

# How do you convert Java code to Kotlin?

In Android Studio or IntelliJ, open the Java file and choose Code > Convert Java File to Kotlin File, or paste Java code into a Kotlin file and accept the conversion prompt.

```java
// Java
public class Greeter {
    private final String name;
    public Greeter(String name) { this.name = name; }
    public String greet() { return "Hello, " + name; }
}
```

```kotlin
// Kotlin after conversion, tidied up
class Greeter(private val name: String) {
    fun greet() = "Hello, $name"
}
```

- Review nullability: the converter marks types as nullable when it cannot prove otherwise. Java annotations such as `@NonNull` and `@Nullable` improve the result.
- Convert one file at a time and compile after each, so problems are easy to place.
- Afterwards, replace getters and setters with properties, loops with collection functions, and null checks with `?.` and `?:`.
- Keep the converted file in version control history by committing the rename separately.

## Related questions

- [How do you convert Kotlin code to Java?](https://bugsee.com/answers/kotlin/convert-kotlin-to-java/)
- [How do you copy a map in Kotlin?](https://bugsee.com/answers/kotlin/kotlin-copy-map/)
