Java Byte Example Program

Chapter: Data Types Last Updated: 28-03-2017 17:31:47 UTC

Program:

            /* ............... START ............... */
                
public class JavaByteExample {
	public static void main(String[] args) {
		byte b = 3;
		Byte bObj1 = new Byte(b);
		Byte bObj2 = new Byte("10");
		// print value of Byte objects
		System.out.println(bObj1);
		System.out.println(bObj2);
	}
}

                /* ............... END ............... */
        

Output

3
10

Notes:

  • Byte data type is a 8-bit signed two's complement integer.
  • Byte has minimum value of -128 and a maximum value of 127 (inclusive).
  • Default value is 0.
  • Byte data type is used to save space in large arrays because byte is four times smaller than an int.
  • Example: byte a = 100 , byte b = -20.
  • The java.lang.Byte class wraps a value of primitive type byte in an object. An object of type Byte contains a single field whose type is byte.

Tags

Java, Byte

Similar Programs Chapter Last Updated
Java String Example Program Data Types 19-06-2016
Primitive Datatypes In Java Example Data Types 17-06-2016
Enum In Java Example Data Types 28-04-2016
Java Short Example Program Data Types 10-06-2016
Java Long Example Program Data Types 15-07-2016
Java Int Example Program Data Types 06-07-2016
Int Array In Java Example Program Data Types 09-06-2016
Java Float Program Example Data Types 28-03-2017
Java Double Example Program Data Types 28-03-2017
Java Char Example Program Data Types 28-03-2017
Java Boolean Example Program Data Types 28-03-2017

1