Tag: java

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.

The Big Three in Java, Part Two: equals(Object)

In the second of a series of four blog posts, we explore another one of the “big three” methods in Java: the Object.equals(Object) method. This method allows us to compare two objects of a given type for value equality, instead of just reference equality. That is, this method can compare the internal state of two objects to determine if they’re equal.

The Big Three in Java, Part One: toString()

In the first of a series of four blog posts, we’ll explore one of the “big three” methods in Java: the Object.toString() method. This method generates a String representation of an object and its state. By overriding the Object.toString() method in any class that we write, we can customize, for example, how objects of that class are displayed when printed to the console.

Things I Wish I Had Known: Learning C++ After Learning Java

When I learned to program, I learned in Java. When I started studying my second language, C++, I found myself struggling to understand the subtle differences in syntax, the significant differences in how memory management works, and even the differences in the meaning of some terms between Java and C++. This blog post lays out three things I wish had realized right off the bat when I started learning C++.

Breaking Down Java’s “Hello World”

The first piece of code most Java students see is the “Hello World” application. Despite the simplicity of what the program does, the code itself has a lot going on. There are words like class, public, static, void, and String[]. Why is all of this code here, and what does it do? In this blog post, we’ll break down Java’s “Hello World” program, and explain what all of the component pieces actually mean.