Java By Comparison: Become a Java Craftsman in 70 Examples 1st Edition, Kindle Edition
Use the Amazon App to scan ISBNs and compare prices.
The Amazon Book Review
Book recommendations, author interviews, editors' picks, and more. Read it now.
Enter your mobile number or email address below and we'll send you a link to download the free Kindle App. Then you can start reading Kindle books on your smartphone, tablet, or computer - no Kindle device required.
To get the free app, enter your mobile phone number.
From the Publisher
Who Should Read This Book
This book is for people who are learning to program in Java at a beginner or intermediate level. It’s also a classroom resource for teachers who coach new developers in their journey to become programmers. Here, we’re giving you tips and tricks based on more recent Java 81 syntax for resource handling, functional programming, or testing.
You should read this book after you’ve learned the basic Java syntax—after you’re able to write small programs with conditions and loops and you know the basics of object-oriented programming. You should be able to write code that compiles, runs, and solves small tasks like FizzBuzz. You should be able to implement simple algorithms, and you should know how to use basic data structures like a list, queue, stack, or map. And obviously, you should be having fun while doing all that! If you feel a deep satisfaction when you solve a complicated problem, then that’s an excellent start. But of course, you also know that there’s still a lot to learn. When you reflect on your skills and you have to confess that you don’t have a lot of experience in programming in Java (or even programming in general), then you can get the maximum benefit out of this book. This means that you probably haven’t yet developed a sense for clean code and the best practices an experienced developer applies. It’s about time to change this!
Of course, if you already know more advanced books on code quality, readability, maintainability, and clean code in Java, such as ‘Effective Java’ and ‘Clean Code’, then you’ve already come a long way. Nevertheless, you can still find something new here and there.
Why Read This Book?
Every developer has a number of requirements in mind that she considers prerequisites for good or clean code. As long as a piece of code doesn’t violate any of these requirements, it qualifies as good or clean from the viewpoint of the developer. Different people have different requirements. And programming languages differ, of course. But still, for a given language, there’s typically a set of “core” requirements and best practices. These are aspects that the community of developers recognizes and accepts, even if they aren’t written down explicitly. In this book, we’re trying to provide you—someone who might not yet be aware of many of the practices in the Java community—with a set of best practices for clean code in Java. As a beginner, your list of requirements for good Java code might be as short as this one:
- The code must compile.
- The output must be correct.
These items are about the functional correctness of your program, but they don’t tell much about the quality of your code. An experienced programmer cares about a lot more than that, and her checklist is much longer. She just needs a quick glance at a piece of code to detect flaws, bad naming, hard-totest methods, inconsistencies, bad practices, and much more. The aim of this book is to train your brain to internalize more checklist items, helping you on your way to becoming an experienced and professional programmer. Each of the items in this book represents such a checklist item.
Are You Ready? Try the Self-Assessment
If you’re a new programmer, we suggest that you do a short self-assessment to see if you’re ready for the material in this book: the FizzBuzz Test (see the Fizz Buzz Test2 or Using FizzBuzz to Find Developers who Grok Coding3). Some employers use this test in job interviews to determine if an applicant can program at all. The task goes like this:
Write a Java program that prints the numbers from 1 to 100 to the console. But for multiples of three, print Fizz instead of the number and for multiples of five, print Buzz. For numbers that are multiples of both three and five, print FizzBuzz. To make the test more interesting, we’ll extend it a bit here by making sure that you can apply object orientation and use classes and interfaces as well. You should implement the FizzBuzz algorithm in a class called ConsoleBased- FizzBuzz, which implements a FizzBuzz interface. This interface provides a method that takes the first and last numbers to print as arguments. In the main method of a separate Main class, you should use the FizzBuzz interface with its Console- BasedFizzBuzz implementation to count from 1 up to the value passed from the console. Here, you’ll see the outlined structure in a short template.
You should be able to finish this exercise in about 15 minutes. One of the links we listed also contains solutions to the FizzBuzz challenge that you can compare to your own. If you can do it, then you’re ready to get the most out of this book. If not, don’t worry! Keep reading anyway. It might take you a little longer, and you might have a harder time understanding a comparison here and there. But if you practice programming by solving small exercises like the ones in this book, you’ll get on track quickly. Many good resources are available online for practicing your programming skills and getting feedback on your code. Have a look at codewars.com4 or cyber dojo.5 These pages let you train your programming skills in various levels of difficulty. If you have a mathematical background, you’ll find solving the problems of Project Euler6 quite appealing.
If, on the other hand, you find the FizzBuzz test terribly easy, and your solution compiles and runs within seconds, be aware that you might already know some of the practices that we outline in this book. You can still get something out of it, of course. We’ve made all the comparisons self-contained. So feel free to jump around and skip the parts that you already now.
About the Author
- Publication Date : March 22, 2018
- File Size : 1059 KB
- Publisher : Pragmatic Bookshelf; 1st Edition (March 22, 2018)
- Word Wise : Not Enabled
- Language: : English
- ASIN : B07CLFTVZS
- Print Length : 302 pages
- X-Ray : Not Enabled
- Simultaneous Device Usage : Unlimited
- Enhanced Typesetting : Enabled
- Text-to-Speech : Enabled
- Lending : Not Enabled
- Best Sellers Rank: #1,179,246 in Kindle Store (See Top 100 in Kindle Store)
- Customer Reviews:
Top reviews from the United States
There was a problem filtering reviews right now. Please try again later.
In my opinion, it's a MUST for people who wants to learn good practices and principles of programming and it's using Java.
If you're looking for some guidance (or wanting to give some to others) in creating more polished, easier to read (i.e. better) code, you can't go wrong with this book. My advice - get every example working in your own IDE. There is nothing like hands-on to get things into your head.
In 70 well-structured examples, the authors show a "normal" example of Java code on the left and the improved version on the right. Both code fragments are very well described - on the left the problem of the code, on the right what is better in the rewritten code fragment.
The selected examples are easy to understand and can easily be transferred to your own code fragments.
All examples are well grouped by topic and the difficulty level increases slowly. It goes from general (how to comment) to more Java-specific topics (lambdas, streams etc.).
Through this structure you can adapt the reading speed to your own knowledge and use the book later on for further reference.
When reading it was helpful for me that I had read Modern Java Recipes: Simple Solutions to Difficult Problems in Java 8 and 9 by Ken Kousen shortly before and therefore also knew the more modern Java constructs.
In your early days, it can also be useful as an introduction (although very brief) to some related real-world topics such as testing, continuous integration or static code analysis. Overall I do recommend this book especially for junior developers, who will benefit from it the most.
Each example is two pages to show the before/after along with companion text.
Top reviews from other countries
The book is well written and I especially like the exemplary presentation of bad versus good code. In my line of work I have caught myself quite a few times now reconsidering my practices due to this book, so it was already a full success for me. Well done!
Deshalb auch nicht kindle nehmen
Genau das Buch, das ich jedem Entwickler - erfahren oder unerfahren - nur mpfehlen kann.
Selbst nach 2 Dekaden Java Programmierung noch lesenswert.
Das beste zum Thema Clean/Readable code, was ich bisher gelesen habe.
Schön auch die Vergleiche ohne / mit Lambdas bzw. prozedural vs. deklarativ.
The structure of chapters and individual comparisons is very well done and helps to comprehend the implementation as well as the reason behind a code practice. For every bad practice/example, the origin is analized (How was this mistake made?). After that, it is shown why the approach is bad and how it can be improved. This method is very well suited and readers can relate to the featured examples and apply suggestions easily.
When reading, it becomes clear that the authors have a lot of experience with teaching good code practices and have learned a lot from seing code of others.
Funny anecdotes help to map the context of abstract ideas, for example when introducing a new chapter.
I can reccomend Java by Comparison to any java programmer. While beginners will have a good learning curve by reading the book cover to cover, it is very easy for more experienced programmers to extract information most relevant for them.
The concepts are explained very clearly and the format of having both the "bad" and "good" code directly besides each other is lovely.
If you want to learn how to write clear concise and ideomatic java code, then buy this book. It is very easy to read, and I can reccomend it to everyone starting programming in Java. I'd say it's the first programming book you should read after learning the basics, if you want to code in Java. Read it before the Robert C. Martin Series eg Clean Code and other Java books like Effective Java (Which I wouldn't reccomend beginners)