The basic data types in java include byte. byte stores integer data, which occupies 1 byte (8 bits). The data storage range is-128 ~ + 127.
Byte is a class in java. lang to encapsulate the basic data type byte. Encapsulation has several advantages, such as: 1. byte can pass object references so that multiple functions can operate on data of the byte type. The basic data type of the byte must be stored in the stack region after being assigned values; 2. defines the conversion method between String and String. The Byte size is 8 bytes. Because Byte applies for objects through the keyword new, and the objects applied for in this part are placed in the heap (heap area) of the memory ).
Package BasicKnowledge. testlang; public class ByteTest {public static void main (String args []) {Byte by1 = new Byte ("123"); Byte by2 = new Byte ("123 "); int length = by1.SIZE; int max = by2.MAX _ VALUE; int min = by2.MIN _ VALUE; if (by1 = by2) {System. out. println ("Operation '= 'compares the reference of Byte objects and equal");} else System. out. println ("Operation '= 'compares the objects of Byte objects and not equal"); if (by1.equals (by2) {System. out. println ("Function 'equals () 'compares the value of Byte objects and equal");} else System. out. println ("Function 'equals () 'compares the value of Byte objects and not equal"); Byte by3 = by1; if (by3 = by1) {System. out. println ("Operation '= 'compares the reference of Byte objects and equal");} else System. out. println ("Operation '= 'compares the reference of Byte objects and not equal"); System. out. println (by1); System. out. println (by2); System. out. println ("The length is" + length); System. out. println ("MAX:" + max + "MIN" + min); byte temp = (byte) 241; // The binary representation of 241 is 11110001 (complement ), if the first digit is the symbol bit, the remaining calculation result is 15 and the final result is-15System. out. println (temp );}}
Output result:
Operation '=' compares the objects of Byte objects and not equal
Function 'equals()' compares the value of Byte objects and equal
Operation '=' compares the reference of Byte objects and equal
123
123
The length is 8
MAX:127 MIN-128
-15