Kotlin is a modern programming language used to build Android applications. It was developed by JetBrains and officially supported by Google for Android development in 2017. Kotlin makes coding simpler, safer, and more enjoyable compared to older languages. Learning Kotlin helps you create mobile apps, games, and useful software that runs on billions of Android devices worldwide.
Kotlin is a statically-typed programming language that runs on the Java Virtual Machine (JVM). This means Kotlin code is checked for errors before the program runs, making it more reliable.
To write and run Kotlin programs for Android, you need specific software tools installed on your computer.
Every Kotlin program follows a specific structure with important components that make the code work properly.
The main function is the entry point where program execution begins. Every Kotlin program must have a main function.
fun main() { }To display output on the screen, Kotlin uses built-in print functions.
println("Hello, Android!") displays the message on screenComments are notes written in code that the computer ignores. They help programmers understand what the code does.
// This is a comment/* This comment spans multiple lines *//** Used for official documentation */Variables are containers that store information. Kotlin has different types of variables for different kinds of data.
Kotlin provides two keywords to create variables: val and var.
val name = "Rahul" or var age = 15Kotlin has several built-in data types for storing different kinds of information.

Type inference means Kotlin automatically detects the data type based on the assigned value. You don't always need to specify the type explicitly.
val age = 15 (Kotlin knows this is Int)val age: Int = 15 (Type specified manually)String templates allow you to insert variables directly inside text using the dollar sign ($).
val name = "Priya"; println("Hello, $name") outputs "Hello, Priya"println("Sum is ${5 + 3}") outputs "Sum is 8"Operators are symbols that perform operations on variables and values. Kotlin supports various types of operators.
Used to perform mathematical calculations.
5 + 3 = 810 - 4 = 66 × 7 = 4220 ÷ 4 = 517 % 5 = 2 (gives remainder after division)Used to compare two values. Result is always a Boolean (true or false).
5 == 5 returns true5 != 3 returns true8 > 5 returns true3 <> returns true5 >= 5 returns true4 <=> returns falseUsed to combine multiple conditions together.
(5 > 3) && (8 > 6) returns true(5 > 3) || (2 > 6) returns true!(5 > 3) returns falseUsed to assign values to variables with shortcuts for common operations.
var x = 10x += 5 means x = x + 5x -= 3 means x = x - 3x *= 2 means x = x × 2x /= 4 means x = x ÷ 4Control flow statements decide which code will execute based on conditions. They control the order in which instructions run.
The if statement executes code only when a condition is true. The else statement provides an alternative when the condition is false.
if (age >= 18) { println("Adult") }if (marks >= 40) { println("Pass") } else { println("Fail") }val result = if (a > b) a else bThe when expression is Kotlin's replacement for switch-case statements. It matches a value against multiple options.
when (variable) { value1 → action1; value2 → action2; else → defaultAction }when (x) { 1, 2, 3 → println("Small number") }when (age) { in 0..17 → println("Minor") }Loops repeat a block of code multiple times. Kotlin provides different types of loops for various situations.
The for loop repeats code for a specific number of times or iterates through a collection.
for (i in 1..5) { println(i) } prints numbers 1 to 5for (i in 1 until 5) { println(i) } prints 1 to 4 (excludes 5)for (i in 1..10 step 2) { println(i) } prints 1, 3, 5, 7, 9for (i in 5 downTo 1) { println(i) } prints 5 to 1 backwardsThe while loop repeats code as long as a condition remains true. The condition is checked before each iteration.
while (condition) { code to repeat }var count = 1; while (count <= 5)="" {="" println(count);="" count++="">The do-while loop executes code at least once, then checks the condition. Different from while loop which checks condition first.
do { code to repeat } while (condition)var x = 0; do { println(x); x++ } while (x <>Functions are reusable blocks of code that perform specific tasks. They help organize code and avoid repetition.
Functions in Kotlin are declared using the fun keyword.
fun functionName() { code }fun greet(name: String) { println("Hello, $name") }fun add(a: Int, b: Int): Int { return a + b }fun multiply(x: Int, y: Int) = x * y (return type inferred)Parameters are inputs that functions receive to perform their tasks.
fun greet(name: String = "User") { } uses "User" if no name providedgreet(name = "Amit") makes code clearer when multiple parameters existNull safety is Kotlin's most important feature. It prevents NullPointerException errors that commonly crash programs.
By default, Kotlin variables cannot hold null values. You must explicitly allow nullability.
var name: String = "Raj" cannot be assigned nullvar name: String? = null can hold null (note the question mark)The safe call operator (?.)) safely accesses properties or methods of nullable variables.
name?.lengthThe Elvis operator (?:) provides a default value when a variable is null.
val length = name?.length ?: 0The not-null assertion operator (!!) forces Kotlin to treat a nullable variable as non-null.
name!!.lengthCollections are containers that store multiple values together. Kotlin provides different types for different needs.
A List stores ordered elements that can be accessed by index position.
val numbers = listOf(1, 2, 3, 4, 5) cannot be modifiedval numbers = mutableListOf(1, 2, 3) can add or remove elementsnumbers[0] gets first element (indexing starts at 0)add(), remove(), size, contains()A Set stores unique elements with no duplicates allowed. Order is not guaranteed.
val fruits = setOf("apple", "banana", "apple") keeps only one "apple"val fruits = mutableSetOf("mango", "orange")A Map stores data as key-value pairs. Each key is unique and maps to exactly one value.
val capitals = mapOf("India" to "New Delhi", "France" to "Paris")val scores = mutableMapOf("Priya" to 95, "Amit" to 87)capitals["India"] returns "New Delhi"scores["Neha"] = 92val list = mutableListOf(1, 2) is valid. The reference is immutable but list contents can changevar name: String? = null; println(name.length) won't compile. Must use name?.lengthname?.length returns Int? not Int1..5 includes 5, but 1 until 5 excludes 5 (only goes to 4)fun double(x: Int) = x * 2fun add(a: Int, b: Int): Int { return a + b }listOf() creates read-only list. Cannot use add() or remove()studentAge instead of xKotlin provides a modern, safe, and beginner-friendly approach to programming for Android. Its concise syntax reduces code complexity while null safety features prevent common crashes. Mastering these basics-variables, data types, operators, control flow, functions, and collections-forms the foundation for building Android applications. Practice writing small programs regularly to strengthen understanding. Remember that Kotlin's design prioritizes developer productivity and code safety, making it an excellent choice for learning programming concepts.