Kotlin Cheat Sheet
Practical Kotlin cheat sheet with setup steps, core workflows, debugging, and copy-paste examples.
kotlin syntax examples reference
Kotlin cheat sheet with real commands and snippets for setup, core workflows, debugging, and production-safe automation patterns. If you are working across tools, pair this with the JSON Cheat Sheet and LaTeX Cheat Sheet.
Setup and Tooling
Goal: Install and verify language toolchain
# Run kotlinc command
kotlinc -version
# Run sdk command
sdk install kotlin
# Run gradle command
gradle -v
Core Workflows
Goal: Run and build source code
# Execute kotlinc workflow
kotlinc Main.kt -include-runtime -d main.jar
# Execute java workflow
java -jar main.jar
Goal: Use a practical code snippet
data class User(val id: Int, val name: String)
fun main() {
val users = listOf(User(1, "Ada"), User(2, "Linus"))
println(users.first().name)
}
Testing and Formatting
Goal: Run automated tests
# Execute test-related command
./gradlew test
# Execute test-related command
./gradlew check
Goal: Run lint and formatter checks
# Execute quality command
./gradlew ktlintFormat
# Execute quality command
./gradlew detekt
Automation and CI
Goal: Create a repeatable CI shell step
# Run strict shell mode for CI step
set -euo pipefail
# Install dependencies deterministically
npm ci || pip install -r requirements.txt || true
# Run tests and fail fast on errors
./gradlew test
Debugging and Troubleshooting
Goal: Trace runtime issues
# Print runtime and package manager versions
node --version || python --version || true
# Search stack traces and TODO markers
rg "Traceback|Exception|TODO" .
# Re-run tests with verbose output
./gradlew test -v || ./gradlew test --verbose || true
Common Gotchas
- Pin Kotlin language/runtime versions in local and CI environments.
- Keep formatting and linting automated to avoid noisy diffs in code review.
- Prefer explicit dependency lock files for reproducible builds.
- Write small, deterministic tests that can run quickly in pre-commit checks.
- Document compiler/interpreter flags used in production builds.
Related Sheets
- JSON Cheat Sheet — daily JSON commands and production-ready examples.
- LaTeX Cheat Sheet — daily LaTeX commands and production-ready examples.
- Markdown Cheat Sheet — daily Markdown commands and production-ready examples.
Related Cheat Sheets
JSON Cheat Sheet
Practical JSON cheat sheet with setup steps, core workflows, debugging, and copy-paste examples.
LaTeX Cheat Sheet
Practical LaTeX cheat sheet with setup steps, core workflows, debugging, and copy-paste examples.
Markdown Cheat Sheet
Practical Markdown cheat sheet with setup steps, core workflows, debugging, and copy-paste examples.