Java byte type
In this chapter you will learn:
Description
The smallest integer type is byte
.
byte
type variables are useful when working with a stream of data from a network or file.
Byte variables are declared by use of the byte keyword. The following declares two byte variables called b and c:
byte b, c;
Size and value
byte
is a signed 8-bit type that has a range from -128 to 127.
Example
The following code creates two byte type variables and assigns values.
public class Main {
public static void main(String[] args) {
byte b1 = 100;
byte b2 = 20;
System.out.println("Value of byte variable b1 is :" + b1);
System.out.println("Value of byte variable b1 is :" + b2);
}//from w ww. ja va 2s. c om
}
The code above generates the following result.
The Byte class wraps a value of primitive type byte in an object. Byte class provides several methods for converting a byte to a String and a String to a byte.
Next chapter...
What you will learn in the next chapter: