Kotlin Java

Tags: Kotlin

Learn Kotlin, a modern language for the JVM (now officially supported on Android!)

Last updated 2022-01-10 | 4.6

- Solve problems in Kotlin
- Understand Kotlin's advantages over Java
- Effectively leverage Kotlin's null safety and mutability guarantees

What you'll learn

Solve problems in Kotlin
Understand Kotlin's advantages over Java
Effectively leverage Kotlin's null safety and mutability guarantees
Speed up work with collection using Kotlin's collection operationrs
Have fun with a new JVM language!

* Requirements

* A basic knowledge of Java is beneficial

Description

This is a course on the Kotlin programming language. Kotlin is a programming language made by JetBrains which targets the JVM. Kotlin is designed to be a better Java. It is more concise, safer, has better support for functional programming and is designed to speed up everyday development tasks. Kotlin also has great tool support, since it's made by the makers of IntelliJ IDEA, the world leading IDE.

This course is designed for people already familiar with Java who are looking for a more modern, expressive and powerful language for the JVM.

In this course, you will learn about:

  • How to install and run Kotlin and why toolability matters (I use IntelliJ)

  • Type inference and how it can save you a lot of time

  • Smart control flow structures that let you write more succinctly

  • Mutability options (val and var), what they mean and how to use them

  • Nullability guarantees and how they make your code more safe

  • The power of functional literals (nested functions and lambdas)

  • Powerful built-in delegation functionality

  • How to leverage Kotlin's collection operations to process data sets efficiently

...and a lot more!

This course is completely live-demo based. All the lectures are examples of real code being edited and executed using the IntelliJ IDEA Community Edition IDE.

Update: Google has just announced official support for Kotlin on Android. Congratulations to the Kotlin team!

Who this course is for:

  • Android developers wishing to learn the latest Google-approved language
  • Java developers looking for a better programming language
  • Developers looking for interesting language design ideas

Course content

9 sections • 54 lectures

Introduction Preview 05:34

A brief overview of why Kotlin is so good.

Downloading and Installing Preview 02:03

A little note about the options available for downloading and installing Kotlin.

Our First Kotlin Program Preview 03:53

Let's set up the IDE and run our first Kotlin program.

Variable Declarations Preview 06:31

Learn about the difference between val and var. Also: there is no new and no semicolons.

Type Inference Preview 01:33

Thanks to type deduction, most variable type decorations are not necessary. Woo-hoo!

Ranges Preview 08:20

Ranges of values. Self-explanatory, right?

Arrays Preview 05:59

A look at how arrays are represented and used in Kotlin.

Strings and String Interpolation Preview 06:44

Strings aren't complicated, but interpolation makes them more powerful.

Nullability Preview 08:17

Kotlin provides powerful support for dealing with nullability. Lean everything about ?, ?., ?: and !!

If Statement Preview 03:22

Yer olde if is an expression that can return values and can appear in interpolated strings.

Smart Casts Preview 02:26

Why should the IDE check if you are risking an NPE, if the compiler can do it just as well? This awesome compiler feature also takes care of type conversions and more.

For Iteration Preview 02:55

This ain't your father's for loop!

When Expression Preview 05:56

Kotlin's powerful alternative to Java's switch.

Top-Level Functions Preview 03:15

Kotlin has functions which are not inside any class. What is this, C++?!?

Return Types and Arguments Preview 04:53

Kotlin supports default argument values and calls with named arguments.

Variable-Argument Functions Preview 03:03

Call a function with any number of arguments, comma-separated-like.

Local (a.k.a. Nested or Inner) Functions Preview 04:09

Functions within functions.

Infix Functions Preview 02:45

Explains how functions such as downTo are implemented.

Lambda Functions Preview 06:17

Yay, lambdas! Oh, wait, Java has lambdas too? Yeah, but not like these!

Warning: Kotlin lambdas may or may not be cached when passed into Java event listeners. Be careful!

Higher-Order Functions Preview 03:15

Functions taking functions, but why?

Function Types with Receivers Preview 01:50

Define the context of the function's operation. Advanced topic!

Functors Preview 04:17

Give a class a magic method called invoke and call it like a function (a.k.a. functor).

Properties Preview 06:33

What, no fields? With Kotlin, forget about fields and getter/setter hell: properties take care of it all!

Extension Functions and Properties Preview 06:28

Give any type additional functionality.

Primary Constructors and Initialization Preview 03:28

Primary constructors provide an epic level of succinctness. But if you need to do more than initialize some fields, init block to the rescue!

Delegated Properties Preview 06:29

You can override the implementation of a property in an external class. But why?!?

Warning: when you reference this in a delegated property class, you are referring to that class, not the class where the delegated property is going to be used. Be careful!

Data Classes Preview 04:04

Simple, yet powerful, data classes auto-implement the basic scaffolding for you. Don't worry, you can override anything you don't like!

Singleton Preview 03:03

Kotlin lets you make Singletons with ease. It doesn't have static functions, but companion objects are a close alternative.

Companion Objects Preview 05:17

Kotlin doesn't have statics. But you can still get them, in a way.

Inheritance Preview 03:34

Learn about the override keyword, base call disambiguation, opening types and more.

Interfaces Preview 02:42

Interfaces... can contain properties as well as functions.

Class Delegation Preview 04:49

The Decorator pattern is essentially built-in in Kotlin.

Overview Preview 02:18

A discussion of Kotlin collection support and why it rocks.

API Overview and Sequence Generators Preview 05:23

Let's dig into kotlin-runtime.jar and find all the classes related to collection operations as well as sequences. We'll also learn how to make sequence generators: a useful feature that we'll use throughout this entire section.

Quantifiers (any, all, count, contains) Preview 04:59

Counting how many elements fit a predicate.

Projection (map, flatMap, associate) Preview 13:45

Mapping each element to something else.

Aggregation (fold, reduce, joinToString) Preview 17:55

Compressing a sequence to a single value.

Filtering (filter, filterNot) Preview 05:24

Keeping elements satisfying (or not) a particular predicate and throwing all others away.

Partitioning (drop & take) Preview 06:42

Splitting a sequence based on a criterion.

Grouping (groupBy) Preview 05:04

Grouping elements by a particular key.

Sorting (sortedBy, sortedWith, compareBy, thenBy) Preview 09:24

Sorting a data set by one or more of its properties.

Element Operations (first, last, single, elementAt) Preview 07:05

Operations which try to access an individual element of the collection.

Set Operations (distinct, intersect, union, subtract) Preview 06:15

Operations on algebraic sets.

Summary Preview 09:01

A summary of all the collection operations we've discussed in this section of the course.

Class Reflection Preview 06:34

Yeah, Java has reflection too, but can you tell if your object is a singleton or a companion object? Of course not. Kotlin reflection to the rescue!

Function References Preview 07:38

Learn to work with references to functions. Remember, functions are everywhere in kotlin. Got a property? Well, its getters/setters are functions. Also you get to see how to handle references to function overloads.

Property References Preview 06:59

Learn to work with property references. Remember, typical val/var declarations are properties too!

Constructor References Preview 02:51

Learn to work with references to class constructors.

Bound References Preview 06:04

Function and property references can also bind itself to an instance of the receiver.

Type Aliases Preview 07:19

Type aliases provide alternative names for existing types.

Enumerations Preview 06:35

Yes, enumerations, with abstract functions and whatnot.

Exceptions Preview 01:58

Kotlin has no checked exceptions. But try-catch is an expression.

Operator Overloads Preview 02:03

But only standard operators, none of that F#-inspired operator <#%$> magic.

Type-Safe Builders Preview 11:28

A look at how function types with receivers, together with lambda expressions, can help us make Groovy-style builders.