Numbering System edge cases of Java

Anojaa Gnaneswaran
2 min readMar 2, 2022

Java contain two type of data types.primitive and Reference data types.Primitive data should included with numeric data type.It divided into two parts.

  1. Floating (Float,Double)
  2. Integer (byte, short,int, long)

Here we going to discuss about Integer data type,those are use for numeric based calculation like math purpose.Those data types are signed with two’s complement (2s) And It data Range and Size also different from each of those.

Int Data type

int data type store with -2147483648 to 2147483647 range and mostly used for declared variable as a Numeric value.Below code shows how use this integer in java .It is 32bit Size.

int number = 454;
System.out.println(number); // print 454

long Data type

long data type is a two’s complement and 64bit. By default, The Range of a long data type is signed from -2 63to 2 63–1.It is 64 bit size.

For example:

long number = 17000000000L;
System.out.println(number); // print 15000000000

Short Data type

A short data type is greater than byte in terms of size and less than a integer(byte< short< int). It’s ranges signed from -32,768 to 32767. The default size is 2 bytes. Let’s see an example for short data type

class ShortExample {
public static void main(String[] args) {
short a= 3455,
System.out.println(a);
}
}

byte Data type

We must need good understanding about byte data type. It is an 8-bit size and signed two’s complement integer. It range between -128 to 127. A byte data type is helpful for saving memory in large amounts. let’s see a small example for byte.

class byteExample{
public static void main(String[]args){
byte a = 125;
byte b = 6;
result = (byte) (a+b);
System.out.println(result);
}
} //print -125

Above code you see we got -125 as output ,reason for that byte data type range will -127 to 127.therefore when we Add 125+ 6= 131.it will above the 127 range.so we got results as -125.

Number wheel for java Byte data type

edge case

This case java occur edge case ,edge case mean it occurs the extreme (maximum or minimum).For an example we develop any java application like like Teachers attendance system.If more than 127 teachers attendance mark in that system it will shows negative value.the attendance value marked as negative it’s a big problem in that system.Then they arise big issue with that. That is the main edge case occur when we use Byte data type in java .

I hope this article help to get little idea about edge case in java.

Happy Learning!

Reference

  1. https://www.educative.io/edpresso/corner-case-vs-edge-case

--

--

Anojaa Gnaneswaran

Faculty of IT, University of Moratuwa, Associated Software Engineer at Virtusa