Java By Comparison: Become a Java Craftsman in 70 Examples 1st Edition, Kindle Edition
Use the Amazon App to scan ISBNs and compare prices.
- Highlight, take notes, and search in the book
- Length: 208 pages
"Neverworld Wake" by Marisha Pessl
Read the absorbing new psychological suspense thriller from acclaimed New York Times bestselling author Marisha Pessl. Learn more
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.
Customers who bought this item also bought
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.
Would you like to tell us about a lower price?
Top customer reviews
There was a problem filtering reviews right now. Please try again later.
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.
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.
Maybe their code is written on Java but you can easily apply it to another languages. Thanks.