Kotlin Tutorial

Learn modern programming with Kotlin

🚀 Welcome to Kotlin

Kotlin is a modern, concise programming language that runs on the Java Virtual Machine. It's fully interoperable with Java and perfect for Android development, web development, and more.


fun main() {
    println("Hello, Kotlin World!")
}
                                    

Output:

Hello, Kotlin World!

Why Learn Kotlin?

📱

Android Development

Google's preferred language for Android apps

class MainActivity : AppCompatActivity()

Java Interoperability

Works seamlessly with existing Java code

val list = ArrayList()
🎯

Concise Syntax

Write less code, do more

data class User(val name: String)
🛡️

Null Safety

Prevents null pointer exceptions

var name: String? = null

🔹 What You'll Learn

  • Kotlin Basics: Variables, functions, and data types
  • Object-Oriented Programming: Classes, inheritance, and interfaces
  • Functional Programming: Lambda expressions and higher-order functions
  • Collections: Lists, sets, and maps
  • Null Safety: Handling nullable types safely
  • Coroutines: Asynchronous programming made easy

🔹 Quick Example

Here's a simple Kotlin program that demonstrates basic concepts:

// Data class
data class Person(val name: String, val age: Int)

// Function with default parameter
fun greet(person: Person, greeting: String = "Hello") {
    println("$greeting, ${person.name}! You are ${person.age} years old.")
}

fun main() {
    val person = Person("Alice", 25)
    greet(person)
    greet(person, "Hi")
}

Output:

Hello, Alice! You are 25 years old.
Hi, Alice! You are 25 years old.

🧠 Test Your Knowledge

What company developed Kotlin?