Java Tutorial - Compound Assignment Operators

Many times when we want to assign an expression to a given variable, the expression uses simple operation that involves the original value of the variable. For example, a = a + 2 means we want to add 2 to the variable, and assign the value back to it. Java provides a short hand notation for this to make programming more concise and easier to understand. We call it compound assignment operators. We will discuss around 11 of these in this post. Below are examples on how to perform compound assignment operators in Java.

Java Tutorial - Assignment Operators

It is very hard to write any program without using variables. And when we use variable, the first thing we want to do is to assign it some values. Variables are like storage of data, so it is natural for us to put some values to this storage. In this post, we will show how to use the assignment operator in Java, which assigns values to a variable.

Java Tutorial - Basic Arithmetic Operators

The most basic way we use a programming language is to develop programs that performs mathematical calculations. The foundation of the most basic of all mathematical operations are arithmetic. Which in most programming languages covers addition, subtraction, division, multiplication, and modulus. Most other mathematical calculations can be done through the use of these basic operations. Below is a tutorial on how to perform arithmetic operations in Java.

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.