Setup of Kotlin Java Project in IntelliJ IDEA

Many IDEs are available for Kotlin project development, but IntelliJ IDEA is one of the most commonly used options for writing and running Kotlin code. Kotlin support is built into IntelliJ IDEA, and a Kotlin Java project is a good starting point when you want to write Kotlin programs that run on the JVM.

In this tutorial, we shall learn how to set up a Kotlin Java project in IntelliJ IDEA, create a Kotlin file, write a simple Hello, world! program, and run it from the IDE.

First of all, you need to have IntelliJ IDEA installed on your computer. If you do not have the setup, the Community Edition is available at  https://www.jetbrains.com/idea/. Download the IDE and follow the installation instructions for your operating system.

What you need before creating a Kotlin Java project in IntelliJ IDEA

  • IntelliJ IDEA Community Edition or Ultimate Edition installed on your computer.
  • JDK installed and selected in IntelliJ IDEA. Kotlin JVM projects need a Java Development Kit because the code runs on the Java Virtual Machine.
  • Basic project folder location where IntelliJ IDEA can create project files.
  • Kotlin support enabled in the IDE. In recent IntelliJ IDEA versions, Kotlin support is usually available by default.

Steps to setup Kotlin Java project in IntelliJ IDEA

1. Start IntelliJ IDEA and create a new Kotlin project

Once you are ready with IntelliJ IDEA Community Edition, start IntelliJ IDEA. A welcome window should appear with an option to create a new project.

IntelliJ IDEA start up window - - Setup of Kotlin Project in IntelliJ IDEA - Kotlin Tutorial - www.tutorialkart.com
IntelliJ IDEA start up window

Click the Create New Project button. IntelliJ IDEA opens the New Project window, where you can choose the project type, language, build system, and JDK.

2. Select Kotlin Java support for the JVM project

Click on the “Create New Project” button. It takes to a New Project window. By default, on the left pane, you may find Java, Java FX, Android etc. Select Java. In the “Additional Libraries and Frameworks” section, check “Kotlin(Java)”. Leave other options to their defaults. Click on Next.

New Kotlin(Java) Project - - Setup of Kotlin Java Project in IntelliJ IDEA - Kotlin Tutorial - www.tutorialkart.com
New Kotlin(Java) Project

In newer versions of IntelliJ IDEA, the New Project window may show Kotlin directly as a language option. In that case, choose Kotlin, select a JVM project type, choose a JDK, and continue. The screen labels may differ slightly between IntelliJ IDEA versions, but the goal is the same: create a Kotlin project that targets the JVM.

3. Enter Kotlin project name and project location

Give your project a name, “KotlinTutorial” and choose a location for the project to be created in, as per you choice.

Project Name and Location - Setup of Kotlin Java Project in IntelliJ IDEA - Kotlin Tutorial - www.tutorialkart.com
Project Name and Location

Click on Finish.

Kotlin Project Window - Setup of Kotlin Java Project in IntelliJ IDEA - Kotlin Tutorial - www.tutorialkart.com
Kotlin Project Window

Create a Kotlin file inside the IntelliJ IDEA src folder

4. Add a new Kotlin File/Class to the project

If Project window is not visible, hit Alt+1.
Expand the project. “src” project should be there in the Project.
Now, right click on “src” folder -> New -> Kotlin File/Class.

New Kotlin File - Setup of Kotlin Java Project in IntelliJ IDEA - Kotlin Tutorial - www.tutorialkart.com
New Kotlin File

Give a name, “hello_world” and click on “OK”

Kotlin File - Setup of Kotlin Java Project in IntelliJ IDEA - Kotlin Tutorial - www.tutorialkart.com
Kotlin File

A Kotlin source file normally uses the .kt extension. You can name the file hello_world for this example, but in regular projects it is better to use clear file names such as Main.kt or names that match the feature you are writing.

Write and run the first Kotlin program in IntelliJ IDEA

5. Add the Kotlin main function and run the file

Write the main method and hit Run-> Run.
The Kotlin compiles and runs the project. The message “Hello, world!” is printed to the output as shown in the below screenshot.

</>
Copy
fun main() {
    println("Hello, world!")
}

When this Kotlin program runs successfully, IntelliJ IDEA displays the output in the Run tool window.

Hello, world!
Kotlin Project Run - Setup of Kotlin Java Project in IntelliJ IDEA - Kotlin Tutorial - www.tutorialkart.com
Kotlin Project Run

Use Java and Kotlin in the same IntelliJ IDEA project

A Kotlin Java project in IntelliJ IDEA can contain both Kotlin and Java source files. This is useful when you are adding Kotlin to an existing Java project or when you want to learn Kotlin while still using Java classes. Kotlin can call Java code, and Java can also use Kotlin classes when the project is configured correctly.

For example, a simple Java class can be placed in the same source folder or module.

</>
Copy
public class MessageProvider {
    public static String message() {
        return "Hello from Java";
    }
}

The Kotlin file can call the Java method directly.

</>
Copy
fun main() {
    println(MessageProvider.message())
}
Hello from Java

This Java and Kotlin interoperability is one reason Kotlin is often introduced gradually into existing JVM projects instead of rewriting everything at once.

Configure Kotlin in an existing Java project in IntelliJ IDEA

If you already have a Java project in IntelliJ IDEA and want to add Kotlin, create a Kotlin file in the source folder. IntelliJ IDEA usually detects that Kotlin is not configured and shows a prompt to configure Kotlin in the project. Follow the prompt, choose the module, select the Kotlin runtime, and apply the changes.

  • Open the existing Java project in IntelliJ IDEA.
  • Right-click the source folder where you want to add Kotlin code.
  • Select New -> Kotlin File/Class.
  • If IntelliJ IDEA asks to configure Kotlin, accept the prompt and select the correct module.
  • After configuration, write a simple Kotlin main function and run it to confirm the setup.

Kotlin Java project setup issues in IntelliJ IDEA

IssueLikely reasonWhat to check
Kotlin file does not runNo main function or wrong run configurationCheck that the file contains fun main() and run the Kotlin file again.
JDK is not availableProject SDK is not configuredOpen Project Structure and select an installed JDK for the project.
Kotlin option is not visibleDifferent IntelliJ IDEA version or missing Kotlin supportCheck plugins/settings and make sure Kotlin support is enabled.
Java class is not detected in KotlinFile is outside the source root or modulePlace Java and Kotlin files in the proper source folder and confirm module settings.
Project imports but build failsBuild system or dependency configuration issueCheck Gradle, Maven, or IntelliJ project settings depending on the project type.

Convert Kotlin to Java in IntelliJ IDEA: what to know

IntelliJ IDEA can help you inspect Kotlin bytecode and decompile it to Java-like code, but this is mainly for understanding how Kotlin is represented on the JVM. It is not the same as producing clean, handwritten Java source code. If you need a Java version of Kotlin code, review the generated Java-like output carefully and rewrite it where needed for readability and maintainability.

FAQs on Kotlin Java project setup in IntelliJ IDEA

How to setup Kotlin project in IntelliJ IDEA?

Install IntelliJ IDEA, create a new project, choose Kotlin or Kotlin(Java) for a JVM project, select a JDK, enter the project name and location, create a Kotlin file, and run a simple main function.

Can I use Java and Kotlin in the same IntelliJ IDEA project?

Yes. Kotlin and Java can be used in the same JVM project. Kotlin code can call Java classes, and Java code can use Kotlin classes when the project and module are configured correctly.

How do I add Kotlin to an existing Java project in IntelliJ IDEA?

Open the Java project, create a Kotlin file in the source folder, and use IntelliJ IDEA’s configure Kotlin prompt if it appears. Then select the required module and Kotlin runtime settings.

Do I need a JDK for a Kotlin Java project?

Yes. A Kotlin Java project targets the JVM, so IntelliJ IDEA needs a configured JDK to compile and run the project.

How to change Kotlin to Java in IntelliJ IDEA?

You can inspect Kotlin bytecode and decompile it to Java-like code in IntelliJ IDEA, but the result should be treated as reference code. For production use, rewrite and test the Java version manually.

Editorial QA checklist for this Kotlin IntelliJ IDEA setup tutorial

  • Does the tutorial clearly explain that the Kotlin Java project runs on the JVM?
  • Are IntelliJ IDEA steps written so they still make sense when the UI labels vary by version?
  • Does the article show a runnable Kotlin fun main() example and its output?
  • Does the tutorial answer whether Java and Kotlin can be used in the same project?
  • Does the troubleshooting table cover JDK setup, Kotlin configuration, and source folder issues?

Conclusion

In this Kotlin Tutorial, we have learnt the setup of Kotlin Java Project in IntelliJ IDEA and started writing our first Kotlin program to print a “Hello, world!” message to the output. In our next tutorial, we shall look into Basic Kotlin Program.