Kotlin from the ground up
The modern language on the Java virtual machine
- Beginner
- 12 chapters
- 200 min read
Learn Kotlin by running it: values and types, string templates, if and when as expressions, ranges and loops, functions with defaults and named arguments, lists, lambdas and the calls that replace most loops, maps, null safety, classes and data classes, and a sales report that uses the whole course at once.
What You'll Learn
- Write and run a Kotlin program, and know what the compiler expects of it
- Hold values in val and var, and tell whole numbers from decimals
- Build text with string templates, and drop an expression into a string
- Choose between values with if, and between many cases with when
- Repeat work with ranges, until, step, downTo, and while
- Write functions with return values, default arguments and named arguments
- Keep several values in a list, and read them by position or by name
- Replace loops with map, filter, sumOf, count and sortedBy
- Store lookups in a map, and handle a key that is not there
- Handle a value that may be missing with safe calls and fallbacks
- Model records with classes, constructors and data classes, and copy them
- Assemble a sales report with an interface, records and list transformations
Prerequisites
- No programming experience needed — this course starts at the first line
- Any other language you know will make the early chapters quick
Course Content
- 01Your first KotlinNot started
What Kotlin is, the main function every program begins at, println and print, and output you can read one line at a time.
- 02Values and typesNot started
Val and var, the handful of types you meet first, whole numbers against decimals, and converting between them on purpose.
- 03Text and string templatesNot started
Building text with templates, dropping an expression into a string with braces, and the everyday string names worth knowing.
- 04Decisions with if and whenNot started
Comparing values, choosing between two paths, and treating if and when as expressions that produce a value instead of only running code.
- 05Ranges and loopsNot started
Counting with ranges, the until, step and downTo that adjust them, looping over a list of values, and the while loop for when the count is unknown.
- 06FunctionsNot started
Naming a piece of work, giving it inputs and an answer, letting callers leave out arguments, and passing arguments by name so the call explains itself.
- 07ListsNot started
Holding several values in order, reading them by position, walking them with a loop, and the difference between listOf and mutableListOf.
- 08Lambdas and list workNot started
Passing a small function into a list call, the single input named it, and the handful of calls that replace most loops you would otherwise write.
- 09Key and value mapsNot started
Looking a value up by name instead of by position, what a missing key gives back, walking the pairs, and counting with a mutable map.
- 10Null safetyNot started
A value that may be missing, the question mark that says so in the type, the safe call and the fallback, and the double bang you should reach for last.
- 11Classes and data classesNot started
Grouping values with the behaviour that belongs to them, constructors that also declare properties, and the data class whose equals, text form and copy are written for you.
- 12Putting it together: a sales reportNot started
A capstone that uses the whole course once: an interface that promises a total, records as data classes, one transformation per question, and a report printed at the end.
