Previous Next

Kotlin In-Depth A Guide to a Multipurpose Programming Language for Server-Side, Front-End, Android, and Multiplatform Mobile (Aleksei Sedunov) (z-library.sk, 1lib.sk, z-lib.sk)

Author: Aleksei Sedunov

移动

The book ‘Kotlin In-Depth, Second Edition’ updates all the essential parts of Kotlin and incorporates modern principles, methodologies, and approaches for achieving efficient solutions. The book will guide you to successfully utilize Kotlin in developing JVM apps for desktop, mobile, web platforms and transferring existing Java codebases to Kotlin. The book begins with an introduction to the language and its environment, which will help you to grasp the fundamental concepts underlying Kotlin's design. The readers will learn the Kotlin tooling and the language's core syntax and structures. The book teaches Kotlin's multi-paradigm nature, which enables the creation of powerful abstractions by mixing parts of functional and object-oriented programming. This book discusses how to use standard Kotlin APIs like the standard library, reflection, and coroutine-based concurrency, as well as how to create your flexible APIs using domain-specific languages. The book demonstrates how to use Kotlin for more specific tasks such as testing, developing Android applications, developing Web applications, and developing microservices. After reading this book, you'll be prepared to dive deeper into the Kotlin ecosystem's more specialized areas, including Android applications, server-side development, native programming, and code sharing across different platforms.

📄 File Format: PDF
💾 File Size: 6.4 MB
7
Views
0
Downloads
0.00
Total Donations

📄 Text Preview (First 20 pages)

ℹ️

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

📄 Page 1
(This page has no text content)
📄 Page 2
(This page has no text content)
📄 Page 3
Kotlin In-Depth A Guide to a Multipurpose Programming Language for Server-Side, Front-End, Android, and Multiplatform Mobile Aleksei Sedunov www.bpbonline.com
📄 Page 4
FIRST EDITION 2022 Copyright © BPB Publications, India ISBN: 978-93-91030-63-6 All Rights Reserved. No part of this publication may be reproduced, distributed or transmitted in any form or by any means or stored in a database or retrieval system, without the prior written permission of the publisher with the exception to the program listings which may be entered, stored and executed in a computer system, but they can not be reproduced by the means of publication, photocopy, recording, or by any electronic and mechanical means. LIMITS OF LIABILITY AND DISCLAIMER OF WARRANTY The information contained in this book is true to correct and the best of author’s and publisher’s knowledge. The author has made every effort to ensure the accuracy of these publications, but publisher cannot be held responsible for any loss or damage arising from any information in this book. All trademarks referred to in the book are acknowledged as properties of their respective owners but BPB Publications cannot guarantee the accuracy of this information. www.bpbonline.com
📄 Page 5
Dedicated to Tatiana, my guiding light and the incessant source of inspiration
📄 Page 6
About the Author Aleksei Sedunov has been working as a Java developer since 2008. After joining JetBrains in 2012, he’s been actively participating in the Kotlin language development focusing on IDE tooling for the IntelliJ platform. Currently, he’s working in a DataGrip team, a JetBrains Database IDE, carrying on with using Kotlin as the main development tool.
📄 Page 7
About the Reviewers Sanjay Kakadiya is currently working as a Sr Software developer of the e- commerce Android app. He completed his Bachelor of Engineering in IT from Gujarat University in 2012 and has more than 9 years of experience in mobile application development using Java, React Native, and Kotlin. He has been a co-organizer of the Ahmedabad Web and Mobile Developers Meetup group since 2015. He is a Kotlin and Java addict. He is obsessed with the elegant and functional style code. He mainly focuses on the mobile apps architecture. Sanjay has created and improvised dozens of successful applications for clients in areas of social networking, education, video streaming, entertainment, self-help, fitness, lifestyle, and commerce. Touhidul Islam is currently working as a mobile engineer at Toptal. He has a good grasp at data structure and algorithms and an eye for better architecture. Although, he has professional software experience in both cross-platform mobile and back-end technologies, he shines on native Android development. He has hands-on experience working at startups from his early career and one of the software developed by him earns about 40% of the revenue for that company. He later joined a big tech company developing pixel-perfect customer-facing mobile software and led the development there. He is currently working with Australia’s one of the leading service provider companies to revolutionize how people interact with service providers.
📄 Page 8
Acknowledgements Above all others, I would like to give my gratitude to the entire Kotlin team at JetBrains which has created such a beautiful language and continues to relentlessly work on its improvement – especially Andrey Breslav who’s been leading the language design from the very first day. I’m really grateful to everyone at BPB Publications for giving me this splendid opportunity for writing this book and lending a tremendous support in improving the text before it gets to the readers. Many thanks to Sanjay Kakadiya and Touhidul Islam for their great help as technical reviewers for the second edition. Last but not least, I’d like to thank my beloved family for their support throughout the work on the book.
📄 Page 9
Preface Since its first release in 2016 (and even long before that), Kotlin has been gaining popularity as a powerful and flexible tool in a multitude of development tasks being equally well-equipped for dealing with mobile, desktop, and server-side applications and finally, getting its official acknowledgment from Google in 2017 and 2018 as a primary language for Android development. This popularity is well-justified since language pragmatism, the tendency to choose the best practice among known solutions was one of the guiding principles of its design. With the book you’re holding in your hands, I’d like to invite you to the beautiful world of Kotlin programming where you can see its benefits for yourself. After completing this book, you’ll have all the necessary knowledge to write in Kotlin on your own. The first volume deals with the fundamentals of Kotlin language such as its basic syntax, procedural, object-oriented, and functional programming aspects as well as the Kotlin Standard Library. The book is divided into 9 chapters as follows: Chapter 1 explains key ideas behind the language design, gives an overview of the Kotlin ecosystem and tooling, and guides the reader through the first steps required to set up a Kotlin project in various environments. Chapter 2 introduces the reader to the Kotlin syntax, explains how to use variables, and describes simple data types such as integers or Boolean values as well as their built-in operations. It also addresses the basics of more complex data structures such as strings and arrays. Chapter 3 discusses the syntax of Kotlin functions and explains the uses of various control structures supported by Kotlin such as binary/multiple choice, iteration, and error handling. Additionally, it addresses the matter of using packages for code structuring. Chapter 4 introduces the reader to the basic aspects of object-oriented programming in Kotlin. It explains how to create and initialize a class instance and how to control member access, describe the use of object
📄 Page 10
declarations and non-trivial kinds of properties, and brings up the concept of type nullability. Chapter 5 explains the functional aspects of Kotlin and introduces the reader to the idea of higher-order and anonymous functions, addresses the uses of inline functions, and explains how one can add features to existing types using extension functions and properties. Chapter 6 explains the use of special kinds of classes tailored at specific programming tasks: data classes for simple data holders, enumerations for representing a fixed set of instances, and inline classes for creating lightweight wrappers. Chapter 7 explores object-oriented features introduced in Chapters 4 and 6 focusing on the idea of a class hierarchy. It explains how to define subclasses, how to use abstract classes and interfaces, and how to restrict hierarchies using sealed classes. Chapter 8 describes a major part of the Kotlin standard library which is concerned with various collection types and their operations as well as utilities simplifying file access and stream-based I/O. Chapter 9 introduces the idea of generic declarations and explains how to define and use generic classes, functions, and properties in Kotlin. It also explains the notion of variance and how it can be used to improve flexibility of your generic code. The second volume introduces you to the more advanced Kotlin features such as reflection, domain-specific languages and coroutines, discusses Java/Kotlin interoperability issues, and explains how Kotlin can be used in various development areas, including testing, Android applications, and Web. It’s divided into the following 8 chapters: Chapter 10 addresses the use of annotations which allow you to accompany the Kotlin code with various metadata and explains the basics of Reflection API which provides access to runtime representation of Kotlin declarations. Chapter 11 describes some advanced features which help developer in composing flexible APIs in the form of the domain-specific languages: operator overloading, delegated properties, and builder-style DSLs based on the higher-order functions.
📄 Page 11
Chapter 12 discusses common issues of combining Java and Kotlin code within the same codebase and explains the specifics of using Java declarations in Kotlin code and vice versa. Chapter 13 introduces the reader to the Kotlin coroutines library which introduces a set of building blocks for programming asynchronous computations. Additionally, it describes some utilities simplifying the use of Java concurrency API in Kotlin code. Chapter 14 discusses the KotlinTest, a popular testing framework aimed specifically at the Kotlin developers. It describes various specification styles, explains the use of assertion API, and addresses more advanced issues like using fixtures and test configurations. Chapter 15 serves as an introduction to using Kotlin for development on the Android platform. It guides the reader through setting up an Android Studio project and explains basic aspects of Android development using an example of a simple calculator application. Chapter 16 explains the basic features of the Ktor framework aimed at development of connected applications which make heavy use of Kotlin features and asynchronous computations. Chapter 17 describes how to build a microservice application using Spring Boot and Ktor frameworks.
📄 Page 12
Code Bundle and Coloured Images Please follow the link to download the Code Bundle and the Coloured Images of the book: https://rebrand.ly/04dc29 The code bundle for the book is also hosted on GitHub at https://github.com/bpbpublications/Kotlin-In-Depth. In case there's an update to the code, it will be updated on the existing GitHub repository. We have code bundles from our rich catalogue of books and videos available at https://github.com/bpbpublications. Check them out! Errata We take immense pride in our work at BPB Publications and follow best practices to ensure the accuracy of our content to provide with an indulging reading experience to our subscribers. Our readers are our mirrors, and we use their inputs to reflect and improve upon human errors, if any, that may have occurred during the publishing processes involved. To let us maintain the quality and help us reach out to any readers who might be having difficulties due to any unforeseen errors, please write to us at : errata@bpbonline.com Your support, suggestions and feedbacks are highly appreciated by the BPB Publications’ Family. Did you know that BPB offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.bpbonline.com and as a print book
📄 Page 13
customer, you are entitled to a discount on the eBook copy. Get in touch with us at: business@bpbonline.com for more details. At www.bpbonline.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 BPB books and eBooks.
📄 Page 14
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 business@bpbonline.com 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 www.bpbonline.com. We have worked with thousands of developers and tech professionals, just like you, to help them share their insights 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. 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 BPB can understand what you think about our products, and our authors can see your feedback on their book. Thank you! For more information about BPB, please visit www.bpbonline.com.
📄 Page 15
Table of Contents 1. Kotlin - Powerful and Pragmatic Structure Objectives What is Kotlin? Safe Multiparadigm Concise and expressive Interoperable Multiplatform Kotlin ecosystem Coroutines Testing frameworks Android development Web development Desktop applications Getting started with Kotlin Setting up an IntelliJ project Using REPL Interactive editors Setting up an Eclipse project Conclusion Points to remember Questions 2. Language Fundamentals Structure Objectives Basic syntax Comments Defining a variable Identifiers Mutable variables
📄 Page 16
Expressions and operators Primitive types Integer types Floating-point types Arithmetic operations Bitwise operations Char type Numeric conversions Boolean type and logical operations Comparison and equality Strings String templates Basic string operations Arrays Constructing an array Using arrays Conclusion Points to remember Multiple choice questions Answers Questions 3. Defining Functions Structure Objective Functions Function anatomy Trailing commas Positional vs named arguments Overloading and default values Varargs Function scope and visibility Packages and imports Packages and directory structure Using import directives Conditionals Making decisions with if statements
📄 Page 17
Ranges, progressions, and in operation when statements and multiple choice Loops while/do-while loop Iterables and for loop Changing loop control-flow: break and continue Nested loops and labels Tail-recursive functions Exception handling Throwing an exception Handling errors with try statements Conclusion Points to remember Multiple choice questions Answers Questions Key terms 4. Working with Classes and Objects Structure Objectives Defining a class A class anatomy Constructors Member visibility Nested classes Local classes Nullability Nullable types Nullability and smart casts Not-null assertion operator Safe call operator Elvis operator Properties: Beyond simple variables Top-level properties Late initialization Using custom accessors
📄 Page 18
Lazy properties and delegates Objects and companions Object declarations Companion objects Object expressions Conclusion Points to remember Multiple choice questions Answers Questions Key terms 5. Leveraging Advanced Functions and Functional Programming Structure Objective Functional programming in Kotlin Higher-order functions Functional types Lambdas and anonymous functions Callable references Inline functions and properties Non-local control flow Extensions Extension functions Extension properties Companion extensions Lambdas and functional types with the receiver Callable references with receiver Scope functions run / with run without context let apply / also Extensions as class members Conclusion Points to remember Questions
📄 Page 19
Key terms 6. Using Special-Case Classes Structure Objective Enum classes Exhaustive when expressions Declaring enums with custom members Using common members of enum classes Data classes Data classes and their operations Destructuring declarations Inline classes Defining an inline class Unsigned integers Conclusion Points to remember Questions Key terms 7. Exploring Collections and I/O Structure Objective Collections Collection types Iterables Collections, lists, and sets Sequences Maps Comparables and comparators Creating a collection Basic operations Accessing collection elements Collective conditions Aggregation Filtering Transformation
📄 Page 20
Extracting subcollections Ordering Files and I/O streams Stream utilities Creating streams URL utilities Accessing file content File system utilities Conclusion Points to remember Multiple choice questions Answers Questions 8. Understanding Class Hierarchies Structure Objective Inheritance Declaring a subclass Subclass initialization Type Checking and Casts Common methods Abstract classes and interfaces Abstract classes and members Interfaces Sealed classes Delegation Conclusion Points to remember Multiple choice questions Answers Questions 9. Generics Structure Objective Type parameters
The above is a preview of the first 20 pages. Register to read the complete e-book.

💝 Support Author

0.00
Total Amount (¥)
0
Donation Count

Login to support the author

Login Now

Recommended for You

Loading recommended books...
Failed to load, please try again later
Back to List