Integral data types can hold integers ( positive and negative counting numbers, as well as zero ) . byte, short, int, long comes under Integral data types category .
Let’s see each one in detail

byte :

  • byte size is 8 bits(1 byte)byte can hold the maximum value 127(2^7-1)
  • It can hold the Minimum value -128(-2^7)
  • byte is suitable if we want handle data in terms of streams
  • We can assign any character to byte type variable

For better understanding of byte type usage, see the below examples.

        byte a=120;
        byte b=128;  // causes compiler error. the value should be < 128
        byte c=-121;
        byte d=-129;  // causes compiler error. the value should be >= -128
        byte e='a';   // 99 is assigned(ASCII value of 'a')
        byte f= -'a';  // -99 is assigned
        byte g='-a';  // causes compiler error

short :

  • short size is 16 bits (2 bytes)
  • Maximum value we can assign is 32,767(2^15-1)
  • Minimum value we can assign is -32,768 (-2^15)
  • We can assign any character to short type variable
  • Example : short a=1200; short b= ‘a’; (ASCII value of char will be assigned)

int :

  • int is the most used data type in java
  • int size is 32 bits (4 bytes for any operating system)
  • Maximum value we can assign is 2,147,483,647(2^31-1)
  • Minimum value we can assign is – 2,147,483,648(-2^31)
  • We can assign any character to int type variable
  • Example : int a=1200; int b= ‘a’; (ASCII value of char will be assigned)

long :

If int is not enough to hold the value then we go for long data type. for example, if we want hold light year value, int type is not enough. so, we have to go for long data type. For Example .

long lightyear = 3,00,00036524*3600;

  • long size is 64 bits(8 bytes)
  • long can hold the maximum value 2^63-1
  • It can hold the Minimum value -2^63
  • We can assign any character to long type variable