Kotlin is a modern, statically typed, JVM based language. Get an overview of the the major features of the language and learn about the App that will be developed during this course
- [Instructor] Kotlin, is a modern new programming language that was released in 2016. It was developed by JetBrains, maker of Android studio and IntelliJ as well as many other widely used IDEs or integrated development environments. Kotlin is a JVM, or a Java Virtual Machine language. It can be run under any JVM. This means it can run on a server, or on Android. Kotlin can be used with Java or any other JVM based language.
In fact, you don't have to completely rewrite your Android app to add new features. You can just add new Kotlin code and it will be compatible with your existing code base. Kotlin is also strongly typed which means that you need to declare a variable to be a specific type. And it cannot change. There are two variable types. Val for variables that cannot change and var for changeable variables. For example, val name string equals Thread.
This declares a variable name that is a type string, and it cannot be changed. If you did not provide the string type, it could infer the type by the string thread, and conversely, var name string equals Fred could be updated to change the value of the string to Sue. We'll get into more about variables later in this course. Kotlin shares some of its syntax with Java and if you've ever worked with Swift, you'll notice some similarities as well. Function definitions start with a key word fun.
Control statements are very similar to Java except for when. For example, if name dot length is greater than zero. Another example, val x int equals one, and no semicolons are needed. The compiler ensures that you don't mistakenly use a variable that is null. You create nullable variables by appending a question mark after the variable name. If the variable is null, making a method call will happen, and no null pointer exceptions will occur.
If you are sure your variable can't be null, you can use two exclamation points if the variable's null, then a null pointer exception will occur. So use it sparingly. You cannot use a statement like val name string without giving it a value. This is invalid. Val name string equals Fred is valid, as is var name string, question mark equals null. It's valid because it can be null. Lambdas are called function literals.
Basically anything inside of curly braces. This allows functions to be passed as parameters. For example, you can pass text view dot set text clicked as a parameter to a non click listener function that takes a class as a parameter. Using Kotlin produces less code than Java for the same functionality. If you take a look at the difference between on click listeners, you can see how much easier it is to read. You don't need to define a new anonymous class.
Kotlin knows that this only has one method. We'll discuss more about functions later. The compiler ensures that null pointer exceptions are a lot less likely. For example, the adaptor uses a question mark to state that it can be null. Later, we use the question mark to call the set has stable Id's method. Why would you want to use Kotlin? For one, you can use it anywhere you can use Java. Kotlin provides null pointer safety.
Kotlin uses lambdas for function references. Kotlin is a modern language, and uses the latest techniques. This is just a brief introduction to Kotlin. We'll be exploring Kotlin in depth throughout this course.
- Setting up Kotlin
- Converting activities from Java to Kotlin
- Creating an emulator
- Installing and adding Android libraries
- Reviewing basic Kotlin syntax
- Using variables
- Creating functions
- Retrieving images using the REST API from Pixabay
- Layering image views using a FrameLayout and a RelativeLayout
- Building the RecyclerView adapter
- Displaying a high-resolution photo of the image in the RecyclerView