March 2018

Comparing Long Values in Java

  • Satish 

1. Overview In this short tutorial, we’ll discuss different ways to compare two Long instances. We emphasize the problems that arise when using the reference comparison operator (==). 2. Problem Using Reference Comparison Long is a wrapper class for the primitive type long. Since they are objects and not primitive values, we need to compare the content of Long instances using .equals() instead of the reference comparison operator (==). In some cases, we may get the idea that == is okay, but looks are deceiving. Consider that we can use ==… Read More »Comparing Long Values in Java

Overflow and Underflow in Java

  • Satish 

1. Introduction In this tutorial, we’ll look at the overflow and underflow of numerical data types in Java. We won’t dive deeper into the more theoretical aspects — we’ll just focus on when it happens in Java. First, we’ll look at integer data types, then at floating-point data types. For both, we’ll also see how we can detect when over- or underflow occurs. 2. Overflow and Underflow Simply put, overflow and underflow happen when we assign a value that is… Read More »Overflow and Underflow in Java