คลาส Byte ล้อมค่าของ byte ชนิดดั้งเดิมในวัตถุ
ต่อไปนี้เป็นฟิลด์สำหรับคลาส Byte−
- สแตติกไบต์ MAX_VALUE − เป็นค่าคงที่ที่คงค่าสูงสุดที่ไบต์มีได้ 27-1
- ไบต์คงที่ MIN_VALUE − ค่าคงที่นี้เป็นค่าคงที่ที่ค่าต่ำสุดที่ไบต์มีได้ -27
- ขนาด int คงที่ − นี่คือจำนวนบิตที่ใช้แทนค่าไบต์ในรูปแบบไบนารีเสริมของสองตัว
- คลาสคงที่
TYPE − นี่คืออินสแตนซ์ของคลาสที่แสดงไบต์ประเภทดั้งเดิม
ตัวอย่าง
เรามาดูตัวอย่างกัน −
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