Are you ready to jump into the world of modern Android development? Kotlin, a concise, safe, and interoperable language, has become the preferred choice for many developers. This technology is not just a fad; it’s a powerful tool. But where do you even begin? Get ready to build your first Kotlin application.
Key Takeaways
- Download and install the latest version of IntelliJ IDEA Community Edition from JetBrains.
- Create a new Kotlin project in IntelliJ IDEA, selecting the “JVM | IDEA” template for a basic console application.
- Write and run a simple “Hello, World!” program in Kotlin to verify your environment is set up correctly.
- Familiarize yourself with Kotlin syntax, including variable declaration (val/var), data types (Int, String, Boolean), and control flow statements (if/else, for, while).
1. Install the Kotlin Development Environment
Your first step is setting up your development environment. I recommend IntelliJ IDEA Community Edition. It’s free, powerful, and has excellent Kotlin support. Download the latest version for your operating system. Once downloaded, run the installer. Accept the default settings, but make sure to check the box that adds IntelliJ IDEA to your system’s PATH variable; it will make your life easier later.
Pro Tip: During installation, associate .kt files with IntelliJ IDEA. This will automatically open Kotlin files in the IDE when you double-click them.
2. Create Your First Kotlin Project
Now that IntelliJ IDEA is installed, launch it. You’ll be greeted with a welcome screen. Click on “New Project.” In the project wizard, select “Kotlin” from the left-hand menu. Then, choose “JVM | IDEA” as the project template. This will create a basic Kotlin project for running console applications. Give your project a meaningful name (e.g., “MyFirstKotlinProject”) and specify a location to save it. Click “Create.”

This is what the New Project window should look like. Ensure that the project SDK is set to at least Java 8. If it’s not, click “Download JDK” and select a suitable version. I prefer using the Liberica JDK from BellSoft.
Common Mistake: Forgetting to set the Project SDK or selecting an older version of Java. Kotlin is designed to work seamlessly with modern Java versions.
3. Write Your “Hello, World!” Program
Once your project is created, you’ll see a default project structure. Create a new Kotlin file by right-clicking on the “src” folder in the Project view, selecting “New,” and then “Kotlin File/Class.” Name it “Main.kt” and choose “File” as the kind. Now, open “Main.kt” and type the following code:
fun main() {
println("Hello, World!")
}
This simple program defines a main function, which is the entry point of your application. The println function prints the text “Hello, World!” to the console.
Pro Tip: Learn to use Kotlin’s interactive mode. Within IntelliJ IDEA, right-click on your main function and select “Run ‘Main.kt'”. The output will appear in the Run tool window at the bottom of the IDE.
4. Run Your Program
To run your program, right-click anywhere in the “Main.kt” file and select “Run ‘Main.kt'”. IntelliJ IDEA will compile and execute your code, and you should see “Hello, World!” printed in the Run tool window at the bottom of the IDE. Congratulations, you’ve just run your first Kotlin program!

Common Mistake: Not setting up the Run configuration correctly. If you’re having trouble running your program, make sure the Run configuration is set to “Kotlin” and points to your “Main.kt” file.
5. Explore Basic Kotlin Syntax
Now that you have a working environment, it’s time to dive into the basics of Kotlin syntax. Let’s start with variable declaration. In Kotlin, you can declare variables using val (for read-only variables) and var (for mutable variables). For example:
val name: String = "Alice"
var age: Int = 30
Kotlin also supports type inference, so you can omit the type declaration if it’s obvious from the context:
val name = "Alice"
var age = 30
Next, let’s look at control flow statements. Kotlin provides familiar if/else, for, and while constructs. Here’s an example:
val score = 85
if (score >= 90) {
println("Excellent!")
} else if (score >= 70) {
println("Good")
} else {
println("Needs improvement")
}
Pro Tip: Kotlin’s when expression is a powerful alternative to multiple if/else statements. It allows you to write more concise and readable code.
6. Learn About Kotlin Data Classes
Kotlin data classes are a fantastic feature for creating classes that primarily hold data. They automatically generate useful methods like equals(), hashCode(), toString(), and copy(). Here’s an example:
data class Person(val name: String, val age: Int)
You can then create instances of this class and easily compare them or print their contents:
val person1 = Person("Bob", 40)
val person2 = Person("Bob", 40)
println(person1 == person2) // Output: true
println(person1) // Output: Person(name=Bob, age=40)
Common Mistake: Trying to manually implement equals(), hashCode(), and toString() for data classes. Let Kotlin handle it for you!
7. Explore Kotlin’s Null Safety Features
One of Kotlin’s key strengths is its built-in null safety. Kotlin distinguishes between nullable and non-nullable types. By default, variables cannot be assigned null values. To allow null values, you must explicitly declare a variable as nullable using the ? operator:
val nullableString: String? = null
val nonNullableString: String = "Hello" // This cannot be null
To access a nullable variable, you can use the safe call operator (?.) or the Elvis operator (?:):
println(nullableString?.length) // Output: null
println(nullableString?.length ?: 0) // Output: 0
Pro Tip: Embrace Kotlin’s null safety features to prevent NullPointerExceptions, a common source of bugs in Java.
8. Practice with Kotlin Koans
To solidify your understanding of Kotlin, I highly recommend working through the Kotlin Koans. These are a series of exercises that cover various aspects of the language, from basic syntax to advanced concepts. You can complete them online or within IntelliJ IDEA using the EduTools plugin.
Common Mistake: Skipping the practice exercises and jumping straight into building complex projects. Mastering the fundamentals is crucial for long-term success.
9. Build a Simple Application (Case Study)
Let’s put your newfound knowledge to the test by building a simple command-line application that manages a list of tasks. We’ll call it “TaskMaster 3000.” This is how I guide new developers joining my team at LexCorp in downtown Atlanta. The goal is to reinforce the concepts you’ve learned and get you comfortable with writing Kotlin code.
First, create a new Kotlin project in IntelliJ IDEA. Define a Task data class:
data class Task(val id: Int, val description: String, var completed: Boolean = false)
Next, create a TaskManager class that manages a list of tasks:
class TaskManager {
private val tasks = mutableListOf<Task>()
private var nextId = 1
fun addTask(description: String) {
val task = Task(nextId++, description)
tasks.add(task)
println("Task added with ID: ${task.id}")
}
fun completeTask(id: Int) {
val task = tasks.find { it.id == id }
if (task != null) {
task.completed = true
println("Task ${task.id} completed")
} else {
println("Task with ID $id not found")
}
}
fun listTasks() {
if (tasks.isEmpty()) {
println("No tasks found")
return
}
tasks.forEach {
println("${it.id}: ${it.description} (Completed: ${it.completed})")
}
}
}
Finally, create a main function to interact with the user:
fun main() {
val taskManager = TaskManager()
while (true) {
println("\nTaskMaster 3000")
println("1. Add Task")
println("2. Complete Task")
println("3. List Tasks")
println("4. Exit")
print("Enter your choice: ")
val choice = readLine()?.toIntOrNull()
when (choice) {
1 -> {
print("Enter task description: ")
val description = readLine() ?: ""
taskManager.addTask(description)
}
2 -> {
print("Enter task ID to complete: ")
val id = readLine()?.toIntOrNull() ?: 0
taskManager.completeTask(id)
}
3 -> taskManager.listTasks()
4 -> return
else -> println("Invalid choice")
}
}
}
This application allows you to add tasks, mark them as complete, and list them. It demonstrates the use of data classes, lists, and user input. We use this project to give candidates at LexCorp a feel for real-world Kotlin development. Last year, I had a candidate who refactored this code to use coroutines for asynchronous task processing – they got the job! You may also be interested in whether Kotlin will still be the right choice in the future.
10. Explore Android Development with Kotlin
While Kotlin is versatile, it shines in Android development. Once you’re comfortable with the basics, start exploring Android development using Kotlin. Android’s official documentation provides a wealth of resources and tutorials to guide you. You can create user interfaces, handle user input, and build full-fledged Android applications.
Pro Tip: Start with simple Android projects, such as a calculator or a to-do list app, to gradually learn the Android framework and Kotlin’s integration with it.
Kotlin is a powerful tool in the modern developer’s arsenal. By following these steps, you’ll gain a solid foundation in Kotlin and be well-equipped to tackle more complex projects. Don’t be afraid to experiment, explore, and build things that interest you. The best way to learn is by doing. So, get coding! Many developers also wonder if Kotlin can save a buggy Java app.
The single most important thing you can do right now is to write some code. Don’t just read about Kotlin; use it. Start with the “Hello, World!” example, then build the TaskMaster 3000 project, and then challenge yourself with something even more ambitious. That’s how you’ll internalize the concepts and truly master the language. You might even want to consider your first Kotlin program.