A collection of examples that let you run the Kotlin concepts you learned in theory. The progression is designed for step-by-step learning, from environment setup to Spring Boot and Kafka integration, practical coroutine usage, and Kotlin Multiplatform.

Example List#

The table below lists the available examples. We recommend going through them in order: environment setup first, then basic examples, Spring Boot integration, Kafka integration, practical coroutine usage, and finally the Multiplatform mini project.

ExampleDescriptionDifficulty
Environment SetupJDK, Gradle Kotlin DSL, IDE configurationBeginner
Basic ExamplesHello Kotlin, applying core conceptsBeginner
Spring Boot IntegrationKotlin + Spring Boot REST APIIntermediate
Kafka IntegrationProducer/Consumer in KotlinIntermediate
Practical CoroutinesReal-world scenarios using suspend and FlowIntermediate
Multiplatform IntroKMP mini projectAdvanced

Example Project Structure#

The examples follow the standard Gradle Kotlin DSL project structure. Below is the typical directory layout.

kotlin-example/
├── build.gradle.kts           # Build script (Kotlin DSL)
├── settings.gradle.kts
├── gradle/
│   └── wrapper/
└── src/
    ├── main/
    │   ├── kotlin/            # Kotlin sources
    │   └── resources/         # Resources (application.yml, etc.)
    └── test/
        ├── kotlin/            # Test code
        └── resources/

Project configuration and dependencies are defined in build.gradle.kts, and source code lives under src/main/kotlin/. Test code goes in src/test/kotlin/.

How to Run the Examples#

To run an example, first clone the repository, move into the example directory you want, and run the Gradle command.

Clone the project

git clone https://github.com/advanced-beginner/advanced-beginner.github.io.git
cd advanced-beginner.github.io

Run with Gradle Wrapper

Most examples run with a single ./gradlew command. The first run may take time due to dependency downloads.

./gradlew run

Spring Boot examples

Spring Boot examples are launched with the bootRun task.

./gradlew bootRun

Kafka examples

For Kafka examples, you must start a Kafka broker first. The Docker Compose configuration is in the docker/ directory at the project root.

cd docker && docker-compose up -d
cd ..
./gradlew bootRun

Key Learning Points per Example#

Here are the core concepts you can learn from each example.

Environment Setup covers the foundations of Kotlin development. You’ll learn JDK installation, writing Gradle Kotlin DSL, and IntelliJ IDEA configuration.

Basic Examples let you practice Kotlin’s core features — modeling data with data classes, writing expressive code using extension functions, and applying collection operations such as map, filter, and reduce.

Spring Boot Integration walks through using Kotlin together with Spring Boot. It covers Kotlin-friendly dependencies, writing controllers and services, and pitfalls when designing JPA entities.

Kafka Integration shows how to write Kafka Producers and Consumers in Kotlin, using KafkaTemplate and @KafkaListener for declarative message handling.

Practical Coroutines applies suspend functions and Flow to real-world scenarios — parallel external API calls, stream processing with backpressure, and structured concurrency patterns.

Multiplatform Intro introduces the basic structure of a Kotlin Multiplatform project and the expect/actual mechanism.

Hands-on Practice#

Don’t just run the example code — modify and experiment with it.

  1. Edit files under src/main/kotlin/
  2. Run ./gradlew run or ./gradlew run --continuous (auto re-run)
  3. Verify the result

With the --continuous flag, Gradle recompiles and re-runs automatically whenever files change.

Suggested Exercises

Try implementing the following exercises to sharpen your Kotlin skills.

For beginner exercises, write a program that filters even numbers from a list and prints their squares. Also try defining a Person(name, age) data class and sorting by age.

For intermediate exercises, implement a safe division function using Result<T>. Build a Spring Boot controller endpoint that uses coroutines to call two external APIs in parallel and combines their responses.

For advanced exercises, experiment with Kafka message stream processing using Flow and apply backpressure. Build a common module with Kotlin Multiplatform that runs on both JVM and JS.