Become a Better Java Developer
Improve your coding skills by comparing your code to that of expert programmers, so you can write code that’s clean, concise, and to the point: code that others will read with pleasure and reuse.
Get hands-on advice to level up your coding style through small and understandable examples that compare flawed code to an improved solution. Discover handy tips and tricks, as well as common bugs an experienced Java programmer needs to know.
Make your way from a Java novice to a decent developer.
Learn more
Become a Better Java Developer in 70 Examples
A Mentor for you
This book is a useful companion for anyone learning to write clean Java code. The authors introduce you to the fundamentals of becoming a software developer, by comparing pieces of problematic code with an improved version, to help you to develop a sense for clean code. This unique before-and-after approach teaches you to create clean Java code.
Code Cleanly
Keep your booleans in check, get rid of magic numbers, and use the right style of iteration. Comment wisely, name things accurately, handle exceptions robustly, test with JUnit 5, and write elegant functional and object-oriented code.
Become a Developer
Writing excellent code isn’t just about implementing the functionality. It’s about the small important details that make your code more readable, maintainable, flexible, robust, and faster. Java by Comparison teaches you to spot these details and trains you to become a better programmer.
- 70 Examples
- 206 Pages
- 15 Reviewers
- uncountable Cups of Coffee
Who Is This Book For?
For anyone learning to program in Java at a beginner or intermediate level, and for teachers and senior developers who coach new developers.
Before reading
- You know the Java basics: conditions, loops, classes and objects, simple algorithms, and lists, queues, stacks and maps.
- You can solve FizzBuzz in Java. That is the readiness check from the preface.
- Your code works, but you are not sure it is clean, readable, and easy to maintain.
After reading
- You spot common code smells in booleans, formatting, magic numbers, and iteration.
- You name things right, comment wisely, and handle exceptions robustly.
- You test with JUnit 5 and use a functional style and clear object-oriented design.
- You have internalized a checklist of 70 items to review your own and others' code.
Already know Effective Java and Clean Code? You will still find something new. All you need is a Java 8 compiler, a text editor, and a fresh mind. For newer Java, up to Java 25, see the free Modern Java and Java Concurrency comparisons.
What's in the book...
Welcome! (free sample)
Welcome to Java by Comparison! Get ready for code quality.
Start Cleaning Up
Learn the basics of code understandability and start cleaning your code.
Level Up Your Code Style
Get the quality of your Java code to the next stage.
Use Comments Wisely
Write meaningful comments when they're needed and avoid them when not.
Name Things Right
Find concise names for your code structures that comply to the conventions.
Prepare for Things Going Wrong
Make your program robust with clean exception handling
Assert Things Going Right
Use JUnit5 to test your code.
Design Your Objects
Apply object-oriented design principles to make your program flexible and maintainable.
Let Your Data Flow
Leverage the power of lambda expressions and functional programming in Java.
Prepare for the Real World
Use static analyis, build automation and concurrency to release your program into the wild.
Comparisons Online
Besides the table of contents of the book, we publish further before/after comparisons on the web, with code and explanations.
Java by Comparison
All 70 comparisons of the book, chapter by chapter, with page numbers and free samples.
Java Concurrency by Comparison
Protect shared mutable state and collections, step by step from unsafe to thread-safe code.
Modern Java by Comparison
New language features after Java 8, such as records, text blocks, and switch expressions.
What Happy Readers Say

Achim Weimert
CTO
I wish Java by
Comparison had been there when I was getting started with programming, It's like
a mentor, looking over your shoulder, and patiently helping you get your programming
skills up to the next level.


Dr. Guido Wirtz
Professor for Computer Science
This is the book I’ve
been waiting for since starting with intermediate Java programming courses. Without
dwelling for too long on the basics, Java by Comparison leads you step by
step to new insights on good coding practice. Instructive examples compare the do’s and
dont’s and make it easy for beginners to get the key points. Here, the book shines and
shows it’s based on long-term classroom experience. Luckily, the book can be read as a
textbook but is also useful as a reference. I’m looking forward to using it in my
classrooms. Are you sure your style is perfect? Get it!


Ashish Bhatia
Software Engineer
Java by
Comparison is a well-crafted quick read with good, succinct examples updated with
the latest Java 8 styling. Highly recommended for Java developers a few years into their
career.


Stefan Tilkov
CEO
With any language, once you’ve mastered its syntax, the next step is to learn how to use
it idiomatically. Whether you’re a beginner who has just started with Java or a seasoned
Java developer who started out using one of its many earlier versions, I consider Java
by Comparison a great step to become proficient in using Java well.


Johannes Schwalb
Java Architect
Java by
Comparison is a wonderful read for all those who want to level up their Java
skills. It contains the essence of Effective Java and Clean Code, updated with JUnit 5 and
Java 8.

Used in University Courses
The book grew out of more than six years of teaching. Today it is course literature at universities in Germany, the Netherlands, and Sweden, and the kata runs in company coding dojos.
University of Bamberg
Hochschule München
Vrije Universiteit Amsterdam
Stockholm University
Do you teach with Java by Comparison? Tell us about your course.
The Science Behind the Book: Teaching Clean Code
The before/after method was developed and evaluated in university teaching and published in peer-reviewed software engineering education workshops. Read the story of the book and the research behind it.
-
Teaching Clean Code
Describes a feedback-driven course for 2nd and 3rd year students that puts clean code ahead of mere correctness, refined over more than six years and awarded a faculty teaching award. It proposes a knowledge base of before/after examples, the idea behind this book.
-
Code Process Metrics in University Programming Education
Mines the Git repositories of 38 student teams in two Bamberg courses that use Java by Comparison in their code reviews, and analyzes how code process metrics relate to students' grades.
About the three Authors
Take a closer look into our amazing team. We won’t bite.
Dr. Simon Harrer
Co-Founder & CEO, Entropy DataSimon is a product engineer at heart who co-founded Entropy Data, a data product marketplace for humans and agents. He taught Java at the University of Bamberg for years, and his friends call him a clean code evangelist, but in a good way. simonharrer.com
Dr. Jörg Lenhard
DeveloperJörg is a developer, teacher, and researcher. He has been teaching programming in Java for almost a decade and enjoys contributing to open source software.
Dr. Linus Dietz
Lecturer, King's College LondonLinus is Lecturer (Assistant Professor) in Computer Science at King's College London. He researches data science and recommender systems and works on computer science education. linusdietz.com
Press Coverage
Reviewed in magazines, on developer portals, blogs, and podcasts, in five languages.
Java Magazine
Review by Andrew Binstock, editor in chief.
Read the reviewInfoQ
Review by Jeanne Boyarsky, also translated into Japanese.
Read the reviewheise Developer
Review by Michael Müller (German).
Read the reviewDZone
Reviews by Dustin Marx and Ken Fogel.
Read the reviewRobert C. Martin
Short review by "Uncle Bob", author of Clean Code.
Read the postairhacks.fm
Adam Bien interviews Simon Harrer on his podcast.
Listen
Show all 47 reviews and interviews
- English
- Review by Andrew Binstock in the Java magazine
- Short review by Robert C. Martin on Twitter
- Thorough review by Frank Raiser on his personal blog
- Recommended Summer Reading by Thorben Janssen on his personal blog
- Review by Alexander Schwartz on his personal blog
- Review by Philip Riecks on his personal blog
- Review by Quinn Gil on his personal blog
- Review by Vijitha Kumara on Coderanch.com
- Review by Alex Armstrong on i-programmer.info
- Interview by David Rael on the Developer On Fire podcast
- Review by Dustin Marx on DZone and published on his own blog.
- Review by Steven Schwenke on his own blog.
- Review by Jeanne Boyarsky on infoQ
- Review by Michael Hönnig on his own blog
- Review by Rick Leir on blinkmonitor.com
- Review by Gary Woodfine on his blog
- Review by Daniel Lindner on his blog
- Review by Pan Pantziarka on TechBookReport
- Review by Tom Hombergs on reflectoring.io
- Review by Dan Geabunea on his own blog
- Dylan Isreal interviews Simon Harrer on coding360 on youtube
- Review by Sylvain Leroy on his own blog
- Timothée Bourguignon interviews Simon Harrer on the Software Developer's Journey Podcast
- Review by Ken Fogel on his own blog and on DZone
- Review by Sudheer Jonna on his own blog
- Review by Alexander Radzin on his own blog
- Interview by Adam Bien on his podcast airhacks.fm
- Review by Vojtech Ruzicka on his own blog
- Review by Mateusz Palichleb on his personal blog
- Interview by David Tanzer
- Review by Naresha K on his own blog
- Review by Kasra Madadipouya on his own blog
- German
- Review by Felix Betzl on www.feki.de
- Review by Michael Müller on Heise Developer
- Michael Vitz interviews Simon Harrer on the INNOQ Podcast
- Review by Jörn Hameister on his personal blog
- Interview of Simon Harrer and Linus Dietz on Uni Bamberg Facebook Account
- Review by Stefan Macke as a blogpost and podcast!
- Review in the JAVAPRO 3/2018 magazine
- Review by Prof. Dr. Oliver Höß on his site innovative-trends.de
- Review by Johnny Graber on his personal blog
- Autoweird.fm Podcast Interview
- French
- Review by Eric Siber on his personal blog, including an interview
- Turkish
- Review by İbrahim Kürce on medium.com Part 1
- Review by İbrahim Kürce on medium.com Part 2
- Presentation about Java by Comparison by İbrahim Kürce on slideshare.net
- Japanese
- Review by Jeanne Boyarsky on infoQ, translated by H. Yoshida
Links to pages that no longer exist point to their copy in the Internet Archive.
Fun fact: Java by Comparison is one of the books in the Bartz v. Anthropic copyright settlement, the class action over books used to train Anthropic's Claude models. In a way, its comparisons live on in Anthropic's frontier models.
Awards
Translations and Libraries
Korean edition
자바 코딩의 기술, published by Gilbut in 2020, translated by 심지현.
All editions and translationsIn university libraries
HTW Berlin, HU Berlin, TH Hamburg, TH Köln, TH Nürnberg, TU Darmstadt, TU München, Uni Bamberg, Uni Bayreuth, Uni Dresden, Uni Erlangen, Uni Hamburg, Uni Passau, Uni Stuttgart, Uni Weimar, Uni Würzburg, and more.
Talks and Events
Upcoming
No talks are scheduled right now. Want a talk or the kata workshop at your meetup, conference, or company? Get in touch.
Past
Most talks were in German; the slides of the OTH Regensburg guest lecture are in English.
- HUK-COBURG, Coburg
· Slides (PDF) - JavaLand 2023, Phantasialand, Brühl
· Slides (PDF) - OTH Regensburg (Ostbayerische Technische Hochschule)
- JUG Darmstadt (online)
· Video · Slides (PDF) - JUG Hamburg
· Slides (PDF)
Show all 17 talks
- JUG Mainz, Hochschule Mainz
· Slides (PDF) - Softwerkskammer Köln, at REWE Digital
- Softwerkskammer Nürnberg
· Slides (PDF) - Lightweight Java User Group München
- WIAI PraxisReport, University of Bamberg
- DWX Developer Week 2019, Messe Nürnberg
- Softwerkskammer Leipzig
- Softwerkskammer Düsseldorf
- Softwerkskammer Ruhrgebiet
· Video (German) · Slides (PDF) - BMW Group coding dojo, München
- Hackerkegeln (DATEV SCC), Nürnberg
- devcamp
· Slides (PDF)
Frequently Asked Questions
What is Java by Comparison?
Java by Comparison: Become a Java Craftsman in 70 Examples is a book by Simon Harrer, Jörg Lenhard, and Linus Dietz, published by The Pragmatic Bookshelf in 2018. Each of its 70 items compares a piece of flawed Java code with an improved version and explains the difference.
Who should read Java by Comparison?
Developers learning Java at a beginner or intermediate level who already know the basics such as conditions, loops, classes, and collections. Teachers and senior developers use it as a reference when reviewing code of students and junior developers.
What topics does the book cover?
Booleans and conditions, formatting, magic numbers, iteration, comments, naming, exception handling, testing with JUnit 5, functional programming with lambdas and streams, object-oriented design, and preparing code for the real world with static analysis, build automation, and concurrency.
How is it different from Clean Code or Effective Java?
It is shorter and example-driven: every item shows a concrete piece of code before and after the improvement, so you can apply it right away. Readers who already know Clean Code and Effective Java still find new items.
Which Java version does the book use?
The examples need a Java 8 compiler and use lambdas, streams, and JUnit 5. The advice applies to newer Java versions as well.
Where can I buy it?
As an e-book (PDF, EPUB, MOBI) and paperback from The Pragmatic Bookshelf, and as a paperback on Amazon in the US, UK, and Germany. A Korean translation was published by Gilbut in 2020.
Is there a free sample?
Yes. The preface and three complete items are free PDFs: Return Boolean Expressions Directly, Document Using Examples, and Split Method with Boolean Parameters. They are linked in the table of contents on this page.