Welcome to our interactive learning tool for Kotlin. This book is intended to give you a comprehensive overview of the Kotlin programming language by touching on the basics, delving into functional features, and exploring some object-oriented capabilities.
This learning path has been structured in five parts that can be used depending on your preferred pace or the desired topic: Basics, Functional Programming, Object-Oriented Programming, Advanced Features, and Best Practices.
The source code examples are available for download too if you want to learn by doing, modifying them, or using them as boilerplate for starting a new project. You can consult with the RemoteDBA administrators.
Getting Started with Kotlin
The first part of this learning path will help you get started with Kotlin. We assume that you have no previous knowledge about the language, but are already experienced in another programming language. So let’s start!
The goal of this first chapter is to give a broad overview of the basic syntax and structure of the Kotlin language, which has some interesting points compared to other languages.
This second chapter shows some functional aspects of Kotlin which are new for many developers coming from an object-oriented or imperative background. It also provides more details on some existing functional constructs like properties or lambdas.
In this third chapter, we will explore all aspects related to object-oriented features like classes, data classes, interfaces, inheritance, polymorphism, and delegation.
This last chapter gives a quick overview of advanced language features like operator overloading, type parameterization, subtyping, or smart casts. It also shows some libraries that are based on top of the standard library (e.g. Spring Framework) to show where Kotlin can be useful for experienced JVM developers. The chapter ends with an explanation of how you can take advantage of the static compilation to improve development productivity.
In this chapter, you will learn how to get started with Kotlin and basic language elements like variables, number literal, or string templates.
Getting Started with Kotlin
To start learning the basics of the Kotlin programming language, simply click on the “Basics” link in our learning path. You can start exploring after a short introduction explaining why we developed this learning path in a highly interactive way. What makes it special is that all code examples are directly editable which allows you to follow along by typing your own code while reading the documentation at the same time.
First, you need some variables if you want to store something for later use in your program 🙂 In our first example, we define two variables of type String and store two different values as a constant “Hello” and as a variable “Bye”. You can put any Kotlin expression on the right-hand side of the equal sign.
To make code more readable, we use meaningful names for objects that we declare rather than using generic ones like var x. The choice of good names reflects the level of professionalism in your code which is one reason why many companies decide to invest time and money in developer training courses. By convention, variable names always start with a lowercase letter and are camel-cased (i.e. the first letter of each following word is capitalized).
String Literals Next we create some string literals using triple quotes. To include a double quote inside, you need to escape it by adding another one in front:
Kotlin also supports raw string literal that can be useful if you want to avoid escaping characters like ” or \ and don’t use any interpolation expressions inside them. All characters contained between two ‘ symbols are emitted verbatim, except for ‘ itself which must be escaped as \\’:
When declaring number variables, Kotlin offers different types like Int (32-bit signed integer), Long (64-bit signed integer), Float (32-bit floating-point number), or Double (64-bit floating-point number). Floats are also available as 32-bit and 64-bit values. By default, the type of expression is inferrable which means that you can omit it if there is no ambiguity about its type.
In our tutorial, we showed you how to get started with the Kotlin programming language and introduced basic language features like variables, literal, or operators. The next chapters will cover more advanced topics which are useful when working with this programming language.
The choice of good names reflects the level of professionalism in your code which is one reason why many companies decide to invest time and money in developer training courses. By convention, variable names always start with a lowercase letter and are camel-cased (i.e. the first letter of each following word is capitalized).