Kotlin Tutorial #7: Classes, Objects, and Data Classes

In the previous tutorial, you learned about control flow. Now let’s learn about classes — the foundation of object-oriented programming in Kotlin. Kotlin classes are more concise than Java classes. What takes 50 lines in Java takes 1 line in Kotlin with data classes. In this tutorial, you will learn: ...

March 19, 2026 · 8 min

Jetpack Compose Cheat Sheet 2026 — Every Component and Modifier

Bookmark this page. Use Ctrl+F (or Cmd+F on Mac) to find what you need. This cheat sheet covers Jetpack Compose components, modifiers, state, navigation, and common patterns. Last updated: April 2026 Core Composables Composable Usage Text("Hello") Display text Text("Bold", fontWeight = FontWeight.Bold) Styled text Button(onClick = { }) { Text("Click") } Clickable button OutlinedButton(onClick = { }) { Text("Outlined") } Outlined variant TextButton(onClick = { }) { Text("Text") } Text-only button IconButton(onClick = { }) { Icon(...) } Icon button TextField(value, onValueChange = { }) Text input field OutlinedTextField(value, onValueChange = { }) Outlined text input Image(painter, contentDescription) Display an image Icon(Icons.Default.Home, contentDescription) Material icon Checkbox(checked, onCheckedChange) Checkbox Switch(checked, onCheckedChange) Toggle switch RadioButton(selected, onClick) Radio button Slider(value, onValueChange) Slider CircularProgressIndicator() Loading spinner LinearProgressIndicator(progress) Progress bar HorizontalDivider() Horizontal divider line (replaces deprecated Divider()) Spacer(modifier = Modifier.height(16.dp)) Empty space Layouts // Column — vertical stack Column { Text("First") Text("Second") } // Row — horizontal stack Row { Text("Left") Spacer(Modifier.weight(1f)) Text("Right") } // Box — stack on top of each other Box { Image(...) // background Text("Overlay") // on top } // LazyColumn — scrollable vertical list (RecyclerView replacement) LazyColumn { items(list) { item -> Text(item.name) } } // LazyRow — scrollable horizontal list LazyRow { items(list) { item -> Card { Text(item.name) } } } // LazyVerticalGrid — grid layout LazyVerticalGrid(columns = GridCells.Fixed(2)) { items(list) { item -> Card { Text(item.name) } } } Common Modifiers Modifiers change the appearance and behavior of composables. Order matters — modifiers are applied top to bottom. ...

March 18, 2026 · 6 min

Jetpack Compose Tutorial #6: Lists — LazyColumn and LazyRow

Every app has lists. A chat app has a list of messages. A store app has a list of products. A settings app has a list of options. In the old Android world, you used RecyclerView — which needed an Adapter, a ViewHolder, a LayoutManager, and a lot of boilerplate code. In Compose, you just use LazyColumn. That’s it. LazyColumn vs Column — Why Not Just Use Column? You already know Column from Tutorial #2. Why not use it for lists? ...

March 18, 2026 · 9 min

Git Commands Cheat Sheet 2026 — Every Command You Need

Bookmark this page. Use Ctrl+F (or Cmd+F on Mac) to find what you need. This cheat sheet covers Git commands from basics to advanced workflows. Last updated: April 2026 Setup and Config Command Description git config --global user.name "Alex" Set your name (shown in commits) git config --global user.email "alex@example.com" Set your email git config --global init.defaultBranch main Set default branch name git config --list Show all config settings git init Create a new repository git clone <url> Clone a remote repository git clone <url> <folder> Clone into a specific folder Basic Workflow Command Description git status Show changed, staged, and untracked files git add <file> Stage a file for commit git add . Stage all changes git add -p Stage changes interactively (hunk by hunk) git commit -m "message" Commit staged changes git commit -am "message" Stage tracked files and commit (does NOT stage untracked files) git commit --amend Modify the last commit (add files or fix message) git diff Show unstaged changes git diff --staged Show staged changes (ready to commit) git diff HEAD Show all changes (staged + unstaged) Working Directory → git add → Staging Area → git commit → Repository Viewing History Command Description git log Show commit history git log --oneline One line per commit git log --oneline --graph --all Visual branch graph git log -5 Show last 5 commits git log --author="Alex" Filter by author git log --since="2026-01-01" Commits after a date git log -- <file> History of a specific file git show <commit> Show details of a commit git blame <file> Show who changed each line Branching Command Description git branch List local branches git branch -a List all branches (local + remote) git branch <name> Create a new branch git branch -d <name> Delete a branch (safe — won’t delete unmerged) git branch -D <name> Force delete a branch git branch -m <old> <new> Rename a branch git switch <name> Switch to a branch git switch -c <name> Create and switch to a new branch git checkout <name> Switch to a branch (older syntax) git checkout -b <name> Create and switch (older syntax) Branch Workflow (ASCII Diagram) main: A --- B --- C --- F (merge commit) \ / feature: D --- E - Merging Command Description git merge <branch> Merge branch into current branch git merge --no-ff <branch> Force a merge commit (no fast-forward) git merge --squash <branch> Merge all commits as one (does not auto-commit) git merge --abort Cancel a merge in progress Resolving Conflicts When Git cannot auto-merge, it marks conflicts in the file: ...

March 17, 2026 · 6 min

Jetpack Compose Tutorial #5: State — The Most Important Concept

This is the most important tutorial in the entire series. If you don’t understand state, nothing in Compose will make sense. If you do understand it, everything clicks. State is the reason the login form from the previous tutorial worked. It is the reason buttons can toggle, text fields can update, and screens can change. Without state, your UI is frozen — it shows something once and never changes. Let’s fix that. ...

March 17, 2026 · 10 min

Kotlin Cheat Sheet 2026 — Quick Reference Guide

Bookmark this page. Use Ctrl+F (or Cmd+F on Mac) to find what you need. This cheat sheet covers Kotlin syntax from basics to coroutines. Try examples live at play.kotlinlang.org. Last updated: April 2026 Variables Syntax Description val name = "Alex" Immutable (read-only) — cannot reassign var count = 0 Mutable — can reassign val age: Int = 25 Explicit type annotation const val PI = 3.14 Compile-time constant (top-level or object only) val name = "Alex" // type inferred as String var score = 0 // type inferred as Int score = 10 // OK — var can be reassigned // name = "Sam" // ERROR — val cannot be reassigned Basic Types Type Example Notes Int 42 32-bit integer Long 42L 64-bit integer Double 3.14 64-bit decimal Float 3.14f 32-bit decimal Boolean true, false String "hello" Immutable Char 'A' Single character Type Conversions val x: Int = 42 val d: Double = x.toDouble() // 42.0 val s: String = x.toString() // "42" val i: Int = "123".toInt() // 123 val safe: Int? = "abc".toIntOrNull() // null Null Safety Syntax Description String? Nullable type — can hold null name?.length Safe call — returns null if name is null name ?: "default" Elvis operator — use default if null name!! Not-null assertion — throws if null (avoid this) name?.let { ... } Execute block only if not null val name: String? = null val len = name?.length // null (no crash) val safe = name ?: "Unknown" // "Unknown" // val crash = name!!.length // throws NullPointerException String Templates val name = "Alex" println("Hello $name") // Hello Alex println("Length: ${name.length}") // Length: 4 println("Sum: ${2 + 3}") // Sum: 5 Functions // Regular function fun greet(name: String): String { return "Hello $name" } // Single-expression function fun greet(name: String) = "Hello $name" // Default parameters fun greet(name: String = "World") = "Hello $name" // Named arguments greet(name = "Alex") // Unit return type (void equivalent) fun log(message: String) { println(message) } Control Flow if / else (is an expression) val max = if (a > b) a else b when (replaces switch) when (x) { 1 -> println("one") 2, 3 -> println("two or three") in 4..10 -> println("between 4 and 10") is String -> println("it is a string") else -> println("something else") } // Guard conditions in when (Kotlin 2.2+) when (val result = fetchData()) { is Result.Success if result.data.isNotEmpty() -> show(result.data) is Result.Success -> showEmpty() is Result.Error -> showError(result.message) } // when as expression val label = when { score >= 90 -> "A" score >= 80 -> "B" else -> "C" } Loops for (i in 1..5) { } // 1, 2, 3, 4, 5 for (i in 1 until 5) { } // 1, 2, 3, 4 (or 1..<5) for (i in 1..<5) { } // 1, 2, 3, 4 (open-ended range, Kotlin 1.8+) for (i in 5 downTo 1) { } // 5, 4, 3, 2, 1 for (i in 0..10 step 2) { } // 0, 2, 4, 6, 8, 10 for (item in list) { } // iterate a collection list.forEachIndexed { index, item -> } Collections Type Create Mutable Version List listOf(1, 2, 3) mutableListOf(1, 2, 3) Set setOf(1, 2, 3) mutableSetOf(1, 2, 3) Map mapOf("a" to 1) mutableMapOf("a" to 1) Common Operations val numbers = listOf(1, 2, 3, 4, 5) numbers.filter { it > 2 } // [3, 4, 5] numbers.map { it * 2 } // [2, 4, 6, 8, 10] numbers.first() // 1 numbers.last() // 5 numbers.firstOrNull { it > 10 } // null numbers.any { it > 3 } // true numbers.all { it > 0 } // true numbers.count { it % 2 == 0 } // 2 numbers.sum() // 15 numbers.sorted() // [1, 2, 3, 4, 5] numbers.reversed() // [5, 4, 3, 2, 1] numbers.distinct() // remove duplicates numbers.take(3) // [1, 2, 3] numbers.drop(2) // [3, 4, 5] numbers.groupBy { it % 2 } // {1=[1,3,5], 0=[2,4]} numbers.associate { it to it * it } // {1=1, 2=4, 3=9, ...} numbers.flatMap { listOf(it, it * 10) } // [1,10,2,20,...] Map Operations val map = mapOf("a" to 1, "b" to 2) map["a"] // 1 map.getOrDefault("c", 0) // 0 map.keys // [a, b] map.values // [1, 2] map.entries // [a=1, b=2] map + ("c" to 3) // new map with c added Lambdas val double = { x: Int -> x * 2 } double(5) // 10 // Single parameter uses "it" val numbers = listOf(1, 2, 3) numbers.filter { it > 1 } // Trailing lambda numbers.fold(0) { acc, n -> acc + n } Classes // Data class — equals, hashCode, toString, copy generated data class User(val name: String, val age: Int) val user = User("Alex", 25) val copy = user.copy(age = 26) // Enum class enum class Color { RED, GREEN, BLUE } // Sealed class — restricted hierarchy sealed class Result { data class Success(val data: String) : Result() data class Error(val message: String) : Result() data object Loading : Result() } // Object — singleton object Database { fun connect() { } } // Companion object — static-like members class MyClass { companion object { fun create(): MyClass = MyClass() } } Extension Functions fun String.addExclamation() = "$this!" "Hello".addExclamation() // "Hello!" fun List<Int>.secondOrNull(): Int? = if (size >= 2) this[1] else null Scope Functions Function Object ref Return Use case let it Lambda result Null checks, transformations run this Lambda result Object config + compute result with this Lambda result Group calls on an object apply this Object itself Object configuration also it Object itself Side effects (logging, validation) // let — execute block if not null val length = name?.let { it.length } // apply — configure a builder/mutable object val paint = Paint().apply { color = Color.RED strokeWidth = 4f } // also — side effects val list = mutableListOf(1, 2).also { println("Before: $it") } // run — compute a result val result = service.run { connect() fetchData() } // with — group calls val info = with(user) { "$name is $age years old" } Coroutines Basics // Launch — fire and forget scope.launch { val data = fetchData() // suspend function updateUi(data) } // Async — returns a Deferred (future) val deferred = async { fetchData() } val result = deferred.await() // Parallel execution coroutineScope { val a = async { fetchA() } val b = async { fetchB() } println("${a.await()} ${b.await()}") } // Switch context withContext(Dispatchers.IO) { // Run on background thread readFile() } // Flow — reactive stream fun numbers(): Flow<Int> = flow { for (i in 1..3) { delay(100) emit(i) } } // collect is a suspend function — must be called inside a coroutine scope.launch { numbers().collect { println(it) } } Dispatcher Use case Dispatchers.Main UI updates Dispatchers.IO Network, database, file I/O Dispatchers.Default CPU-heavy computation Smart Casts // Kotlin auto-casts after a type check — no explicit cast needed fun printLength(x: Any) { if (x is String) { println(x.length) // x is auto-cast to String } } // Works with when too when (result) { is Result.Success -> println(result.data) is Result.Error -> println(result.message) } Value Classes // Wraps a value with zero runtime overhead (no extra object allocation) @JvmInline value class Email(val address: String) val email = Email("alex@example.com") // At runtime, this is just a String — no wrapper object Multi-line Strings val json = """ { "name": "Alex", "age": 25 } """.trimIndent() val sql = """ SELECT * FROM users WHERE age > 18 ORDER BY name """.trimIndent() Common Patterns Safe casting val x: Any = "hello" val s: String? = x as? String // "hello" val i: Int? = x as? Int // null (no crash) Destructuring val (name, age) = User("Alex", 25) val (key, value) = mapEntry takeIf / takeUnless val positiveNumber = number.takeIf { it > 0 } // number or null val nonBlank = name.takeUnless { it.isBlank() } // name or null // Chain with Elvis val port = config.getPort().takeIf { it in 1..65535 } ?: 8080 Lazy initialization val heavy: String by lazy { println("Computed!") "result" } Common Mistakes Mutable vs immutable collections — listOf() returns a read-only List. Use mutableListOf() if you need add() or remove(). Casting a List to MutableList is unsafe. ...

March 16, 2026 · 7 min

Jetpack Compose Text, Button, Image, and TextField: Complete Guide

You know layouts. You know modifiers. Now let’s learn the components you will use in every single screen — Text, Button, Image, and TextField. These are the building blocks of every Android app. Get comfortable with them and you can build almost anything. Text — Showing Words on Screen You have already used Text, but there is much more to it. Basic Text Text("Hello, World!") Styling Text Text( text = "Styled Text", fontSize = 24.sp, fontWeight = FontWeight.Bold, color = Color.Blue, letterSpacing = 1.sp, textAlign = TextAlign.Center, modifier = Modifier.fillMaxWidth() ) All the Style Options Property What It Does Example fontSize Text size 16.sp, 24.sp fontWeight Thickness FontWeight.Bold, FontWeight.Light fontStyle Italic or normal FontStyle.Italic color Text color Color.Red, Color(0xFF333333) textAlign Alignment TextAlign.Center, TextAlign.End letterSpacing Space between letters 2.sp lineHeight Space between lines 28.sp maxLines Maximum number of lines 1, 3 overflow What happens when text is too long TextOverflow.Ellipsis textDecoration Underline or strikethrough TextDecoration.Underline Truncating Long Text When text is too long for the available space: ...

March 16, 2026 · 9 min

Jetpack Compose Tutorial #3: Modifiers — The Secret to Styling Everything

In the previous tutorial, we learned how to arrange things on screen with Column, Row, and Box. But everything looked plain. No padding. No colors. No borders. That is where Modifiers come in. Modifiers are how you control everything about how a Composable looks and behaves — size, spacing, color, shape, click behavior, scrolling, and more. If layouts are the skeleton, modifiers are the skin and muscles. What is a Modifier? A Modifier is a chain of instructions that you attach to a Composable. Each instruction changes one thing about how it looks or acts. ...

March 15, 2026 · 9 min

Jetpack Compose Layouts: Column, Row, and Box Explained with Examples

In the previous tutorial, we wrote our first Composable. But one Text on the screen is not an app. You need to put things next to each other, below each other, and on top of each other. That is what layouts do. Compose gives you three main layout components: Column — puts things vertically (top to bottom) Row — puts things horizontally (left to right) Box — puts things on top of each other (like layers) Every screen you will ever build uses a combination of these three. Master them and you can build anything. ...

March 14, 2026 · 12 min

Jetpack Compose Tutorial #10: MVI — Keep Your App Simple and Clean

Your app is growing. Your code is getting messy. Let’s fix that. Jetpack Compose makes building Android UI easy. But here is the problem — when your app gets bigger, things get complicated fast. Buttons, loading spinners, error messages… suddenly your code is everywhere. MVI can help you organize all of this. In this guide, you will learn: What MVI means (in plain words) Why it works so well with Jetpack Compose How to build a real example, step by step Mistakes you should avoid Let’s start. ...

March 14, 2026 · 6 min