Java hashCode

Java hashCode() method has a close relationship with the equals() method as they complement and are used together. On a high level, the equals method should inspect the relevant data of two instances to determine if they are logically the same object. What internal data the equals() method used should also be used to generate the hashCode() value of a specific object instance. Below are more detailed discussion with code examples about Java hashCode.

Java Char Array

When we are dealing with a handful of data of the same type, we can use a different variable for each. But if we are working with arbitrarily more numbers of data of same type, array can be a good choice because it is a simple data structure to work with. List or Set is also a good choice, but arrays is much simpler to manipulate and work with. We explore below how do we work with Java Char Array. We will check different common scenario we encounter when working with char arrays.

Java String hashCode

Hash code in Java is very important specially with the introduction of the Java Collections API. Many classes in the Collections API uses hash code as a convention. So what exactly is a hash code? It is an integer representation of a specific Object instance. The assumption is that this integer value should be the same whenever the hashCode() method is invoked on the same Object more than once during an execution of a Java application. The hashCode method must consistently provide the same value provided that no internal data used in equals is modified on the Object. We should not worry about this on Immutable objects as internal data is not change throughout it's lifetime. In addition, if two objects are equal using the equals method of the class, then the hashCode of both should return the same value. This implies that the hashCode should be based on the data used in equals method. Lastly, it is not required that two unequal Objects should have different hashCode. Since hashCode is common to all classes as it is implemented in the Object class, we will discuss on how it is implemented in the String class of Java. This post will explain and give examples on Java String HashCode.

Java Tutorial - Read Input From Console

This tutorial will show how to read user input when creating a console application. This is very useful when the program you are writing needs to get input from user before it can proceed with processing.

Java Tutorial - Primitive Types

Primitive types are the most basic data types in Java that are used to store simple values. They can be used directly in programs or as a building block to create more complex data types.

Java Tutorial - Variables and Assignment Statements

Variables are a fundamental component of any programming language. This tutorial will give a brief introduction to variables in Java.

Java Tutorial - Simple Hello World Java Application

A good way of learning a new language is to analyze a simple application that outputs something to the screen. This tutorial will walk you through a simple Hello World application to help you start your journey with Java.

Java Tutorial - Setup Your Windows Development Environment

For Java beginners, I recommend to start with setting up a development environment. It is easier to understand concepts by running actual code and testing them. This Java tutorial is written to help newbie Java programmers to prepare their Windows Development Environment.