Let’s consider a text file: maybe it ends with a newline character, or maybe it doesn’t. Tools like git work more smoothly with files that end in newlines. Command-line tools like cat also produce clearer output when working with files that end in a newline. So, today’s Java programming problem asks you to fix files that don’t end in a newline.
Tag: java
What’s That Tiny Makefile?
When I’m working with programming students, I usually write a quick Makefile. Only a few lines long, this file allows us to recompile code on the command line just by typing “make”. In this post, we’ll skip over all the details of writing complex Makefiles. Instead, we’ll see how to slap together a rudimentary Makefile in seconds — one that will save us time while we’re working on an assignment.
Better println() Debugging in Java
In today’s blog post, we’ll look at one way to improve System.out.println() debugging in Java. Namely, let’s make it so our println() debugging outputs include the name of the source code file, the method name, and the line number where the output happens. Debugging with println() is fast and easy, and it’s not going anywhere; so, let’s just make its output more useful.
The Big Three in Java, Part Four: equals(Object) in Hierarchies
In the final entry in a series of four blog posts about the “big three” methods in Java, we return to the Object.equals(Object) method. Specifically, we discuss how to maintain the symmetry and transitivity properties of the method in class hierarchies. We answer the question: when do we use instanceof, and when do we check for class equality instead?
The Big Three in Java, Part Three: hashCode()
For part three in this series of four blog posts, we look at another one of Java’s “big three” methods: Object.hashCode(). This method returns an integer value that can be used to split objects into buckets. One critical requirement is that any two objects that compare as equal must return the same hash code. We explore how to meet that requirement, while also writing hashCode() methods that are effective and efficient.
