Byte Datatype in Java


Byte:
byte is smallest Java integer type.
byte is 8 bit signed type ranges from –128 to 127.
byte is mostly used when dealing with raw data like reading a binary file.
Syntax:
Declare byte varibale as below
byte <variable name> = <default value>;
Note:
Here assigning default value is optional.

public class Byte {
 
        public static void main(String[] args) {

                 
                 byte b1 = 10;
                 byte b2 = 200;
                 
                System.out.println("Value of byte variable b1 is :" + b1);
                System.out.println("Value of byte variable b1 is :" + b2);
        }
}


Output:
Value of byte variable b1 is :10
Value of byte variable b1 is :200