Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Kotlin Programming Cookbook

You're reading from   Kotlin Programming Cookbook Explore more than 100 recipes that show how to build robust mobile and web applications with Kotlin, Spring Boot, and Android

Arrow left icon
Product type Paperback
Published in Jan 2018
Publisher
ISBN-13 9781788472142
Length 434 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Aanand Shekhar Roy Aanand Shekhar Roy
Author Profile Icon Aanand Shekhar Roy
Aanand Shekhar Roy
Rashi Karanpuria Rashi Karanpuria
Author Profile Icon Rashi Karanpuria
Rashi Karanpuria
Arrow right icon
View More author details
Toc

Table of Contents (21) Chapters Close

Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
1. Installation and Working with Environment FREE CHAPTER 2. Control Flow 3. Classes and Objects 4. Functions 5. Object-Oriented Programming 6. Collections Framework 7. Handling File Operations in Kotlin 8. Anko Commons and Extension Function 9. Anko Layouts 10. Databases and Dependency Injection 11. Networking and Concurrency 12. Lambdas and Delegates 13. Testing 14. Web Services with Kotlin 1. Other Books You May Enjoy Index

Preface

Kotlin Cookbook will be a go-to guide to problems new Kotlin developers get stuck with. Along with that, Kotlin Cookbook will also help developers learn handy tricks and concepts that they may need while coding. This book will also help developers uncover the full potential of an amazing programming language, that is, Kotlin.

The book starts with an overview of Kotlin and moves on to some great simple concepts and features that Kotlin offers. From there, it will move on to OOP fundamentals and creating simple Android applications. Next will be the recipes for more complicated concepts such as networking, database, architectures, file io, and testing. It will also cover some great features of Anko that really eases out some complicated concepts in Android development, making it faster and more fun. Last will be some miscellaneous but extremely useful recipes that developers might need from time to time.

Who this book is for

This book is targeted at Kotlin beginners who know Android and Java Development and who have a good knowledge level and understanding of the Android development cycle. The readers are familiar with the concepts of Android development and understand the needs of testing their code. They want to learn efficient Kotlin techniques in order to make the existing Android development process more efficient and fun. This is not an introductory book for Kotlin, and it assumes basic familiarity with Kotlin. This book aims at helping developers solve issues they are stuck with while working with Kotlin.

What this book covers

Chapter 1, Installation and Working with Environment, walks you through starting with a Kotlin project. We will also introduce you to the Gradle build system and help you in setting up your development environment.

Chapter 2, Control Flow, includes recipes for control flow in Kotlin. Kotlin has brought a lot of power to old control flows, as you can now use them as an expression. Kotlin has also introduced a powerful "when", which is basically Java’s "switch" improvements.

Chapter 3, Classes and Objects, says that classes and objects are inevitable parts of object-oriented programming. This chapter will include the solutions and examples of real-world problems faced by developers and how Kotlin solves it. This chapter will also lay the foundation to the upcoming chapter OOPS programming with Kotlin.

Chapter 4, Functions, informs that functions are inevitable parts of object-oriented programming. This chapter will include the solutions and examples of real-world problems faced by developers and how Kotlin solves it.

Chapter 5, Object-Oriented Programming, builds upon the learning of Chapter 3Classes and Objects, and will include recipes that help in OOP.

Chapter 6, Collections Framework, presents the recipes that will explore the full potential of Collection framework in Kotlin.

Chapter 7, Handling File Operations in Kotlin, covers recipes about basic I/O and File I/O.

Chapter 8, Anko Commons and Extension Function, contains recipes on how to use the Anko library of Kotlin for efficient and quick Android development.

Chapter 9, Anko Layouts, has recipes on how to use the Anko library of Kotlin for efficient and quick Android development.

Chapter 10, Databases and Dependency Injection, dives into recipes to work with SQLite databases in Android.

Chapter 11, Networking and Concurrency, discusses recipes that will help developers make network calls and fetch data over a network.

Chapter 12, Lambdas and Delegates, uncovers some of the best (and difficult) features of Kotlin, that is, Lambdas and Delegates. This contains recipes to help the developers get started with them.

Chapter 13, Testing, outlines concepts on writing tests in Kotlin while touching Unit tests, integration tests, instrumentation, and acceptance tests.

Chapter 14, Web Services with Kotlin, helps developers write web services using Kotlin language.

To get the most out of this book

This book assumes familiarity with Java and Android development. This is not an introductory book for learning Kotlin. Readers must have used Android studio because many of the recipes will be focused toward Android development.

Download the example code files

You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packtpub.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitLab at https://gitlab.com/users/aanandshekharroy/projects. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

 

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "The corresponding sourceSets property should be updated if not using the default convention."

A block of code is set as follows:

sourceSets {
   main.kotlin.srcDirs += 'src/main/myKotlin'
   main.java.srcDirs += 'src/main/myJava'
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

sourceSets {
   main.java.srcDirs += 'src/main/kotlin/'
}

Any command-line input or output is written as follows:

$ kotlinc hello.kt -include-runtime -d hello.jar.
$ java -jar hello.jar

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "In the Select Deployment Target window, select your device, and click on OK."

Note

Warnings or important notes appear like this.

Note

Tips and tricks appear like this.

Sections

In this book, you will find several headings that appear frequently (Getting ready, How to do it..., How it works..., There's more..., and See also).

To give clear instructions on how to complete a recipe, use these sections as follows:

Getting ready

This section tells you what to expect in the recipe and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make you more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

Get in touch

Feedback from our readers is always welcome.

General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime
Visually different images