It takes a week to travel the 8,000 miles overland from Java to Kotlin. If you're an experienced Java developer who has tried the Kotlin language, you were probably productive in about the same time.
You'll have found that they do things differently in Kotlin, though. Nullability is important, collections are different, and classes are final by default. Kotlin is more functional, but what does that mean, and how should it change the way that you program? And what about all that Java code that you still have to support?
Your tour guides Duncan and Nat first made the trip in 2015, and they've since helped many teams and individuals follow in their footsteps. Travel with them as they break the route down into legs like Optional to Nullable, Beans to Values, and Open to Sealed Classes. Each explains a key concept and then shows how to refactor production Java to idiomatic Kotlin, gradually and safely, while maintaining interoperability.
The resulting code is simpler, more expressive, and easier to change. By the end of the journey, you'll be confident in refactoring Java to Kotlin, writing Kotlin from scratch, and managing a mixed language codebase as it evolves over time.
Table of contents
- The Grain of a Programming Language
- An Opinionated History of Java Programming Style
- The Grain of Kotlin
- Refactoring to Kotlin
- What Are We Working On?
- Let’s Get Started!
- 2. Java to Kotlin Projects
- 3. Java to Kotlin Classes
- 4. Optional to Nullable
- 5. Beans to Values
- 6. Java to Kotlin Collections
- 7. Actions to Calculations
- 8. Static Methods to Top-Level Functions
- 9. Multi- to Single-Expression Functions
- 10. Functions to Extension Functions
- 11. Methods to Properties
- 12. Functions to Operators
- 13. Streams to Iterables to Sequences
- 14. Accumulating Objects to Transformations
- 15. Encapsulated Collections to Type Aliases
- 16. Interfaces to Functions
- 17. Mocks to Maps
- 18. Open to Sealed Classes
19. Throwing to Returning
- Error Handling Before Exceptions
- Error Handling with Exceptions
- Java and Checked Exceptions
- Kotlin and Exceptions
- Beyond Exceptions: Functional Error Handling
- Error Handling in Kotlin
- Refactoring Exceptions to Errors
- More Fixup
- Moving On
- 20. Performing I/O to Passing Data
- 21. Exceptions to Values
- 22. Classes to Functions
- 23. Continuing the Journey
- Title: Java to Kotlin
- Release date: August 2021
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781492082279
You might also like
Clean Code: A Handbook of Agile Software Craftsmanship
Even bad code can function. But if code isn't clean, it can bring a development organization …
40 Algorithms Every Programmer Should Know
Learn algorithms for solving classic computer science problems with this concise guide covering everything from fundamental …
Building Microservices, 2nd Edition
Distributed systems have become more fine-grained as organizations shift from code-heavy monolithic applications to smaller, self-contained …
Head First Design Patterns, 2nd Edition
You know you don’t want to reinvent the wheel, so you look to design patterns—the lessons …