Java byte and Byte

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.