How to Create and Save a Kotlin File in Android Studio

In the first post, we talked about what Kotlin is and why we use it for Android development. Now, let’s take the next step: creating and saving Kotlin files in Android Studio.

If you’re just starting out, don’t worry — this guide is beginner-friendly!

🗂 What Is a .kt File?

Kotlin files use the .kt extension, which stands for Kotlin.
For example:

MainActivity.kt  

MyUtils.kt  

LoginScreen.kt

This file contains Kotlin code — classes, functions, variables — that define what your app does.

📁 How to Create a Kotlin File in Android Studio

Here are the steps to create a Kotlin file (or class) inside your Android project:

✅ Method 1: Create a Kotlin Class/File

  1. Open Android Studio and make sure your project is loaded.

  2. In the Project pane, right-click on the folder where you want to add the file — usually: 

  3. Select: New > Kotlin Class/File

  4. Enter the name of your file (e.g., MainActivity)

  5. Choose the type:

    • Class – for creating a class

    • File – for writing functions outside of classes

    • Interface, Enum, etc. – depending on what you need
  6. Click OK, and Android Studio will create a file like: MainActivity.kt

Pro Tip: Where Should You Save Kotlin Files?

In Android Studio projects, Kotlin files are usually saved under:

app > src > main > java > com.yourapp.name

Even though Kotlin is a different language from Java, Kotlin files go into the same folder structure because they’re both compiled into Java bytecode and run on the same virtual machine (JVM).



Σχόλια