Book description
Use Kotlin to build Android apps, web applications, and more—while you learn the nuances of this popular language. With this unique cookbook, developers will learn how to apply thisJava-based language to their own projects. Both experienced programmers and those new to Kotlin will benefit from the practical recipes in this book.
Author Ken Kousen (Modern Java Recipes) shows you how to solve problems with Kotlin by concentrating on your own use cases rather than on basic syntax. You provide the contextand this book supplies the answers. Already big in Android development, Kotlin can be used anywhere Java is applied, as well as for iOS development, native applications, JavaScriptgeneration, and more. Jump in and build meaningful projects with Kotlin today.
- Apply functional programming concepts, including lambdas, sequences, and concurrency
- See how to use delegates, late initialization, and scope functions
- Explore Java interoperability and access Java libraries using Kotlin
- Add your own extension functions
- Use helpful libraries such as JUnit 5
- Get practical advice for working with specific frameworks, like Android and Spring
Publisher resources
Table of contents
- Foreword
- Preface
-
1. Installing and Running Kotlin
- 1.1. Running Kotlin Without a Local Compiler
- 1.2. Installing Kotlin Locally
- 1.3. Compiling and Running Kotlin from the Command Line
- 1.4. Using the Kotlin REPL
- 1.5. Executing a Kotlin Script
- 1.6. Building a Standalone Application Using GraalVM
- 1.7. Adding the Kotlin Plug-in for Gradle (Groovy Syntax)
- 1.8. Adding the Kotlin Plug-in for Gradle (Kotlin Syntax)
- 1.9. Using Gradle to Build Kotlin Projects
- 1.10. Using Maven with Kotlin
-
2. Basic Kotlin
- 2.1. Using Nullable Types in Kotlin
- 2.2. Adding Nullability Indicators to Java
- 2.3. Adding Overloaded Methods for Java
- 2.4. Converting Between Types Explicitly
- 2.5. Printing to Different Bases
- 2.6. Raising a Number to a Power
- 2.7. Using Bitwise Shift Operators
- 2.8. Using Bitwise Boolean Operators
- 2.9. Creating Pair Instances with to
-
3. Object-Oriented Programming in Kotlin
- 3.1. Understanding the Difference Between const and val
- 3.2. Creating Custom Getters and Setters
- 3.3. Defining Data Classes
- 3.4. The Backing Property Technique
- 3.5. Overloading Operators
- 3.6. Using lateinit for Delayed Initialization
- 3.7. Using Safe Casting, Reference Equality, and Elvis to Override equals
- 3.8. Creating a Singleton
- 3.9. Much Ado About Nothing
- 4. Functional Programming
-
5. Collections
- 5.1. Working with Arrays
- 5.2. Creating Collections
- 5.3. Creating Read-Only Views from Existing Collections
- 5.4. Building a Map from a Collection
- 5.5. Returning a Default When a Collection Is Empty
- 5.6. Restricting a Value to a Given Range
- 5.7. Processing a Window on a Collection
- 5.8. Destructuring Lists
- 5.9. Sorting by Multiple Properties
- 5.10. Defining Your Own Iterator
- 5.11. Filtering a Collection by Type
- 5.12. Making a Range into a Progression
- 6. Sequences
- 7. Scope Functions
- 8. Kotlin Delegates
- 9. Testing
- 10. Input/Output
-
11. Miscellaneous
- 11.1. Working with the Kotlin Version
- 11.2. Executing a Lambda Repeatedly
- 11.3. Forcing when to Be Exhaustive
- 11.4. Using the replace Function with Regular Expressions
- 11.5. Converting to Binary String and Back
- 11.6. Making a Class Executable
- 11.7. Measuring Elapsed Time
- 11.8. Starting Threads
- 11.9. Forcing Completion with TODO
- 11.10. Understanding the Random Behavior of Random
- 11.11. Using Special Characters in Function Names
- 11.12. Telling Java About Exceptions
- 12. The Spring Framework
- 13. Coroutines and Structured Concurrency
- Index
Product information
- Title: Kotlin Cookbook
- Author(s):
- Release date: November 2019
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781492046639
You might also like
book
Mastering Kotlin
Explore popular language features, Java to Kotlin interoperability, advanced topics, and practical applications by building a …
book
Kotlin in Action
Kotlin in Action guides experienced Java developers from the language basics of Kotlin all the way …
video
Advanced Kotlin Programming
Designed for developers who already have a basic understanding of Kotlin, this video course examines some …
book
Programming Kotlin
Programmers don't just use Kotlin, they love it. Even Google has adopted it as a first-class …