Kotlin in Action, Second Edition takes you from language basics to building production-quality applications that take advantage of Kotlin’s unique features. Discover how the language handles everything from statements and functions to classes and types, and the unique features that make Kotlin programming so seamless.In Kotlin in Action, Second Edition you will learn: Kotlin statements and functions, and classes and types Functional programming on the JVM The Kotlin standard library and out-of-the-box features Writing clean and idiomatic code Combining Kotlin and Java Improve code reliability with null safety Domain-specific languages Kotlin coroutines and flows Mastering the kotlinx.coroutines library Kotlin in Action, Second Edition is a complete guide to the Kotlin language written especially for readers familiar with Java or another OO language. Its authors—all core Kotlin language developers and Kotlin team members—share their unique insights, along with practical techniques and hands-on examples. This new second edition is fully updated to include the latest innovations, and it adds new chapters dedicated to coroutines, flows, and concurrency.Purchase of the print book includes a free eBook in PDF and ePub formats from Manning Publications.
This book provides a comprehensive guide to the Kotlin programming language, covering its core features, advanced concepts, and concurrent programming capabilities. It's aimed at Java developers who want to learn Kotlin and build applications on the JVM and Android.
Eager to master Kotlin and build stunning applications? Intrigued by Kotlin's unique approach to concurrency? Want to unlock the full potential of Kotlin in JVM and Android development? Then this book is your ultimate guide!
Multi-paradigm: Combines object-oriented and functional programming for flexible and elegant code.
Statically Typed: Catches errors at compile time, improving performance and reliability.
Pragmatic: Integrates seamlessly with existing Java libraries and frameworks.
Coroutines: Offers a powerful way to write asynchronous code.
Multiplatform: Supports building cross-platform applications for desktop, iOS, Android, and browser.
Performance: Faster method calls because types are resolved at compile time.
Reliability: Fewer runtime crashes due to compiler type verification.
Maintainability: Easier to understand unfamiliar code with clear type information.
Tool Support: Enables reliable refactorings and precise code completion in IDEs.
Pragmatic: Addresses common Java pain points, such as verbosity and null safety.
Concise: Reduces boilerplate code, making programs easier to read and write.
Safe: Prevents common errors like NullPointerExceptions.
Interoperable: Fully compatible with Java, allowing mixed-language projects.
Data Classes: Automatically generate methods like
toString()and
equals().
Read-Only Properties (val): Ensure immutability and data integrity.
Nullable Types (Int?): Explicitly handle potentially null values, preventing NullPointerExceptions.
Top-Level Functions: Define functions outside classes for utility operations.
Named Arguments: Improve code readability when calling functions.
String Templates: Simplify string formatting with embedded expressions.
Extension Functions: Add methods to existing classes without modifying their source code.
Higher-Order Functions: Accept functions as arguments and/or return them, enabling powerful abstractions.
Coroutines: Lightweight threads that simplify asynchronous code.
Flows: Represent asynchronous streams of data.
A: Kotlin offers improved conciseness, safety, and interoperability compared to Java. Its modern features and strong tool support enhance developer productivity and code quality.
A: Kotlin uses nullable types (e.g.,
String?) to explicitly mark variables that can be null. This forces developers to handle null cases, preventing unexpected runtime errors.
A: Kotlin Multiplatform allows you to share code between different platforms (e.g., Android, iOS, desktop). It reduces duplication and simplifies cross-platform development.
A: Yes, Kotlin is fully interoperable with Java. You can use Java libraries directly in Kotlin code and vice versa.
A: Gradle is the recommended build system for Kotlin. It offers flexible project models and excellent build performance.
Primarily focused on developers with some level of Java experience. Also suitable for developers experienced with other programming languages such as C# or JavaScript.
The idea for Kotlin was conceived at JetBrains in 2010, born out of the need for a modern, powerful, and rapidly evolving language to replace Java for internal development. Kotlin 1.0 was released more than five years after the first commit to the repository.