Kotlin Programming Language

Kotlin — Complete Tutorial

Learn Kotlin from absolute zero. Every topic explained simply with real examples you can edit and understand quickly.

🟩 Beginner Friendly ▶ Live Code Editor 📚 26 Topics
Your Progress3% complete
Live Kotlin Lab

Edit the Kotlin example below and click Run to preview expected output notes.

kotlin-lab.kt
📝 Edit Code
👁 Live Preview
💡 Try this: modify values and method logic, then run again.
∙ Chapter 001

Kotlin Tutorial

Learn Kotlin Tutorial with a small example you can edit and run.

📝Syntax
fun main(){
  // ...
}
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

tutorial.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fun main() {Program entry point.
println("Welcome to Kotlin")Prints output.
}Kotlin line.
🏢Real-world
  • 1Kotlin is widely used for Android apps and JVM backends.
Common Mistakes
  • 1Mixing up val vs var and mutating unexpectedly.
Best Practices
  • 1Prefer val by default and keep functions small and clear.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin Tutorial
∙ Chapter 002

Kotlin HOME

Learn Kotlin HOME with a small example you can edit and run.

📝Syntax
fun main(){
  // ...
}
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

home.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fun main() {Program entry point.
println("Welcome to Kotlin")Prints output.
}Kotlin line.
🏢Real-world
  • 1Kotlin is widely used for Android apps and JVM backends.
Common Mistakes
  • 1Mixing up val vs var and mutating unexpectedly.
Best Practices
  • 1Prefer val by default and keep functions small and clear.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin HOME
∙ Chapter 003

Kotlin Intro

Learn Kotlin Intro with a small example you can edit and run.

📝Syntax
fun main(){
  // ...
}
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

intro.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fun main() {Program entry point.
println("Welcome to Kotlin")Prints output.
}Kotlin line.
🏢Real-world
  • 1Kotlin is widely used for Android apps and JVM backends.
Common Mistakes
  • 1Mixing up val vs var and mutating unexpectedly.
Best Practices
  • 1Prefer val by default and keep functions small and clear.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin Intro
∙ Chapter 004

Kotlin Get Started

Learn Kotlin Get Started with a small example you can edit and run.

📝Syntax
fun main(){
  // ...
}
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

get-started.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fun main() {Program entry point.
println("Welcome to Kotlin")Prints output.
}Kotlin line.
🏢Real-world
  • 1Kotlin is widely used for Android apps and JVM backends.
Common Mistakes
  • 1Mixing up val vs var and mutating unexpectedly.
Best Practices
  • 1Prefer val by default and keep functions small and clear.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin Get Started
Kotlin Basics
∙ Chapter 005

Kotlin Syntax

Learn Kotlin Syntax with a small example you can edit and run.

📝Syntax
fun main(){
  // ...
}
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

syntax.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fun main() {Program entry point.
val score = 82Declares a variable (val = immutable, var = mutable).
val result = if (score >= 75) "Pass" else "Fail"Declares a variable (val = immutable, var = mutable).
println(result)Prints output.
}Kotlin line.
🏢Real-world
  • 1Kotlin is widely used for Android apps and JVM backends.
Common Mistakes
  • 1Mixing up val vs var and mutating unexpectedly.
Best Practices
  • 1Prefer val by default and keep functions small and clear.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin Syntax
∙ Chapter 006

Kotlin Output

Learn Kotlin Output with a small example you can edit and run.

📝Syntax
println("Hello")
print("No newline")
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

output.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fun main() {Program entry point.
print("Hi")Prints output.
print(" ")Prints output.
println("Kotlin")Prints output.
}Kotlin line.
🏢Real-world
  • 1Kotlin is widely used for Android apps and JVM backends.
Common Mistakes
  • 1Mixing up val vs var and mutating unexpectedly.
Best Practices
  • 1Prefer val by default and keep functions small and clear.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin Output
∙ Chapter 007

Kotlin Comments

Learn Kotlin Comments with a small example you can edit and run.

📝Syntax
// single-line
/* multi-line */
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

comments.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fun main() {Program entry point.
/* Multi-lineKotlin line.
comment */Kotlin line.
println("Comments don't change output")Prints output.
}Kotlin line.
🏢Real-world
  • 1Kotlin is widely used for Android apps and JVM backends.
Common Mistakes
  • 1Mixing up val vs var and mutating unexpectedly.
Best Practices
  • 1Prefer val by default and keep functions small and clear.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin Comments
∙ Chapter 008

Kotlin Variables

Learn Kotlin Variables with a small example you can edit and run.

📝Syntax
val name: String = "Mana"
var age = 21
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

variables.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fun main() {Program entry point.
val name = "Mana"Declares a variable (val = immutable, var = mutable).
var level = 1Declares a variable (val = immutable, var = mutable).
level += 1Kotlin line.
println("$name level $level")Prints output.
}Kotlin line.
🏢Real-world
  • 1Kotlin is widely used for Android apps and JVM backends.
Common Mistakes
  • 1Mixing up val vs var and mutating unexpectedly.
Best Practices
  • 1Prefer val by default and keep functions small and clear.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin Variables
∙ Chapter 009

Kotlin Data Types

Learn Kotlin Data Types with a small example you can edit and run.

📝Syntax
val n: Int = 7
val pi: Double = 3.14
val ok: Boolean = true
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

data-types.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fun main() {Program entry point.
val a: Int = 10Declares a variable (val = immutable, var = mutable).
val b: Double = 3.5Declares a variable (val = immutable, var = mutable).
val ok: Boolean = trueDeclares a variable (val = immutable, var = mutable).
val ch: Char = 'A'Declares a variable (val = immutable, var = mutable).
println("$a, $b, $ok, $ch")Prints output.
}Kotlin line.
🏢Real-world
  • 1Kotlin is widely used for Android apps and JVM backends.
Common Mistakes
  • 1Mixing up val vs var and mutating unexpectedly.
Best Practices
  • 1Prefer val by default and keep functions small and clear.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin Data Types
∙ Chapter 010

Kotlin Operators

Learn Kotlin Operators with a small example you can edit and run.

📝Syntax
val sum = a + b
val gt = a > b
val mod = a % b
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

operators.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fun main() {Program entry point.
val a = 7Declares a variable (val = immutable, var = mutable).
val b = 3Declares a variable (val = immutable, var = mutable).
println(a + b)Prints output.
}Kotlin line.
🏢Real-world
  • 1Kotlin is widely used for Android apps and JVM backends.
Common Mistakes
  • 1Mixing up val vs var and mutating unexpectedly.
Best Practices
  • 1Prefer val by default and keep functions small and clear.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin Operators
∙ Chapter 011

Kotlin Strings

Learn Kotlin Strings with a small example you can edit and run.

📝Syntax
val s = "Kotlin"
println("$s length=${s.length}")
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

strings.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fun main() {Program entry point.
val name = "Mana"Declares a variable (val = immutable, var = mutable).
val msg = "$name Coding"Declares a variable (val = immutable, var = mutable).
println(msg)Prints output.
println(msg.length)Prints output.
}Kotlin line.
🏢Real-world
  • 1Strings are used for UI text, logs, and building messages.
Common Mistakes
  • 1Concatenating in loops instead of using templates/builders.
Best Practices
  • 1Use string templates and keep formatting consistent.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin Strings
∙ Chapter 012

Kotlin Booleans

Learn Kotlin Booleans with a small example you can edit and run.

📝Syntax
val ok = (a >= 10) && (b < 5)
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

booleans.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fun main() {Program entry point.
val a = 10Declares a variable (val = immutable, var = mutable).
val b = 2Declares a variable (val = immutable, var = mutable).
val ok = (a >= 10) && (b < 5)Declares a variable (val = immutable, var = mutable).
println(ok)Prints output.
}Kotlin line.
🏢Real-world
  • 1Kotlin is widely used for Android apps and JVM backends.
Common Mistakes
  • 1Mixing up val vs var and mutating unexpectedly.
Best Practices
  • 1Prefer val by default and keep functions small and clear.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin Booleans
Kotlin Control Flow
∙ Chapter 013

Kotlin If...Else

Learn Kotlin If...Else with a small example you can edit and run.

📝Syntax
val label = if (score >= 75) "Pass" else "Fail"
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

if-else.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fun main() {Program entry point.
val score = 75Declares a variable (val = immutable, var = mutable).
if (score >= 90) println("A")Prints output.
else if (score >= 75) println("B")Prints output.
else println("C")Prints output.
}Kotlin line.
🏢Real-world
  • 1Control flow powers validation, UI state, and business rules.
Common Mistakes
  • 1Forgetting edge cases (empty lists, boundaries).
Best Practices
  • 1Write readable conditions and test boundaries.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin If...Else
∙ Chapter 014

Kotlin When

Learn Kotlin When with a small example you can edit and run.

📝Syntax
val msg = when (day) {
  1 -> "Mon"
  else -> "Other"
}
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

when.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fun main() {Program entry point.
val day = 3Declares a variable (val = immutable, var = mutable).
val name = when (day) {Declares a variable (val = immutable, var = mutable).
1 -> "Mon"Kotlin line.
2 -> "Tue"Kotlin line.
3 -> "Wed"Kotlin line.
else -> "Other"Kotlin line.
}Kotlin line.
println(name)Prints output.
}Kotlin line.
🏢Real-world
  • 1Control flow powers validation, UI state, and business rules.
Common Mistakes
  • 1Forgetting edge cases (empty lists, boundaries).
Best Practices
  • 1Write readable conditions and test boundaries.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin When
∙ Chapter 015

Kotlin While Loop

Learn Kotlin While Loop with a small example you can edit and run.

📝Syntax
while (i <= 5) { i++ }
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

while-loop.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fun main() {Program entry point.
var n = 1Declares a variable (val = immutable, var = mutable).
var sum = 0Declares a variable (val = immutable, var = mutable).
while (n <= 5) {Loop while condition is true.
sum += nKotlin line.
n++Kotlin line.
}Kotlin line.
println(sum)Prints output.
}Kotlin line.
🏢Real-world
  • 1Control flow powers validation, UI state, and business rules.
Common Mistakes
  • 1Forgetting edge cases (empty lists, boundaries).
Best Practices
  • 1Write readable conditions and test boundaries.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin While Loop
∙ Chapter 016

Kotlin Break/Continue

Learn Kotlin Break/Continue with a small example you can edit and run.

📝Syntax
for (i in 1..10) {
  if (i == 3) continue
  if (i == 5) break
}
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

break-continue.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fun main() {Program entry point.
for (i in 1..6) {Loop over a range/collection.
if (i == 3) continueConditional branch.
if (i == 5) breakConditional branch.
println(i)Prints output.
}Kotlin line.
}Kotlin line.
🏢Real-world
  • 1Control flow powers validation, UI state, and business rules.
Common Mistakes
  • 1Forgetting edge cases (empty lists, boundaries).
Best Practices
  • 1Write readable conditions and test boundaries.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin Break/Continue
∙ Chapter 017

Kotlin Arrays

Learn Kotlin Arrays with a small example you can edit and run.

📝Syntax
val a = intArrayOf(1, 2, 3)
val b = arrayOf("A", "B")
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

arrays.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fun main() {Program entry point.
val nums = intArrayOf(1, 2, 3, 4)Declares a variable (val = immutable, var = mutable).
var sum = 0Declares a variable (val = immutable, var = mutable).
for (x in nums) sum += xLoop over a range/collection.
println(sum)Prints output.
}Kotlin line.
🏢Real-world
  • 1Kotlin is widely used for Android apps and JVM backends.
Common Mistakes
  • 1Mixing up val vs var and mutating unexpectedly.
Best Practices
  • 1Prefer val by default and keep functions small and clear.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin Arrays
∙ Chapter 018

Kotlin For Loop

Learn Kotlin For Loop with a small example you can edit and run.

📝Syntax
for (i in 1..3) println(i)
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

for-loop.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fun main() {Program entry point.
for (i in 1..3) {Loop over a range/collection.
print("i=$i ")Prints output.
}Kotlin line.
}Kotlin line.
🏢Real-world
  • 1Control flow powers validation, UI state, and business rules.
Common Mistakes
  • 1Forgetting edge cases (empty lists, boundaries).
Best Practices
  • 1Write readable conditions and test boundaries.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin For Loop
∙ Chapter 019

Kotlin Ranges

Learn Kotlin Ranges with a small example you can edit and run.

📝Syntax
for (i in 1..10 step 2) println(i)
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

ranges.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fun main() {Program entry point.
for (i in 1..10 step 2) {Loop over a range/collection.
print("$i ")Prints output.
}Kotlin line.
}Kotlin line.
🏢Real-world
  • 1Control flow powers validation, UI state, and business rules.
Common Mistakes
  • 1Forgetting edge cases (empty lists, boundaries).
Best Practices
  • 1Write readable conditions and test boundaries.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin Ranges
Kotlin Functions
∙ Chapter 020

Kotlin Functions

Learn Kotlin Functions with a small example you can edit and run.

📝Syntax
fun add(a: Int, b: Int): Int = a + b
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

functions.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
fun add(a: Int, b: Int): Int {Declares a function.
return a + bKotlin line.
}Kotlin line.
fun main() {Program entry point.
println(add(4, 6))Prints output.
}Kotlin line.
🏢Real-world
  • 1Functions help you reuse logic and keep code DRY.
Common Mistakes
  • 1Using unclear names and too many parameters.
Best Practices
  • 1Prefer small, pure functions with clear inputs/outputs.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin Functions
Kotlin Classes
∙ Chapter 021

Kotlin Classes

Learn Kotlin Classes with a small example you can edit and run.

📝Syntax
class Person(val name: String) {
  fun hi() = println("Hi $name")
}
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

classes.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
class Person(val name: String) {Declares a class.
fun greet() { println("Hello, $name!") }Declares a function.
}Kotlin line.
fun main() {Program entry point.
val p = Person("Developer")Declares a variable (val = immutable, var = mutable).
p.greet()Kotlin line.
}Kotlin line.
🏢Real-world
  • 1Classes model app domain objects and reusable components.
Common Mistakes
  • 1Overusing inheritance instead of composition.
Best Practices
  • 1Keep classes focused; use inheritance only when it fits.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin Classes
∙ Chapter 022

Kotlin OOP

Learn Kotlin OOP with a small example you can edit and run.

📝Syntax
class Person(val name: String) {
  fun hi() = println("Hi $name")
}
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

oop.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
class Person(val name: String) {Declares a class.
fun greet() { println("Hello, $name!") }Declares a function.
}Kotlin line.
fun main() {Program entry point.
val p = Person("Developer")Declares a variable (val = immutable, var = mutable).
p.greet()Kotlin line.
}Kotlin line.
🏢Real-world
  • 1Classes model app domain objects and reusable components.
Common Mistakes
  • 1Overusing inheritance instead of composition.
Best Practices
  • 1Keep classes focused; use inheritance only when it fits.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin OOP
∙ Chapter 023

Kotlin Classes/Objects

Learn Kotlin Classes/Objects with a small example you can edit and run.

📝Syntax
class Person(val name: String) {
  fun hi() = println("Hi $name")
}
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

classes-objects.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
class User(val name: String)Declares a class.
fun main() {Program entry point.
val u = User("Mana")Declares a variable (val = immutable, var = mutable).
println(u.name)Prints output.
}Kotlin line.
🏢Real-world
  • 1Classes model app domain objects and reusable components.
Common Mistakes
  • 1Overusing inheritance instead of composition.
Best Practices
  • 1Keep classes focused; use inheritance only when it fits.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin Classes/Objects
∙ Chapter 024

Kotlin Constructors

Learn Kotlin Constructors with a small example you can edit and run.

📝Syntax
class User(val name: String) { /* primary ctor */ }
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

constructors.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
class User(val name: String, var level: Int) {Declares a class.
fun up() { level++ }Declares a function.
}Kotlin line.
fun main() {Program entry point.
val u = User("Mana", 1)Declares a variable (val = immutable, var = mutable).
u.up()Kotlin line.
println("${u.name} level ${u.level}")Prints output.
}Kotlin line.
🏢Real-world
  • 1Classes model app domain objects and reusable components.
Common Mistakes
  • 1Overusing inheritance instead of composition.
Best Practices
  • 1Keep classes focused; use inheritance only when it fits.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin Constructors
∙ Chapter 025

Kotlin Class Functions

Learn Kotlin Class Functions with a small example you can edit and run.

📝Syntax
fun add(a: Int, b: Int): Int = a + b
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

class-functions.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
class Counter {Declares a class.
private var n = 0Kotlin line.
fun inc() { n++ }Declares a function.
fun value(): Int = nDeclares a function.
}Kotlin line.
fun main() {Program entry point.
val c = Counter()Declares a variable (val = immutable, var = mutable).
c.inc(); c.inc()Kotlin line.
println(c.value())Prints output.
}Kotlin line.
🏢Real-world
  • 1Functions help you reuse logic and keep code DRY.
Common Mistakes
  • 1Using unclear names and too many parameters.
Best Practices
  • 1Prefer small, pure functions with clear inputs/outputs.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin Class Functions
∙ Chapter 026

Kotlin Inheritance

Learn Kotlin Inheritance with a small example you can edit and run.

📝Syntax
open class Animal { open fun speak(){} }
class Dog : Animal() { override fun speak(){} }
Example (Edit & Run)

Edit the Kotlin code below and click Run. The output panel shows the extracted Expected Output notes (or simple prints).

inheritance.kt
📝 Edit Code
👁 Output
💡 Tip: keep a // Expected Output: line so the output panel has something to show.
🔍Line-by-line
LineMeaning
open class Animal {Declares a class that can be inherited.
open fun speak() { println("Animal") }Prints output.
}Kotlin line.
class Dog : Animal() {Declares a class.
override fun speak() { println("Woof") }Prints output.
}Kotlin line.
fun main() {Program entry point.
val a: Animal = Dog()Declares a variable (val = immutable, var = mutable).
a.speak()Kotlin line.
}Kotlin line.
🏢Real-world
  • 1Classes model app domain objects and reusable components.
Common Mistakes
  • 1Overusing inheritance instead of composition.
Best Practices
  • 1Keep classes focused; use inheritance only when it fits.
📖Summary & Practice
  • 1Edit the example and rerun to learn faster.
  • 2Use readable Kotlin first; optimize later.
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one value and predict the output.
  • 2Add one edge case and handle it.
  • 3Explain the rule in 1 sentence.
📈SEO

Keywords (topic intent):

Kotlin JVM Kotlin Inheritance
PreviousBack to Home
🎉 Kotlin Tutorial Complete (26 topics)!
Next UpMore Tutorials →