首页 > 编程语言 > 详细

Java数据类型底层拓展

时间:2021-06-08 09:47:14      阅读:15      评论:0      收藏:0      [点我收藏+]

Java数据类型底层拓展

整数

进制:二进制(0b)、八进制(0)、十进制、十六进制(0x)

int i = 10;
int i2 = 010;//八进制
int i3 = 0x10;//十六进制0x 0-9 A-F

System.out.println(i);//10
System.out.println(i2);//8
System.out.println(i3);//16

浮点数

银行业务怎么表示?使用什么数据类型?

使用BigDecimal :数学工具类

不能使用float、double等浮点数,它们是有限的、离散的、有舍入误差。

银行业务最好完全避免使用浮点数进行比较

float f = 0.1f;//0.1
double d = 1.0/10;//0.1

System.out.println(f == d);//false
System.out.println(f);//0.1
System.out.println(d);//0.1

float d1 = 21212121312f;
float d2 = d1+1;

System.out.println(d1==d2);//true
System.out.println(d1);//2.12121211E10
System.out.println(d2);//2.12121211E10

字符

所有的字符的本质还是数字

Unicode表对应 97=‘a‘,字符占2字节,范围:0-65536 2的16次方=65536

表示范围:U0000-UFFFF

char c1 = ‘a‘;
char c2 = ‘中‘;

System.out.println(c1);//a
System.out.println((int)c1);// 强制转换	97

System.out.println(c2);//中
System.out.println((int)c2); //强制转换 20013

char c3 = ‘\u0061‘;
System.out.println(c3);//a

对象

对象是指向内存地址的,new 一个对象相当于创建一个新的内存地址。不使用new关键字则指向常量池中的内存地址。

String sa = new String("Hello World");
String sb = new String("Hello World");
System.out.println(sa==sb);// false

String sc = "Hello World";
String sd = "Hello World";
System.out.println(sc==sd);// true

Java数据类型底层拓展

原文:https://www.cnblogs.com/kkklay/p/14861135.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!