学习java笔记(2),java.lang.Byte。

Byte类型的SIZE是8,开始还以为是1呢。这个值是指使用的bit位数,而不是对象占内存大小。

Byte为有符号数,-128~127,初始化是初始值不能超过表示的范围,会抛异常,而不象C++会截断。

使用字符串类型初始化时,字符串不能为null或者"",否则会抛数字格式化异常。

 

 

结果:

 

=================== 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( )
                   notifyAll( )
   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
         Byte.MIN_VALUE = -128
       Byte.MIN_VALUE-1 = 127

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值