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
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