DevTools Logo

Java to Kotlin Converter

Java to Kotlin Converter

Translate a subset of Java — classes, methods, variables, loops, println — into idiomatic Kotlin.

Java

client-side
simple subset
no network

Supported: System.out.println, variable declarations (with var/val), methods, classes, main, C-style and enhanced for loops, and new. Constructors, lambdas, generics, and static members need a manual pass — always review.

Examples

Method with a return type

Input
public int square(int n) {
    return n * n;
}
Output
fun square(n: Int): Int {
    return n * n
}

Modifiers are dropped, the return type moves after the colon, and `int` becomes `Int`. The trailing semicolon is removed.

About this tool

The Java to Kotlin Converter rewrites simple Java into idiomatic Kotlin. Both languages are brace-based, so the structure carries over and only statement-level changes are needed: System.out.println becomes println, `int`/`boolean`/`String` declarations become `var` or `val`, Java methods become `fun` with Kotlin parameter and return types, and `new Foo()` becomes `Foo()`.

C-style and enhanced for loops map to Kotlin ranges and for-in, and `final` declarations become `val`. The converter runs entirely in your browser — nothing is uploaded. It targets a deliberate subset; constructors, generics, lambdas, and static members are flagged for a manual review.

How to use

  1. Paste a Java snippet

    Load the sample or paste your own class, method, or small program.

  2. Read the Kotlin output

    The right-hand pane updates live; warnings flag anything outside the supported subset.

  3. Copy and review

    Copy the Kotlin and review the flagged constructs (static members, generics) before shipping.

Use cases

Porting a Java utility

Bootstrap a Kotlin version of a small Java class without rewriting every line by hand.

Learning Kotlin

See how a familiar Java snippet reads in Kotlin by converting one construct at a time.

Common mistakes

Mistake:Trusting the output for complex generics.

Fix:Generic type arguments and method references are not handled — review and fix those by hand.

Mistake:Forgetting static members need a companion object.

Fix:Kotlin has no static; the converter warns and you move the member into a companion object.

Frequently asked questions

References & standards