Book Image

Kotlin Programming By Example

By : Iyanu Adelekan
Book Image

Kotlin Programming By Example

By: Iyanu Adelekan

Overview of this book

Kotlin greatly reduces the verbosity of source code. With Google having announced their support for Kotlin as a first-class language for writing Android apps, now's the time learn how to create apps from scratch with Kotlin Kotlin Programming By Example takes you through the building blocks of Kotlin, such as functions and classes. You’ll explore various features of Kotlin by building three applications of varying complexity. For a quick start to Android development, we look at building a classic game, Tetris, and elaborate on object-oriented programming in Kotlin. Our next application will be a messenger app, a level up in terms of complexity. Before moving onto the third app, we take a look at data persistent methods, helping us learn about the storage and retrieval of useful applications. Our final app is a place reviewer: a web application that will make use of the Google Maps API and Place Picker. By the end of this book, you will have gained experience of of creating and deploying Android applications using Kotlin.
Table of Contents (12 chapters)

Advantages of Kotlin

As previously discussed, Kotlin was designed to be a better Java, and as such, there are a number of advantages to using Kotlin over Java:

  • Null safety: One common occurrence in Java programs is the throwing of NullPointerException. Kotlin alleviates this issue by providing a null-safe type system.
  • Presence of extension functions: Functions can easily be added to classes defined in program files to extend their functionality in various ways. This can be done with extension functions in Kotlin.
  • Singletons: It is easy to implement the singleton pattern in Kotlin programs. The implementation of a singleton in Java takes considerably more effort than when it is done with Kotlin.
  • Data classes: When writing programs, it is a common scenario to have to create a class for the sole purpose of holding data in variables. This often leads to the writing of many lines of code for such a mundane task. Data classes in Kotlin make it extremely easy to create such classes that hold data with a single line of code.
  • Function types: Unlike Java, Kotlin has function types. This enables functions to accept other functions as parameters and the definition of functions that return functions.