Kotlin Fundamentals

Kotlin brings modern idioms to the Java platform and reduces the amount of code needed to develop software. This course will teach you all the aspects of the Kotlin language.
Course info
Rating
(67)
Level
Beginner
Updated
Apr 15, 2017
Duration
4h 47m
Table of contents
Course Overview
Introduction
Getting Started with Kotlin
Functions in Kotlin
Programming with Types
Companion Objects
Using High Level Functions to Simplify Your Code
Filtering and Sorting Data in Kotlin
Working with Infinite Collections
Working with Java Functional Interfaces from Kotlin
Using Kotlin’s Nullablity Constraints to Improve Code
Understand How Nullability Interacts with Your Existing Java Code
Kotlin Collection Classes
Using Higher Order Functions in Kotlin
Understand Kotlins Improved Generic Support
Description
Course info
Rating
(67)
Level
Beginner
Updated
Apr 15, 2017
Duration
4h 47m
Description

Kotlin is a new language for writing applications on the JVM. Kotlin was developed by JetBrains, the company that created IntelliJ Idea and Resharper, amongst other tools. Kotlin has recently been adopted by Gradle as the language in which their build DSL will be written. Kotlin is a more modern version of Java. It adopts functional ideas such as immutability and first-class functions, out of the box, and it is also object oriented. In this course, Kotlin Fundamentals, you'll get an in depth look at using Kotlin applications with no prior Kotlin knowledge needed. First, you'll discover how to use Kotlin for functional programming. Next, you'll explore the reification of generic types. Then, you'll get a better understanding of immutability and null checks in Kotlin. Finally, you'll wrap up the course with learning how to use higher order functions. By the end of this course, you'll know the syntax and features of Kotlin.

About the author
About the author

Kevin has spent way too many years in the software industry. Starting on PL/1 on IBM mainframes then graduating through dBase IV to Windows and eventually onto Java, .Net and now JavaScript where he finally thinks he has found a home until the next new shiny comes along.

More from the author
Kotlin: Using Coroutines
Advanced
3h 50m
Aug 10, 2018
More courses by Kevin Jones
Section Introduction Transcripts
Section Introduction Transcripts

Course Overview
Hi everyone! My name is Kevin Jones. And welcome to my course, Kotlin Fundamentals. I am a developer and owner at Rock Solid Knowledge, a software development company based in the United Kingdom. Kotlin is a newish language for writing applications on the Java virtual machine. It's regarded as a better Java than Java. This course is an in-depth look at using Kotlin to write applications. No prior Kotlin knowledge is necessary. Some of the topics we'll cover in this course include using Kotlin for functional programming, reification of generic types, understanding immutability and null checks in Kotlin, and using higher-order functions in Kotlin. By the end of this course, you'll know the syntax and features of Kotlin. Before beginning the course, you should be familiar with programming in Java. I hope you'll join me on this journey to learn Kotlin with the Kotlin Fundamentals course at Pluralsight.

Getting Started with Kotlin
Hi! My name is Kevin Jones, and this is the Getting Started with Kotlin chapter from the Kotlin Fundamental class by Pluralsight. So we think Kotlin's a better Java than Java. And in this chapter, we'll start to introduce some of the ideas that hopefully show that. So one thing Kotlin has (I'll keep emphasizing this throughout the class) is less ceremony than Java. So we don't necessarily need to declare a type when we declare variables. We don't need to declare getters and setters for example. There's no New keyword. So generally we use much less code to do the same thing. So that's one thing we'll ponder in this chapter. Something else we'll take a look at is Kotlin's exception handling, which also comes under the less ceremony umbrella. In Java, we have to declare the exceptions we throw, and we have to handle exceptions. In Kotlin, we don't need to do that. Now to interoperate with Java, you may need to do that, and Kotlin will let you. But in general, you can just handle the exceptions and throw the exceptions that you care about. We'll take a look at that towards the end of this chapter. The primary feature of this chapter, though, is to look at the language feature that Kotlin offers us. So we'll take a look at the support for immutable types. We'll take a look at string interpolation. We'll take a look at the looping constructs Kotlin has. We'll look at language expressions. So, for example, the fact that if is an expression inside Kotlin. And we'll also take a look at ranges inside Kotlin. So one thing we've seen already is that with Kotlin, we can just code. There's no need even for classes. So let's take a look at how we see that now. So in Kotlin when we write an application, we don't need to

Functions in Kotlin
Hi! My name is Kevin Jones, and this is the Functions in Kotlin chapter from the Kotlin Fundamentals class by Pluralsight. So in this chapter, we'll take a look at how we use functions and how we declare functions in Kotlin. Now this is not the functional programming part of the class. We'll cover that a little later, and there we'll cover how we pass functions around and how we can return functions from other functions. In this chapter, we'll actually take a look at how we declare and use functions. So in Java where we have static functions and we have methods and classes, what are the similar constructs in Kotlin? So we'll see throughout this chapter that functions don't need to be declared as part of a class. We can have stand-alone functions in Kotlin. So in Java, we can't have anything outside of a class definition. Sure we can have static functions, but those static functions are still part of a class definition. Functions are introduced with the fun keyword. So all functions are declared by saying fun and then the name of the function. Functions have parameters in the same way that they do in Java, but functions can have default parameters. So we can declare a function that takes three parameters, and we can give each of those parameters default values so that when we call the function, we don't need to pass anything that already has a default. You can also have named parameters in functions in Kotlin. So if you have functions with many default values or functions with many parameters, at times it's nice to be able to see what parameters you're passing to that function. And we can do that with named parameters. And, finally, Kotlin has this idea of extension functions. These are functions that we can use to extend existing types, and we'll see exactly what we mean by this later in this chapter.

Programming with Types
Hi! My name is Kevin Jones, and this is the Programming with Types chapter from the Kotlin Fundamentals class by Pluralsight. So in this chapter, we'll take a look at how we use interfaces and classes in Kotlin. In particular, we'll look at how we can define interfaces and how we can define classes. We'll take a look at how classes can implement interfaces. We'll take a look at inheritance or class inheritance. We'll take a look at how we construct classes and different types of constructors that we have. We'll also take a look at something called data classes. So the first thing we'll take a look at is interfaces and how we define them in Kotlin.

Filtering and Sorting Data in Kotlin
Hi! My name is Kevin Jones, and this is the Filtering and Sorting Data in Kotlin chapter from the Kotlin Fundamentals class by Pluralsight. In the previous chapter, we looked at the use of lambdas in Kotlin. And in this chapter, we're going to see how we can apply those lambdas to collections. We'll see I hope that there are many benefits of using this functional style of programming with collections. We'll take a look at the library functions that are offered within Kotlin such as filter and map and flatMap. And we'll see how using these library functions along with lambdas simplifies code. One thing to be aware of if you're not used to this style of programming, it kind of seems slightly odd at first. But when you do get used to it, you'll discover how powerful it is. So, firstly, we'll take a look at a couple of the essential functions that we're going to apply to collections. These are filter and map. Filter helps us transform entire collections. So using filter I can decide which part of the collections I want to work on. We use filter to filter out unwanted items from the collection. And in that sense, it's similar to a where clause in SQL. Map lets us transform a single item in a collection. So with map I can say take an item and manipulate it, or I can take the data from one item and return a different item entirely. So in that case, it's similar to a select clause in SQL. We do have something called a projection. We're taking an incoming item, and we're projecting its data onto some outgoing item. So let's take a look at some demoes, and it'll make it more obvious how filter and map work and how they work together.

Working with Infinite Collections
Hi! My name is Kevin Jones, and this is the Working with Infinite Collections chapter from the Kotlin Fundamentals class by Pluralsight. At the end of the previous chapter, we talked about the problem with lists. We said that functions such as filter and map create lists. This is fine if lists are small, but it's not good if the lists we are using to iterate over are massive. And we suggested a solution to this would be to use sequences instead. So sequences are very efficient in that they are lazily evaluated. So when we come to iterate over a sequence, no evaluation is carried out until we ask it to. And no extra memory is used while we're doing the evaluation. So to use a sequence, this is an example that was similar to one we saw previously, but rather than just doing meetings. filter. map, we can do meetings. asSequence. So that turns the list of meetings into a sequence of meetings and then allows us to iterate over that sequence. Then the return value we can work on in a similar way that we worked on previously. We can iterate over the return value and print out the data inside it for example. So let's see an example of how we do that.

Working with Java Functional Interfaces from Kotlin
Hi! My name is Kevin Jones, and this is the Working with Java Functional Interfaces from Kotlin chapter of the Kotlin Fundamentals class by Pluralsight. So in Java, we've had the idea of events for a long time. And events are typically methods that accept something of type interface where we call back methods on the passed-in interface. Java 8 introduced the idea of a functional interface, so a functional interface, also known as a SAM, or a Single Abstract Method interface, is an interface with a single method on that's abstract. And often these interfaces are used as event firers. So, for example, runnable or callable are SAM interfaces. To call methods that accepted one of these interfaces prior to Java 8, we typically passed an anonymous object. And we saw this earlier in the class. But since Java 8, we can pass lambdas where in the past we would have had to have passed an object. And Kotlin lambdas are interoperable with SAM interfaces in Java. So what we'll see in this chapter is how we pass Kotlin interfaces into Java objects and how we can use Kotlin lambdas in Java code. So let's write some code that does that.

Understand How Nullability Interacts with Your Existing Java Code
Hi! My name is Kevin Jones, and in this chapter, we'll see how nullability from Kotlin interacts with existing Java code. This is the Kotlin Fundamentals class by Pluralsight. So we see in a previous chapter that Kotlin handles null very, very well. We can declare a variable of type null. We can declare variables that either take or don't take null values. And we have various operators that let us operate on those variables, such as the safe call operator. In Java, we don't have the same facilities. So in Java, there's no way that the compiler can know whether a value can be null or not. However, we want our Kotlin code to interoperate as well as possible with the Java code. So to do that, Kotlin understands certain annotations from the Java world. In particular, it understands the @Nullable and @NotNull annotations. It understands annotations from the javax. annotation package, from the android. support. annotation package, and from the org. jetbrains. annotation package. So if you use annotations from these packages to make variables either nullable explicitly or to tell Kotlin they can't hold values of null explicitly, then Kotlin can make use of this information. So let's see how we do that. Let's see how we can use annotations in our Java codes and how that information is passed into the Kotlin code.

Kotlin Collection Classes
Hi! My name is Kevin Jones, and this is the Kotlin Collection Classes chapter from the Kotlin Fundamentals class by Pluralsight. In this chapter, we want to take a look at certain aspects of collections. In particular, we'll take a look at how collections handle null. So collections themselves can be nullable in the same way that other types can be nullable. Collections can hold null values. Collections can also be read-only or be mutable, so we can change values inside collections. Our collections have to interoperate with Java, so how do we deal with that? And, finally, Kotlin has arrays. How do we handle arrays in collections inside Kotlin?