The size of the byte type is 8. At first, we thought it was 1. This value refers to the bit used, rather than the memory size occupied by the object.
Byte is the number of symbols,-128 ~ 127. Initialization means that the initial value cannot exceed the indicated range, and an exception is thrown, rather than being truncated by C ++.
When the string type is used for initialization, the string cannot be null or "". Otherwise, a numeric formatting exception is thrown.
Package tjava. testlang; </P> <p> public class testbyte extends basicclasstest <br/> {<br/> static string classname = "Java. lang. byte "; </P> <p> Public static void test () throws classnotfoundexception <br/>{< br/> logprintln (" test show :"); <br/> logprintln ("Byte (/" 123/") =" + new byte ("123 ")); <br/> logprintln ("Byte (/"-123/") =" + new byte ("-123 ")); <br/> try <br/> {<br/> logprintln ("Byte (/" ABC/") =" + NE W byte ("ABC"); <br/>}catch (numberformatexception e) <br/>{< br/> logprintln ("Byte (/" ABC /") = new byte (/"ABC/") Throw A numberformatexception! "); <Br/>}< br/> logprintln (" Byte (byte) (123) = "+ new byte (byte) 123 )); </P> <p> try <br/> {<br/> logprintln ("byte. parsebyte (null) = "+ byte. parsebyte (null); <br/>}catch (numberformatexception e) <br/>{< br/> logprintln ("Byte (null) = new byte (null) throw a numberformatexception! "); <Br/>}< br/> try <br/>{< br/> logprintln (" byte. parsebyte (/"/") = "+ byte. parsebyte (""); <br/>}catch (numberformatexception e) <br/>{< br/> logprintln ("Byte (/"/") = new byte (null) Throw A numberformatexception! "); <Br/>}< br/> try <br/>{< br/> logprintln (" byte. valueof (null) = "+ byte. valueof (null); <br/>} catch (numberformatexception e) <br/>{< br/> logprintln ("byte. valueof (null) = new byte (null) Throw A numberformatexception! "); <Br/>}< br/> logprintln (" byte. parsebyte (/"7b/", 16) = "+ byte. parsebyte ("7b", 16); <br/> logprintln ("byte. parsebyte (/"-7b/", 16) = "+ byte. parsebyte ("-7b", 16); <br/> logprintln ("byte. valueof (/"7b/", 16) = "+ byte. valueof ("7b", 16); <br/> logprintln ("byte. valueof (/"-7b/", 16) = "+ byte. valueof ("-7b", 16); <br/> logprintln ("byte. type = "+ byte. type); <br/> logprintln ("byte. size = "+ byte. size); <br/> logprintln ("byte. max_value = "+ byte. max_value); <br/> logprintln ("byte. max_value + 1 = "+ new byte (byte) (byte. max_value + (byte) 1); <br/> logprintln ("byte. min_value = "+ byte. min_value); <br/> logprintln ("byte. MIN_VALUE-1 = "+ new byte (byte) (byte. min_value-(byte) 1); <br/>}</P> <p> Public static void showclassinfo () throws classnotfoundexception <br/>{< br/> basicclasstest. showclassinfo (classname); <br/>}< br/>
Result:
============================ Java. lang. byte's information ================================
Package name: Java. Lang
Class Name: Java. Lang. byte
Super Class Name: Java. Lang. Number
Include method:
Hashcode ()
Compareto (Java. Lang. byte)
Compareto (Java. Lang. Object)
Equals (Java. Lang. Object)
Tostring (byte)
Tostring ()
Decode (Java. Lang. String)
Valueof (byte)
Valueof (Java. Lang. String INT)
Valueof (Java. Lang. String)
Bytevalue ()
Doublevalue ()
Floatvalue ()
Intvalue ()
Longvalue ()
Shortvalue ()
Parsebyte (Java. Lang. String)
Parsebyte (Java. Lang. String INT)
Wait ()
Wait (long INT)
Wait (long)
Getclass ()
Notify ()
Policyall ()
Include field:
Min_value
Max_value
Type
Size
Include constructor:
Java. Lang. byte (byte)
Java. Lang. byte (Java. Lang. String)
Test show:
Byte ("123") = 123
Byte ("-123") =-123
Byte ("ABC") = new byte ("ABC") Throw A numberformatexception!
Byte (byte) (123) = 123
Byte (null) = new byte (null) Throw A numberformatexception!
Byte ("") = new byte (null) Throw A numberformatexception!
Byte. valueof (null) = new byte (null) Throw A numberformatexception!
Byte. parsebyte ("7b", 16) = 123
Byte. parsebyte ("-7b", 16) =-123
Byte. valueof ("7b", 16) = 123
Byte. valueof ("-7b", 16) =-123
Byte. type = byte
Byte. size = 8
Byte. max_value = 127
Byte. max_value + 1 =-128
Bytes. min_value =-128
Byte. MIN_VALUE-1 = 127