day02-基础细节

java

强类型语言(java,c++)

变量的使用严格符合规定,所有变量先定义再使用.

弱类型语言(js,vb)


数据类型

基本数据类型

byte(1个字节):-128~127

short(2个字节):-32768~32767

int(4个字节):-2147483648 ~ 2147483647

long(8个字节):-9223372036854774808 ~ 9223372036854774807

float(4个字节)

double(8个字节)

char(2个字节)

boolean(1个位)

引用数据类型(类,接口,数组)

浮点数拓展

public class hello {
    public static void main(String[] args) {
        float f1 = 0.1f;
        float f2 = 1.0f/10;
        System.out.println(f1 == f2);
        System.out.println(f1);
        System.out.println(f2);
        
        float f3 = 1000000000f;
        float f4 = f3 + 1;
        System.out.println(f3 == f4);
        System.out.println(f3);
        System.out.println(f4);
        //应该尽量避免使用浮点数数据类型进行比较。
    }
}

浮点数有限,会进行舍入


字符串拓展(内存池)

public class hello {
    public static void main(String[] args) {
        String s1 = new String("hello world");
        String s2 = new String("hello world");
        System.out.println(s1 == s2);
        System.out.println("--------------------------------");
        String s3 = "hello world";
        String s4 = "hello world";
        System.out.println(s3 == s4);
    }
}

上面的结果是flase

下面的是true

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值