【Java】Java易错知识点

Java易错知识点

1

int x = 12L; //错误,L表示用 long 类型表示

2,

boolean x = 3==5; // x 's value is false

3,

x = false == (3==0); // x is true

4, 

System.out.println( 4 / 2.3 ); // output 1.700000003

5,

System.out.println(4.5f == 4.5); // 4.5f会转换成4.5(double类型的)因此true
System.out.println(4.4f == 4.4); // false
//这是因为4.4在浮点数中不能精确表示,
//而4.5可以精确表示出来。

6,

int x = (int) true; // wrong, true不能转换,这里Java跟c++的表示不一样

7,

		long  x = 2;
		switch(x) {   //错误!long类型不能用于switch
		case 2:
			System.out.println(2);

		}

8,

Primitive type: 4 bytes for int, 8 bytes for double, ...

Object reference: 8 bytes.

Array: 24 bytes + memory for each array entry.

Object: 16 bytes + memory for each instance variable + 8 if inner class (for point to enclosing class).

Padding: round up to multiple of 8 bytes.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值