第3章 java的基本程序设计结构【补缺学习】【注释与数据类型】【核心技术卷I】

1. /* */   不能嵌套

2.  可以在数字字面量加下划线  让人更易读,编译器会自动去除这些下划线

int decimalism=1_00_0000;
int binary=0b1111_0100_0010_0100_0000;
System.out.println(decimalism);
System.out.println(binary);
1000000
1000000

3. java没有任何无符号形式的int long short byte  但是可以用类方法解释为无符号数

System.out.println("byte的无符号转换");
byte a=-1,b=-128;
System.out.println(Byte.toUnsignedInt(a));
System.out.println(Byte.toUnsignedInt(b));
System.out.println(Byte.toUnsignedLong(a));
System.out.println(Byte.toUnsignedLong(b));
System.out.println("结论:byte可以转换成无符号的 int long");
System.out.println("*******************************************************");

System.out.println("int的无符号转换");
int  c=-128,d=128;
System.out.println(Integer.toUnsignedLong(c));
System.out.println(Integer.toUnsignedLong(d));
System.out.println("结论:int可以转换成无符号的long");

System.out.println(Integer.toUnsignedString(c,2));
System.out.println(Integer.toUnsignedString(d,2));

System.out.println(Integer.toBinaryString(c));
System.out.println(Integer.toBinaryString(d));

System.out.println(Integer.toString(c,2));
System.out.println(Integer.toString(d,2));
System.out.println("结论:");
System.out.println("Integer.toUnsignedString(c,2) == Integer.toBinaryString(c)");
System.out.println("Integer.toUnsignedString(c,8) == Integer.toOctalString(c)");
System.out.println("Integer.toUnsignedString(c,16) == Integer.toHexString(c)");
System.out.println("Integer.toString(num,radix) num可以转成radix进制的有符号字符串");
System.out.println("*******************************************************");
System.out.println("long的无符号转换");
long e=128,f=128;
System.out.println("long没有无符号,只能转成无符号字符串来处理");
byte的无符号转换
255
128
255
128
结论:byte可以转换成无符号的 int long
*******************************************************
int的无符号转换
4294967168
128
结论:int可以转换成无符号的long
11111111111111111111111110000000
10000000
11111111111111111111111110000000
10000000
-10000000
10000000
结论:
Integer.toUnsignedString(c,2) == Integer.toBinaryString(c)
Integer.toUnsignedString(c,8) == Integer.toOctalString(c)
Integer.toUnsignedString(c,16) == Integer.toHexString(c)
Integer.toString(num,radix) num可以转成radix进制的有符号字符串
*******************************************************
long的无符号转换
long没有无符号,只能转成无符号字符串来处理

进程已结束,退出代码 0

4. 记住一些范围 ,大致印象要有

byte  127     2^8-1  ||   -128   -2^8  最高位是符号位也是数据位    1个字节

short 32767     2^16-1      2个字节

int   刚过20亿  2^32-1       4个字节      

long   2^64-1  8个字节

5. 三个溢出和出错的浮点数值  

正无穷大

负无穷大

NaN   (非数字)   用double.

double a=Double.POSITIVE_INFINITY;//正无穷
double b=Double.NEGATIVE_INFINITY;//负无穷·
double c=Double.NaN; //非数字
int d =Integer.MAX_VALUE;
int e=Integer.MIN_VALUE;
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
System.out.println(e);
Infinity
-Infinity
NaN
2147483647
-2147483648

6.浮点数不适用于无法接受舍入误差的金融计算   

因为 

System.out.println(2.0-1.1);

0.8999999999999999   不是所期待的应该为0.9   应该用BigDecimal类

7.

Unicode 转义序列会在解析代码之前得到处理  

System.out.println("\u0022+\u0022");

结果会是空串  \u0022表示 " 双引号


更隐秘的 要注意注释中的\u

// \u000A is a new line
        System.out.println("*****");

错误:(3, 15) java: 需要';'

错误:(4, 15) java: 需要';'

编译没有错,运行时会报错  因为 \u000A 被替换为一个换行符


// look inside c:\users
        System.out.println("*****");

错误:(3, 20) java: 非法的 Unicode 转义

因为\u后面并没有跟着4个十六进制数

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值