Byte 클래스는 기본 유형 byte의 값을 개체에 래핑합니다.
다음은 바이트 클래스에 대한 필드입니다-
- 정적 바이트 MAX_VALUE − 이것은 바이트가 가질 수 있는 최대값인 27-1을 유지하는 상수입니다.
- 정적 바이트 MIN_VALUE − 바이트가 가질 수 있는 최소값 -27을 유지하는 상수입니다.
- 정적 정수 크기 − 2의 보수 바이너리 형식으로 바이트 값을 나타내는 데 사용되는 비트 수입니다.
- 정적 클래스<바이트> 유형 − 기본형 바이트를 나타내는 Class 인스턴스입니다.
예
이제 예를 살펴보겠습니다 -
import java.lang.*;
public class Demo {
public static void main(String[] args){
Byte b1, b2;
int i1, i2;
b1 = new Byte("1");
b2 = Byte.MIN_VALUE;
i1 = b1.intValue();
i2 = b2.intValue();
String str1 = "int value of Byte " + b1 + " is " + i1;
String str2 = "int value of Byte " + b2 + " is " + i2;
System.out.println( str1 );
System.out.println( str2 );
}
} 출력
그러면 다음과 같은 출력이 생성됩니다. -
int value of Byte 1 is 1 int value of Byte -128 is -128
예
이제 다른 예를 살펴보겠습니다 -
import java.lang.*;
public class Demo {
public static void main(String[] args){
Byte b1, b2;
String s1, s2;
b1 = new Byte("-10");
b2 = Byte.MIN_VALUE;
System.out.println("Number of bits in b1 = "+b1.SIZE );
System.out.println("Number of bits in b2 = "+b2.SIZE );
s1 = b1.toString();
s2 = b2.toString();
String str1 = "String value of Byte " + b1 + " is " + s1;
String str2 = "String value of Byte " + b2 + " is " + s2;
System.out.println( str1 );
System.out.println( str2 );
}
} 출력
그러면 다음과 같은 출력이 생성됩니다. -
Number of bits in b1 = 8 Number of bits in b2 = 8 String value of Byte -10 is -10 String value of Byte -128 is -128