Chapter3.Know Your Variables

variables types

  • Variables come in two flavors
    • primitive
      • as object state(instance variables)
    • reference
      • as local variables( variables decleard within a method )

primitive types

TypeBit DepthValue Range
booleanJVM-specifictrue of false
char16 bits0 to 65535
byte8 bits-128 to 127
short16 bits-32768 to 32767
int32 bits-2147483648 to 2147483647
long64 bits-huge to huge
float32 bitsvaries
double64 bitsvaries

controlling your object

  • There is actually no such thing as an object variable.
  • There’s only an object reference variable.
  • An object reference variable holds bits that represent a way to access an object.

* It doesn’t hold the object itself,but it holds something like a pointer.Or an address.

You can’t stuff an object into a variable.Objcet live in one place and one place only – the garbage collectible heap!


When obeject is not assigned,it is abandoned and eligible for Garbage Collection(GC).

变量的类型

  • 变量有两种类型
    • 基本类型
      • 作为对象里的声明(实例变量)
    • 引用类型
      • 作为局部变量(变量声明在方法内)

基本类型

类型位深取值范围
booleanJVM-specifictrue of false
char16 bits0 to 65535
byte8 bits-128 to 127
short16 bits-32768 to 32767
int32 bits-2147483648 to 2147483647
long64 bits-很多到+很多
float32 bits变化的
double64 bits变化的

控制你的对象

  • 实际上没有对象变量
  • 仅仅只是对象引用变量
  • 对象引用变量是二进制数,代表进入对象的方法

* 对象引用变量不是对象,但它像指针或者地址。

你不能把对象塞进变量。对象只存在一个地方–垃圾回收堆(GC)!

当对象没有被变量指定,它将会被丢弃,并符合垃圾收集(GC)的条

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值