In this chapter, you’ll learn the basics of the Kotlin language required to write your first working Kotlin programs. These include basic building blocks that you encounter all throughout Kotlin programs, like variables and functions. You’ll also get acquainted with different ways of representing data in Kotlin via enums as well as classes and their properties.
The control structures you’ll learn throughout this chapter will give you the tools needed to use conditional logic in your programs as well as iterate using loops. You will also learn what makes these constructs special compared to other languages, like Java.
We’ll also introduce the basic mechanics of types in Kotlin, starting with the concept of a smart cast, an operation that combines a type check and a cast into one operation. You’ll see how this helps you remove redundancy from your code without sacrificing safety. We’ll also briefly talk about exception handling and Kotlin’s philosophy behind it. By the end of this chapter, you’ll already be able to combine these basic bits and pieces of the Kotlin language to write your own working Kotlin code, even if it might not be the most idiomatic.