Quick Reach
The byte data type of Java
Java has eight types of primitive data types to store data in the Java programs. The byte is one of the primitive data types in Java.
Few main points about Java byte data type:
- The byte takes eight bits or one byte of signed memory.
- Byte Is a numeric type.
- The Default value of the byte variable is 0.
- The Minimum value of the byte type can be -128.
- The Maximum value of the byte java type can be 127.
byte data type example
The following example declares and uses the byte Java data type variable. The variable is assigned a value and then printed on the screen by using the System.out.println.
See graphic of above example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
public class variable_example {
public static void main(String []args) {
byte a;
byte b=10;
a=1;
System.out.println(b); // Java Variable example
}
}
|
As you run the code the output will be:
10
In the above example, you can see the byte variable is declared and value can be assigned later or at the time of declaration as well.
The java byte type of variable can be used in the array index, for instance, that takes four times less space than the java integers.
Also see Java data types
Leave A Comment?