Jump to ratings and reviews
Rate this book

Java to Kotlin: A Refactoring Guidebook

Rate this book
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.

422 pages, Paperback

Published September 21, 2021

21 people are currently reading
61 people want to read

About the author

Duncan McGregor

13 books3 followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
20 (60%)
4 stars
12 (36%)
3 stars
1 (3%)
2 stars
0 (0%)
1 star
0 (0%)
Displaying 1 - 9 of 9 reviews
Profile Image for Hafiz Hussain.
89 reviews10 followers
January 13, 2022
As I started a book, I found it boring. Some early chapters demotivate me, but I decided to continue, and after some chapters, things changed, and I am amazed. There is a ton of knowledge. I found some chapters pretty difficult they need 100% attention. I had a plan to revise some chapters of this book again. Thank you, the authors, and the team for your time and effort.
1 review
December 3, 2021
When buying the book, I thought: "I'm already past that point where I need to be guided how to go from Java to Kotlin". I was sure that it was about just migrating to Kotlin, forget Java, it's crap and let's be fanboys of Kotlin. However, after first pages I actually learned about the history of Java and where the differences between Java and Kotlin come from. I've been just 6 years in the industry, and started with Java 8, so such retrospective was very valuable. The great term introduced in the book - language's grain - is the answer to most differences and was one of the "aha!" moments for me. This book is a great read for Java developers that even doesn't really want to go into Kotlin (yet), so that they see that Kotlin offers what Java has been trying to be for several years now. It articulates the strengths and reasons first, then you go on a sort-of-pair-programming session with the authors (well, unidirectional, but always), and in a very informal way, play with the code and refactor it in different ways. The authors share the reasons of each refactoring steps and explain the trade-offs. All of this is with keeping compatibility with existing Java code base in mind, because the authors realize that it's nearly impossible to do a big-bang refactoring to Kotlin.

Note: this is not a book which I would recommend as a first read about Kotlin. As the authors state themselves, they didn't mean to teach the language, but rather build on top of the basic knowledge that someone should gather somewhere else. Once you have a nice grasp of the syntax and basics, you are good to go with this book.
8 reviews1 follower
April 11, 2023
A book on Kotlin that introduced me to "The Grain of a programming language", and if the book had just been about that it, would be already worth a read.

Duncan and Nate show in small steps not only how to refactor from Java to Kotlin but also from Kotlin to better Kotlin. They are very good at explaining the why, next to the how.

Their pragmatic view on programming (languages don't HAVE to be either OO or FP, why not both?) is a refreshing break from heavily opinionated/dogmatic manifestos on how to write code.

I felt privileged getting insights into the minds of these well-traveled journeymen.

There's also a companion github repository that allows for following along in code.

Very happy to have read this in a reading group at work, because it sparked some enthusiasm for doing (current and) future projects in Kotlin; combining it with code kata's it builds confidence and a common language, much like Martin Fowler's Refactoring book.
Profile Image for Michał Olejnik.
63 reviews1 follower
July 10, 2022
This is a great piece for every Java programmer who thinks about trying out Kotlin. It doesn't cover every language feature and is by no means a replacement for the reference documentation, but it is something more important in my opinion. As rarely (if ever) in the real world there is a chance to suddenly migrate your project from one language to another, it is crucial to know how you can do such a thing incrementally and where it may bring the most value for your buck. And this book pretty much gives you just that.

I also really liked that the authors put a lot of focus not only on the language itself but also generally on best practices of software development and functional programming especially. The examples are rather simple, but they convey the message pretty well. The text is easy to read and understandable. Overall, I can truly recommend this book.
Profile Image for Viktor Malyshev.
135 reviews5 followers
May 8, 2024
Great intro book for Java Engs thinking about switching to Kotlin.
I enjoyed the start of the book more, as it explains the motivation behind Kotlin, it's idiomatic ideas, and why it provides the best dev experience.
The second part of the book is mostly examples of refactoring existing Java code to Kotlin. Which is OK, but more water than I expected. Good examples tho, but a bit boring.
Nevertheless, I think it's a great book, totally worth reading
Profile Image for Claus Polanka.
2 reviews6 followers
August 3, 2022
One of the best books on Refactoring, Object-Oriented Design and of course Java and Kotlin. A must read if you are interested in any of these topics. Highly recommended from my side.
Profile Image for Jakub Zalas.
9 reviews15 followers
June 19, 2023
Gentle and fun introduction to functional programming in Kotlin for brains used to an Object-oriented approach.
1 review
August 16, 2022
Great book. Title doesn’t make justice for it. Don’t be afraid that you are beyond the Java -> Kotlin transition. The book is so much more than that.

You will learn how to use Kotlin effectively and in a idiomatic way, leveraging it’s tools like functional programming, top level functions, extension functions etc
You will also take a peek on how to test drive your way and quite a bit of refactoring techniques.

Totally worth the read!
Displaying 1 - 9 of 9 reviews

Can't find what you're looking for?

Get help and learn more about the design.