Java Byte类字段及示例
字节类是原始类型字节的一个封装类,它包含了一些有效处理字节值的方法,如将其转换为字符串表示,反之亦然。一个Byte类的对象可以持有一个单一的字节值。
Byte类以 字段 的形式提供了四个常量 。 它们是
- MAX_VALUE: The MAX_VALUE is a instance variable of Byte class which is used to return the maximum byte value.
语法:
public static final byte MAX_VALUE
用法:
Byte.MAX_VALUE
返回值:它返回一个等于127的字节值。
下面是MAX_VALUE的实现。
// Java code to implement
// MAX_VALUE of Byte class
class GFG {
public static void main(String[] args)
{
// byte variable
byte max_value;
// MAX_VALUE Byte class
max_value = Byte.MAX_VALUE;
// printing the MAX_VALUE
System.out.println(max_value);
}
}
输出:
127
- MIN_VALUE:MIN_VALUE**是Byte类的一个实例变量,用于返回最小的字节值。
语法:
public static final byte MIN_VALUE
用法:
Byte.MIN_VALUE
返回值:它返回一个等于-128的字节值。
下面是MIN_VALUE的实现。
// Java code to implement
// MIN_VALUE of Byte class
class GFG {
public static void main(String[] args)
{
// byte variable
byte min_value;
// MIN_VALUE Byte class
min_value = Byte.MIN_VALUE;
// printing the MIN_VALUE
System.out.println(min_value);
}
}
输出:
-128
- SIZE: SIZE是Byte类的一个实例变量,用于返回以二进制表示的字节值所需的比特数(二补)。
语法:
public static final int SIZE
用法:
Byte.SIZE
返回值:它返回一个等于8的int值。
下面是SIZE的实现。
// Java code to implement
// SIZE of Byte class
class GFG {
public static void main(String[] args)
{
// SIZE Byte class
int output = Byte.SIZE;
// printing the output
System.out.println(output);
}
}
输出:
8
- TYPE: TYPE是Byte类的一个实例变量,用于返回代表原始数据类型byte的Class实例。
语法:
public static final Class<Byte> TYPE
用法:
Byte.TYPE
返回值:它返回一个代表原始数据类型字节的类实例。
下面是TYPE的实现。
// Java code to implement
// TYPE of Byte class
class GFG {
public static void main(String[] args)
{
// TYPE variable of Byte class
Class<Byte> output = Byte.TYPE;
// printing the output
System.out.println(output);
}
}
输出:
byte
极客教程