byte keyword Java

byte keyword Java

byte keyword is a primitive data type. It is use for declare variables. It can also be use with methods to return byte value. It can hold an 8-bit signed two’s complement integer.

Example : Using byte with a method

public class ByteExample3 {  
      
    byte age=18;  
      
    public byte display()  
    {  
        return age;  
    }  
    public static void main(String[] args) {  
        ByteExample2 b=new ByteExample2();  
          
System.out.println("The age must be: "+b.display());  
  
                  
    }         
}  

Output

The age must be: 18

Roles

  • The byte range lies between -128 to 127 (inclusive).
  • Its default value is 0.
  • It is useful to handle the st
  • It is also useful for saving memory in large arrays.

What is byte in Java with example?

The following declares two byte variables called a and b: byte a, b; Important Points About byte Integer Data Type: Byte data type is an 8-bit signed two’s complement integer.

Operators Java
Data Types Java
Variable Java
Second Short Program Java
Install and Setup Path Java
Hello World Java