Skip to content

Kotlin

September 29, 2023
April 4, 2019

Kotlin Programming Language
Kotlin (programming language) - Wikiwand
Statically typed programming language for the JVM, Android, the browser and native

Kotlin Clean Architecture – ProAndroidDev
Kotlin, Android's new programming language - Things you need to know about it
kotlin - Amit Shekhar | Coder | Teacher | Mentor
Kt. Academy

Kotlin Course - Tutorial for Beginners - YouTube

Will everyone use Kotlin programming language instead of Java? - Quora
Toppling the Giant: Kotlin vs. Java
Kotlin on the server at Khan Academy | Khan Academy Engineering
What is Kotlin? The Java alternative explained | InfoWorld
Kotlin tutorial: Get started with Kotlin | InfoWorld
Beyond Java: Programming languages on the JVM | InfoWorld
8-Minute Crash Course on Kotlin Programming Language.

Kotlin vs Java The Whole Story | TechYourChanceTechYourChance
Kotlin - The Good, the Bad and the Ugly - DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

The Whys

Why Learn Kotlin? [Infographic] - DZone Java
Rise of Kotlin: The Programming Language for the Next Generation
Why you should totally switch to Kotlin – Magnus Vinther – Medium
Why Kotlin is my next programming language – Mike Hearn – Medium
Why Kotlin? Eight features that could convince Java developers to switch | JavaWorld

Kotlin: A massive leap forward – ProAndroidDev
Kotlin avoids entire categories of Java defects – ProAndroidDev
Kotlin is not Android - Kt. Academy

SDK

Working with the Command Line Compiler - Kotlin Programming Language
kotlinc is also the REPL

fun main(args: Array<String>) {
    println("Hello, World!")
}
kotlinc hello.kt -include-runtime -d hello.jar

# invoke by class
java -jar hello.jar
# invoke by class, Kotlin source file name is used to generate CamelCase Java class name
java -classpath hello.jar HelloKt

Inspecting compiled code:

kotlinc hello.kt
javap -c HelloKt.class

Kotlin Script

Kotlin can also be used to write script with .kts extension

KEEP/scripting-support.md at master Β· Kotlin/KEEP
Kotlin for scripting - Programming Kotlin

# script
kotlinc -script script.kts arg1 arg2
// script.main.kts:
@file:Import("common.main.kts")
val bar = "bar with $foo"

holgerbrandl/kscript: Scripting enhancements for Kotlin

Scratches can be created in IntelliJ IDEA to show result of each statement (and in near-realtime in Interactive mode)
Running Code Snippets - Kotlin Programming Language

Gradle Script Kotlin with Rodrigo Oliveira – Talking Kotlin

Playground

Kotlin Playground: Edit, Run, Share Kotlin Code Online
Kotlin Examples: Learn Kotlin Programming By Example

Try Kotlin old playground?

Learning

Reference - Kotlin Programming Language
Learning Kotlin: Introduction | Robert MacLean
Kotlin Bootcamp for Programmers | Udacity
Google Codelabs
Kotlin Bootcamp Course

Blog - SuperKotlin
Kotlin is Awesome!
mcxiaoke/awesome-kotlin: A curated list of awesome Kotlin frameworks, libraries, documents and other resources
DZone: Programming & DevOps news, tutorials & tools Learning Kotlin series by Robert Maclean
Learn Kotlin - Best Kotlin Tutorials (2019) | gitconnected

On Kotlin | Baeldung
Kotlin Mega Tutorial - SuperKotlin
Idioms - Kotlin Programming Language
Kotlin Tutorial - grokonez
Learning Kotlin: Introduction | Robert MacLean

Uberto Barbini – ProAndroidDev
uberto/kotlin-pearls

The problem with extension functions - Kt. Academy
Learn Kotlin Through Unit Tests - Android Developers - Medium

Conversion Program

Good for veteran programmers

Kotlin for Java Developers | Coursera !important, audit for free, with exercises in IntelliJ IDEA Educational Edition

The Kotlin Guide for the Busy Java Developer – ProAndroidDev
Kotlin for Python developers | kotlin-for-python-developers

Then do the Koans
Kotlin Koans: The Best Way To Learn Kotlin for Java Developers
Kotlin/kotlin-koans: Kotlin workshop offline

Hello, world! | Try Kotlin old playground?

Lambda

The parameter list of a lambda expression must be inside the curly brace and must not be enclosed in parentheses.

Lambda of zero or one parameter can omit the parameter list and arrow. The single parameter can be referred by it in lambda.
If the last parameter to a function is a function type and you use lambda, you can 1) put the lambda out of the omit parentheses; 2) omit the parentheses for invocation altogether if there is only one parameter.
This is very useful for enabling Kotlin a DSL.

Higher-Order Functions and Lambdas - Kotlin Programming Language
Lambda Expressions in Kotlin | Baeldung
Best Practices using Java 8 Lambdas | Baeldung
How Kotlin helps you avoid memory leaks – ProAndroidDev non-instance-capturing lambdas are translated to private, static methods
Diving into Higher order functions and lambdas in Kotlin
Lambda, Filter, and Map Function In Kotlin - AhsenSaeed
Function literals with receiver in Kotlin

Funtion reference - Kotlin Programming Language passing named function as reference

SAM

Calling Java from Kotlin - Kotlin Programming Language Like Java 8, lambda functions can be used directly to implement Single Abstract Method (SAM), no need for anonymous object

google: kotlin comparator sam
Learning Kotlin: Object Expressions and SAM Conversions - DZone Java

Reflection

Reflection - Kotlin Programming Language
KProperty - Kotlin Programming Language

Smartcast

Kotlin 1.3 stdlib used contract for smartcasting in functions
What's New in Kotlin 1.3 - Kotlin Programming Language
Kotlin Contracts | Baeldung
Kotlin Contracts: Make Great Deals With The Compiler! πŸ€œπŸ€›
Discovering Kotlin Contracts – ProAndroidDev

Kotlin DSL

Writing DSLs in Kotlin (part 1) – ProAndroidDev
Writing DSLs in Kotlin (part 2) – ProAndroidDev
Migrating Android build scripts from Groovy to Kotlin DSL

Mastering Kotlin DSL In Android - Step By Step Guide

A Kotlin Time DSL for Java 8 Time - Jworks.io

Java Interop

Java-Friendly Kotlin
How to write Java-Friendly Kotlin Code - Android Developers - Medium

Calling Java from Kotlin - Kotlin Programming Language

Calling Kotlin from Java - Kotlin Programming Language
Java Callingβ€Šβ€”β€ŠKotlin – ProAndroidDev

Run Kotlin Scripts from Kotlin Programs - Kotlin Expertise Blog
How can I run Kotlin-Script (.kts) files from within Kotlin/Java? - Stack Overflow

Module and Package

https://khan.github.io/kotlin-for-python-developers/#packages-and-imports

Module is defined by built tool and can consist of multiple packages. internal symbol is visible in the file and throughout all packages in the module.

Tips and Tricks

afollestad/library-template: A Kotlin + Android library template (with a sample project).

Abstract class vs interface in Kotlin – Kt. Academy
Kotlin: Sealed Classes - ITNEXT
Kotlin Generics Tutorial: Getting Started | raywenderlich.com

Increasing readability using operator conventions in Kotlin

Kotlin Native

Kotlin/Native - Kotlin Programming Language
A Basic Kotlin/Native Application - Kotlin Programming Language

Why we need Kotlin Native – Android Things – Medium
improvements in 1.3, but not for prime time yet
Is Kotlin/Native production ready? Why we are not using it (yet) - QuickBird Studios Blog
Why is Kotlin Native much slower than JVM? - Native - Kotlin Discussions
Debugging Kotlin Native’s Compiler – Kevin Galligan – Medium

kotlin-native/performance at master Β· JetBrains/kotlin-native Β· GitHub
frol/completely-unscientific-benchmarks: Naive performance comparison of a few programming languages (JavaScript, Kotlin, Rust, Swift, Nim, Python, Go, Haskell, D, C++, Java, C#, Object Pascal, Ada, Lua, Ruby)

The magic of Kotlin/Native: Part 1 – AndroIDIOTS – Medium
The magic of Kotlin/Native: Part 2 – AndroIDIOTS – Medium
The Magic of Kotlin/Native: Part 3 – AndroIDIOTS – Medium

Server

Introducing Kotlin support in Spring Framework 5.0
Tutorial Β· Building web applications with Spring Boot and Kotlin
Creating a RESTful Web Service with Spring Boot - Kotlin Programming Language
Going Reactive with Spring, Coroutines and Kotlin Flow

Kotlin Spring Boot Series - YouTube Habibi Coding

Ktor - asynchronous Web framework for Kotlin
Ktor for fast server prototyping. Ktor is framework for creating server… | by JarosΕ‚aw Michalik | Kt. Academy

Javalin - A lightweight Java and Kotlin web framework
Introducing Javalin: a Lightweight Web Framework for Java and Kotlin

#perfmatters

Faster command line tools with Kotlin - Renato Athaydes

Stdlib

kotlin-stdlib - Kotlin Programming Language
kotlin/libraries/stdlib/src/kotlin at master Β· JetBrains/kotlin source

Subtle differences between Kotlin's with(), apply(), let(), also(), and run()

Collections

c.size for collections
s.length for strings

Pair and Triple in Kotlin

Kotlin Collection Extensions Cheat Sheet by Xantier - Download free from Cheatography - Cheatography.com: Cheat Sheets For Every Occasion

Exploring Kotlin: useful standard library functions
Kotlin Sequences: An Illustrated Guide - Dave Leeds on Kotlin

Kotlin Array sort(), sortBy(), sortWith() - grokonez
Functional Android (II): Collection operations in Kotlin

Conversion between collections:
toList(), toMutableList(), toSet(), toMutableSet()

Collections vs Sequences: War of use-cases! - ProAndroidDev
Sequence<T> is a lazily evaluated list, like Python's generator. Use Collection.asSequence() to get a Sequence.

people.associateBy({it.ssn}, {it.name}) to generate a ssn to name Map. Omit the second lambda to generate a ssn to people Map ("key by" operation). Call toMutableMap() at the end to make the result mutable.

Concurrency

Coroutines Guide - Kotlin Programming Language
Kotlin Coroutines Tutorial for Android : Advanced | raywenderlich.com
A Bottom-Up View of Kotlin Coroutines
Understanding Kotlin coroutines - LogRocket Blog

Migrating your Network calls to Coroutines and Moshi in Kotlin
Caching with Kotlin Coroutines – ProAndroidDev
Async tasks with Kotlin Coroutines - NaNLABS
A simple way to work with Kotlin Coroutines in Android

Flow - kotlinx-coroutines-core
Simple design of Kotlin Flow – Roman Elizarov – Medium
Reactive Streams and Kotlin Flows - Roman Elizarov - Medium
Kotlin Flows and Coroutines – Roman Elizarov – Medium
Execution context of Kotlin Flows – Roman Elizarov – Medium
Blocking threads, suspending coroutines – Roman Elizarov – Medium
Explicit concurrency – Roman Elizarov – Medium

Style Guide

Coding Conventions - Kotlin Programming Language
Kotlin style guide | Android Developers

Coding Conventions - Kotlin Programming Language "Kotlin Coding Conventions" vs "IntelliJ IDEA default code style"

pinterest/ktlint: An anti-bikeshedding Kotlin linter with built-in formatter
Code Formatting in Kotlin using ktlint

Libraries

Awesome Kotlin Resources - Kotlin Resources

Vert.x building reactive applications

Compose Multiplatform Framework | JetBrains: Developer Tools for Professionals and Teams reactive Desktop and Web UI framework for Kotlin

CLI

Kotlin/kotlinx.cli: Pure Kotlin implementation of a generic CLI parser.
xenomachina/kotlin-argparser: Easy to use and concise yet powerful and robust command line argument parsing for Kotlin built on kotlin.cli
leprosus/kotlin-cli: Kotlin-CLI - command line interface options parser for Kotlin
Clikt: Simple, powerful command line parser for Kotlin
picocli - a mighty tiny command line interface
jimschubert/kopper: A simple Kotlin option parser

parameter passing - Functional style main function argument parsing for Kotlin - Stack Overflow