Your first look at Kotlin

Reading MainActivity.kt, piece by piece

Let's decode that file you just saw, one keyword at a time β€” no prior Kotlin needed.

  • class MainActivity : ComponentActivity() β€” declares a class named MainActivity that inherits from ComponentActivity, Android's base class for a screen with its own lifecycle. The colon means "is a kind of."
  • override fun onCreate(savedInstanceState: Bundle?) β€” fun declares a function (Kotlin's word for what other languages call a method). override means this replaces a function ComponentActivity already defines β€” Android calls onCreate once, when the screen is first created. The ? after Bundle means the parameter is nullable: it might be a Bundle, or it might be null. Much more on that in Module 2.
  • setContent { … } β€” the bridge into Jetpack Compose. Everything inside those curly braces describes the UI declaratively β€” you say what the screen looks like for the current state, not a sequence of steps to build it.
  • PawWalkTheme { … }, Surface(...) β€” these are @Composable functions: ordinary Kotlin functions marked as UI-describing. Compose calls them to draw the screen, and re-calls them ("recomposes") whenever the state they read changes.

Compose vs SwiftUI, side by side

If you've done (or plan to do) the iOS track, the ideas map almost one-to-one:

| Concept | SwiftUI | Jetpack Compose |
|---|---|---|
| UI building block | struct conforming to View | @Composable function |
| Declare a constant | let | val |
| Declare a variable | var | var |
| Local UI state | @State | remember { mutableStateOf(...) } |
| Re-render on state change | automatic re-render | recomposition |
| Vertical stack | VStack | Column |
| Horizontal stack | HStack | Row |
| String interpolation | "\(name)" | "$name" |

Same job, different spelling. You'll see this table's rows again as real code throughout the course.