Learn Kotlin Programming
Second Edition
A comprehensive guide to OOP, functions, concurrency, and coroutines in Kotlin 1.3
Stephen Samuel
Stefan Bocutiu
BIRMINGHAM - MUMBAI
Learn Kotlin ProgrammingSecond Edition
Copyright 2019 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Richa Tripathi
Acquisition Editor: Denim Pinto
Content Development Editor: Manjusha Mantri
Technical Editor: Mayank Dubey
Copy Editor: Safis Editing
Project Coordinator: Prajakta Naik
Proofreader: Safis Editing
Indexer: Tejal Daruwale Soni
Graphics: Jisha Chirayil
Production Coordinator: Nilesh Mohite
First published: Feb 2017
Second edition: May 2019
Production reference: 1270519
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78980-235-1
www.packtpub.com
mapt.io
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
Packt.com
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at customercare@packtpub.com for more details.
At www.packt.com , you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Contributors
About the authors
Stephen Samuel is an accomplished developer with over 17 years of experience. He has worked with Java throughout his career, and in the past five years has focused on Scala. He has a passion for concurrency and big data technologies. Having spent the last few years in investment banking, he is currently working with Kotlin on a major big data investment project. Stephen is also active in the open source community, being the author of several high-profile Scala and Kotlin libraries
Stefan Bocutiu is a big data consultant with over 13 years of experience in software development. He enjoys coding in Scala and C#, and has a passion for stream processing technologies. With the team at DataMountaineer, he focuses on providing scalable, unified, real-time data pipelines to allow reactive decision making, analytics, and Hadoop integration.
Stefan is passionate about motorsports, and while his racing skills are not good enough to allow him to compete, he tries to attend as many MotoGP races as possible. When he is not coding, he can be found at the climbing wall or at the gym. Occasionally, hiking and scrambling trips are on his calendar, and during the winter season, skiing trips are a must for him .
About the reviewers
Ehsun Behravesh is a senior software engineer employed by Atlassian. He fell in love with computer programming when he was 15. Ehsun is holding a master's degree in computer science, and he has worked as a software engineer in five countries.
I would like to express special thanks to my wife, who has been living with me with love and patience. Secondly, I would also like to thank my parents, who helped me a lot in becoming a programmer.
Rivu Chakraborty is a speaker, author, community contributor, Google-certified Android developer, and Caster.io instructor. He has over seven years of professional experience, and is currently working as a senior software engineer (Android) at BYJU'S The Learning App. Rivu considers himself a Kotlin and Android enthusiast-cum-evangelist. He has been using Kotlin since December 2015. Rivu created the Kotlin Kolkata User Group, and before moving out to Bangalore, he had been the lead organizer for both the Kotlin Kolkata User Group and GDG Kolkata. Along with organizing events, he also speaks at local events and conferences all over India, including DroidJam India and DevFests. Rivu has authored multiple books on Kotlin and Android development.
Packt is searching for authors like you
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Preface
Kotlin is typically associated with Android development, and most discussions surrounding it gravitate around this. However, the language has much more to offer and is ideal for modern server-side developers. While any Android developer will find useful snippets in this book, it is primarily aimed at Java and Scala developers. The book starts with an introduction to Kotlin and explains how you set up your environment before moving on to the basic concepts. Once the basics are out of the way, the focus shifts toward more advanced concepts, and don't be surprised if you see a few bytecode listings. Once you have completed the book, you should have all the knowledge required to start using Kotlin for your next project.
Who this book is for
This book is aimed at those who have little or no Kotlin experience and who wish to learn the language quickly. The focus of the book is on server-side development in Kotlin, and would be best suited to a developer who is currently a server-side developer, or who wishes to learn. No prior knowledge of functional or object-orientated programming is required, but knowledge of another programming language is recommended.
Next page