
Master Kotlin basics and functional programming with lambdas, then apply Kotlin to Android by exploring data classes, extension functions, and practical topics like SQLite, RecyclerView, and a habits app.
Code along with every lecture, complete all exercises, quizzes, and coding challenges to apply what you learn, and participate in the Q and A to share insights.
Discover why Kotlin, around since 2011 with a 2016 stable release, boosts production ready code quality for Android, with adoption by Uber, Pinterest, Trello, Evernote, and growing Kotlin jobs.
Set up Java and Android Studio to prepare your development environment for Android app development. Install or verify the Kotlin plugin, noting Android Studio 3 includes it by default.
Download and install the Java JDK 8 update 131 across Windows, macOS, or Linux, after accepting the license agreement, since Kotlin runs on the Java Virtual Machine.
Install Android Studio, the Google-built IDE based on IntelliJ, to develop Android apps with Kotlin support, and set up the Android SDK and emulator.
Set up a first Android Studio project with Kotlin support, configure Gradle, and run an empty activity app on a Nexus 5X emulator with Android O.
You now have all the tools to develop Android apps in Kotlin, with Java and Android Studio ready with the Kotlin plugin, and you'll dive into Kotlin next.
Dive into Kotlin basics by exploring conditionals, loops, and variables, and compare Kotlin with Java to spot differences and similarities for experienced developers.
Practice declaring variables in Kotlin with var and val in the REPL, learn type inference, and embrace immutability while exploring data types like Boolean, Double, Float, Char, Short, Long.
Explore Kotlin's null safety: default non-null types, nullable types with ?, safe call and Elvis operator, and safe versus unsafe access, plus Java interop considerations.
Explore how Kotlin uses if and when expressions to return values, assign results from branches, and safely handle nullable types by casting to non-nullable when appropriate.
Explore Kotlin when expressions as a switch-like construct with ranges and else defaults. See how when is an expression that returns values and requires no break.
Explore how Kotlin collections extend Java collections api and distinguish immutable from mutable types. Understand mutable versus immutable collections and creation helpers like listOf and mapOf.
Explore Kotlin for loops over ranges, strings, and collections using for in, with downTo and step, and compare it to Java loop syntax.
Master while and do while loops in Java, compare them with for loops, and learn when to use each for unknown iterations or validating user input such as email addresses.
Master Kotlin fundamentals by learning how to create functions with the fun keyword, specifying parameters and return types, and using concise shorthand and vararg forms for flexible calls.
Set up IntelliJ IDEA to write real Kotlin files and practice serious coding, choosing the free community edition and a Kotlin JVM project named KotlinAndroid.
Create a main() function in a Kotlin file, using a top-level function and constants, and print a list and a pi value to the console.
Explore Kotlin's default parameter values to simplify calls without overloading. Use named arguments to reorder parameters and improve readability in a concat example with a default comma-space separator.
Explore Kotlin exception handling by throwing and catching an IOException with try-catch-finally, and learn that Kotlin omits checked exceptions and uses try as an expression.
Explain how Java’s checked exceptions require throws clauses and propagate through layers, why Kotlin omits them, and contrast with unchecked exceptions like illegal state exception.
Explore Kotlin's concise, expressive syntax with immutability via val and immutable collections, non-null by default types, safe call operators, and default parameter values, highlighting benefits over Java.
Explore functional programming in Kotlin, learn how it avoids side effects and enables concise, readable code, see how these concepts apply in Java 8 and languages like Swift and Scala.
Explore the foundations of functional programming, including immutability, lambda expressions, and higher order functions, and see how Kotlin blends functional and object-oriented paradigms for modular, concise solutions.
Explore higher order functions, lambda expressions, and lazy evaluation to write reusable, composable Kotlin code for functional programming on Android.
Explore lambdas and higher-order functions in Kotlin by defining unnamed functions, using filter on ranges, and applying implicit it, function pointers with double colon, and last-argument lambda simplification for readability.
Explore Kotlin's map and flatMap to apply functions to collections with lambdas, including doubling elements, centering data by the average, and flattening nested lists into a single list.
Explore take and drop in Kotlin to efficiently handle lists and infinite sequences, using lazy sequences, toList, and chaining with map and filter for calculations on only the needed elements.
Learn the Kotlin zip function for pairing two collections into string–boolean pairs, compare it with list.zip and map, and chain higher order functions on collections.
Chain Kotlin collection API functions to transform a complex list of maps into a clean int array by flatMap, flatten, filter, and toIntArray.
Explore Kotlin lazy sequences and convert collections with asSequence to enable on-demand evaluation, using filter, map, and take to illustrate lazy computation and its equivalence to Java 8 streams.
Compare the performance of lazy sequences versus normal collections in Kotlin using the measured time release helper; see how lazy evaluation shines with large data and multiple operations, with caveats.
Implement the sieve of Eratosthenes in Kotlin using lazy sequences to generate an infinite stream of primes. Use a pair-based prime sequence and filtering to derive primes on demand.
Explore the Kotlin let operator for scoping and nullable handling, using it to confine a buffered reader to its block and to safely operate on non-null strings with smartcast.
Use the with higher order function to perform many calls on the same object with a lambda, reducing repetition and grouping related statements.
Explore Kotlin's use higher-order function for Closeable resources, replicating Java's try-with-resources. Learn how use automatically closes sockets, files, and database connections to prevent resource leaks.
Discover how inline functions in Kotlin turn higher-order lambdas into inlined code, reducing overhead by avoiding anonymous objects and enabling efficient use of let, with, run, apply, and more.
Learn to apply functional programming in Kotlin to write modular, concise, and readable code using higher-order functions, lambdas, and lazy sequences, and prepare to apply these idioms in Android apps.
Compare Kotlin's object-oriented features with Java, exploring data classes, inheritance, constructors, and property access, and discover how Kotlin reduces boilerplate for concise, expressive code.
Explore Kotlin classes as the foundation of object orientation, compare to Java, and learn about CamelCase, optional class bodies, the implicit constructor, and instantiate without a new keyword.
Explore how Kotlin handles properties with explicit getters and setters, including backing fields and implicit calls, and compare with Java’s fields while preparing to define properties in constructors.
Explore Kotlin constructors by building a Country class, converting constructor parameters to properties with val, using an init block, and wiring primary and secondary constructors with delegation and default values.
Discover how Kotlin class methods add logic to data by defining functions inside a class, using parameters and return values, and accessing properties such as a robot's name.
Explore Kotlin extension functions to add methods to existing classes, improving readability by calling functions like isEven on integers and isLarge on City, without utility classes.
Discover how Kotlin data classes reduce boilerplate by auto-generating hashCode, equals, toString, and copy methods, enabling destructuring and concise structural and referential equality for more readable, robust code.
Explore Kotlin enums via enum class, defining direction or suits, optionally with parameters, and apply when expressions to ensure exhaustiveness without else unless cases missing.
Learn how Kotlin requires open classes to enable inheritance, allowing child classes to inherit properties and methods from a base class for code reuse and maintainability.
Explore inheritance in Kotlin by creating an open Shape class and a Circle subclass with a radius, overriding the area calculation, and using open and final keywords to manage inheritance.
Learn how to use abstract classes to shape inheritance in Kotlin, defining an abstract area method, implementing it in concrete subclasses like Circle, and transitioning to interfaces next.
Explore how interfaces in Kotlin declare APIs for classes, defining methods like drive() and properties without constructors. Learn to implement and override these interfaces in concrete classes to achieve abstraction.
Explore Kotlin's overriding rules, including checks for the override keyword, distinguishing between two parents with qualified super calls, and overriding val with var while implementing abstract methods in a class.
Explore Kotlin's smart casts using the is operator to distinguish between Bicycle and Boat behind a drivable interface, enabling safe method calls like replaceWheel and startEngine without boilerplate.
Explore Kotlin visibilities, including private, protected, internal, and public, and how they enforce information hiding. Note the default public, top-level vs module scope, and the absence of package-private in Kotlin.
Kotlin uses companion objects to replace Java static members, housing static-like properties and methods. Access them via the class name; you can implement interfaces or create factory methods.
Use Kotlin object declarations to create singletons with one instance, accessible by the object name. They have no constructor, hold properties and methods, and can extend parent class or interface.
Explore Kotlin packaging and imports, including package declarations, imports and star imports, top-level functions and properties, companion objects, type aliases, and aliasing with the as keyword, with parallels to Java.
Explore generic classes in Kotlin, compare them to Java, and learn to use generic type parameters with a timeline and maps.
Master how to create generic functions in Kotlin with a timelineOf function, using vararg parameters and a type parameter to produce a timeline of any type, improving readability and maintainability.
Explore covariance by showing how a list of person can accept student, and why read-only collections are covariant while mutable ones are not, with notes on Kotlin and Java differences.
Explore covariance in Kotlin and Java, compare adding covariant collections in Kotlin versus Java, and learn how bounded type parameters solve covariant reuse for time series data.
Explore covariance and contravariance in Kotlin, using out and in to define producers and sinks, and compare with Java invariance.
Recap Kotlin fundamentals, outlining object-oriented design, data classes, smart casts, singletons, and generics with variance to boost reusable Android app code.
Learn how Kotlin enhances Android and Java development with extension functions, higher-order functions, and data classes to write cleaner, safer, non-null code.
Create a new Android Kotlin project named HabitTrainer with package com.petersommerhoff.habittrainer, set MainActivity and layout, enable backwards compatibility, and prepare Kotlin settings to run Hello World.
Explore how Android versions affect app compatibility by configuring compile, min, and target sdk versions, and use Google support libraries to reach over 99% of users.
Create a CardView inside a ScrollView to display habits, with a 22dp image and title and description text, using XML.
Compare the Java way of wiring a text view with the Kotlin approach that uses lateinit and Kotlin Android extensions to access layout elements directly, reducing nulls and boilerplate.
Learn to replace fixed texts with resources, use start/end for RTL compatibility, set content descriptions with string resources, and implement a Kotlin RecyclerView to render multiple habit cards efficiently.
Learn to implement a RecyclerView in Android with Kotlin, a common task that reinforces classes, object orientation, and overriding methods, while launching your Kotlin on Android journey.
Modularize layouts into a single card layout and a recycler view container, then wire up the adapter. Understand how the recycler view recycles items for efficient long lists of habits.
Learn how to implement a recycler view in android, define a habit data class with title, description, and image, and create a habits adapter with sample data for display.
Create a habits adapter for a recycler view to feed a list of habits, and implement a habit view holder by extending RecyclerView.Adapter and overriding onCreateViewHolder, onBindViewHolder, and getItemCount.
Implement onCreateViewHolder and onBindViewHolder to inflate the single card layout, create habit view holders, and bind title, description, and image while reusing views for efficiency.
Bind each habit to a card in a recycler view using a HabitViewHolder. Use null-safe access and Kotlin extensions to set the title, description, and image, with subtle card styling.
Create new habits in the app, store them in SQLite, and switch between activities using Kotlin. Design menus, layouts, and image selection from the gallery.
Create and configure a new Android menu by adding a menu resource, a main menu item begin new habit, extracting a string resource, and overriding activity methods to attach it.
Override onCreateOptionsMenu to inflate main_menu.xml with the menu inflater, attach the begin new habit entry to the main activity, so the menu appears.
Use intents to switch activities when a menu item is selected. Override onOptionsItemSelected, build an intent with the current context and CreateHabitActivity, and call startActivity.
Replace constraint layout with a vertical linear layout to build the create habit screen, adding title and description edits, a choose image button, and a preview image view.
Let users pick an image for a habit by handling an onClick event with a chooseImage method that launches an intent using Intent.ACTION_GET_CONTENT for image/* and a chooser.
Get the user-selected image via startActivityForResult with a choose image request and handle onActivityResult. Read the bitmap using a content resolver, then preview it in the image view.
Validate title, description, and image on save, logging omissions for debugging. Display error messages with a reusable displayErrorMessage function and prepare to store the habit in SQLite using Kotlin.
Learn to use extension functions on edit text to check isBlank with a concise, readable approach, including file level and private implementations, and prep for sequel-like databases.
Learn to integrate SQLite databases in Android using Kotlin, streamline database transactions, and apply extension and higher-order functions to produce readable, concise code.
Define the SQLite database schema and contracts for a habit app, and apply Kotlin extension functions and higher-order functions to write and read data with cleaner Android code.
Define the database contracts by creating a habit table with title, description, and image, and set the database name habittrainer.db and version to 1.
Implement HabitTrainerDb as a Kotlin SQLiteOpenHelper to create and upgrade the Habit table with id, title, description, and image. Use onCreate, onUpgrade, and sql_create_entries and sql_delete_entries for creation and upgrade.
Implement HabitDbTable with a store method that uses a writable database and returns the new row id. Convert the Bitmap to a byte array for storage.
Transform a db.insert() into a robust transaction using beginTransaction, try, setTransactionSuccessful, and endTransaction. Show Kotlin improvements with higher-order and extension functions to remove boilerplate and improve safety over Java.
Modularize transactions with a Kotlin extension on SQLiteDatabase to encapsulate begin, commit, and close. Compose concise, readable inserts by passing a higher-order block.
Enhance Kotlin extension for SQLite transactions by making it generic and inline, returning type T, reducing object creation, and improving performance while preserving modular, readable code.
Use with values to concisely build data, read title, description, and bitmap in create habit activity, store the habit via HabitDB, and return to main activity.
Learn to read all habits from the SQLite database using a readable database, select id, title, description, and image, iterate the cursor, decode the image, and return a Habit list.
Improve a dp.query call by adding a private Kotlin extension on SQLiteDatabase with defaults. Create doquery to mirror parameters, then replace the call with explicit names to map order by.
Explore Kotlin clean-code techniques by refactoring Android database access with extension functions on Cursor, reading title, description, and bitmap via getString, getBlob, BitmapFactory, and parseHabitFromCursor and parseHabitsFromCursor with HabitEntry.
Drag and drop image files into the Android virtual device to copy them to the downloads folder, then access recent to select custom images for habits.
Learn to use Kotlin the right way to actually improve your Android app code
Write null-safe, concise, and readable code in Kotlin using functional and object-oriented concepts
Work around unnecessary boilerplate code when using Android APIs (e.g. SQLite) using higher-order extension functions
Use Android Studio effectively to speed up your development workflow
Get your questions answered along the way should you ever get stuck
Why Take This Course?
I've been involved with Kotlin since late 2015, before it was released in its first stable version. As the instructor of the course "Kotlin for Beginners", I know which topics students are interested in or get stuck with.
My first Kotlin course is recommended from the official Kotlin website and from the official Android website as a resource to learn Kotlin for Android. So you can be sure to get quality teaching here.
After this course, you'll be able to confidently use Kotlin for any kind of project -- but we'll of course apply what we learn to Android app development in this course.
What Makes This Course Special?
Since Google's #IO17 announcement to officially support Kotlin on Android, many new courses on the topic have been released -- which is great because it further helps to spread the language.
What makes this course special is that while most other courses do not teach good coding style, this course will focus on producing clean code and teaches you to make use of Kotlin's amazing features to actually write better code than in Java. This way, you will get a huge benefit using Kotlin instead of Java, e.g. by avoiding boilerplate code around many Android APIs.
What This Course Is NOT
This course is not an Android reference, I assume you already have at least some Android experience. Instead, you'll learn to write cleaner code for your apps by applying Kotlin's powerful language features to avoid unnecessary ceremony around Android APIs. Also, at the end of the course, you'll be able to use Kotlin for any kind of project -- not just for Android apps.
What Students Say About Me (taken from "Kotlin for Beginners")
"TLDR; One of the best Kotlin course for beginners on Udemy! I took some time to write this review and wanted to finish the course THEN watch other courses offered here on Udemy and THEN want to see how good Peter was in teaching me basics of Kotlin so that I can apply the knowledge while writing actual android apps. And I am happy to report that it has helped me immensely. It wouldn't be wrong if I say that the I was easily understanding the WHYs and WHATs even if the teacher wasn't explaining in detail in other courses... Thank you Peter! You have taught me well! [...]"
- Hasaan
"Great introduction to Kotlin and programming for beginner programmers!"
- Per-Erik
"Easy to follow, instructor goes at a great pace that's friendly for beginners."
- Ronaldo
"beyond excellent!!!!"
- Mike
"Great start so far. Looking forward to a great course. Best online course I have taken, by far!!"
- James
"Found this to be a very good course to get an overview of Kotlin. Everything was explained clearly and the examples and exercises were very helpful. I'm glad that Peter is considering a course for Android using Kotlin since I'm curious about that subject."
- James
What You'll Learn
How to set up all you need for Android development using Kotlin (e.g. how to install Android Studio)
The basics of Kotlin: variables, null safety, immutability, conditionals, loops, functions, exception handling
Functional programming in Kotlin: higher-order functions, lambda expressions, lazy evaluation, lazy sequences, the Kotlin standard library
Object-oriented programming in Kotlin: all you know from Java + data classes, extension functions, smart casts, object declarations, differences from Java concerning inheritance
Android development with Kotlin: creating activities, layouts, menus, click listeners, working around unnecessarily complex Android APIs, improving SQLite transactions with extension functions, avoiding null in your code
------
What is Kotlin?
Kotlin is a modern language for the JVM, and the only officially supported language on Android beside Java. It's developed by Jetbrains, the makers of IntelliJ on which Android Studio is based.
Since Google's announcement to officially support Kotlin in 2017, interest in the language has radically increased -- and with it the number of tutorials, courses, books, and also job offers for Kotlin. It's a great time to dive into this modern language and get ahead of other Android developers!
With its modern language design that incorporates industry best practices, Kotlin allows you to write highly expressive, understandable and safe code -- while being 100% interoperable with Java. You can use any Java classes and methods from Kotlin and the other way around.
This courses shows you what language features I mean, and how you can apply them in order to write world-class code.