java笔记2021.10.19

1.标识符注意点

  1. 所有的标识符都应该以字母(A-Z或者a-z)、美元符($)、或者下划线(_)开始
  2. 首字符之后可以是字母(A-Z或者a-z)、美元符($)、下划线(_)或者数字的任何字符组成
  3. 不能使用关键字作为变量名或方法名
  4. 标识符的大小写敏感

2.数据类型

强类型语言

要求变量的使用要严格符合规定,所有变量都必须先定义后才能使用

弱类型语言

JAVA的数据类型分为两大类

基本类型(primitive type)

  1. 数值类型
    1. 整数类型
      1. byte占1个字节范围
      2. short占2个字节范围
      3. int占4个字节范围
      4. long占8个字节范围
    2. 浮点类型
      1. float占4个字节
      2. double占8个字节
    3. 字符类型char占2个字节
  2. boolean类型:占1位其值只有true和false两个
//八大基本数据类型
//整数
int num1 = 10;//常用
byte num2 = 20;
short num3 = 30;
long num4 = 30L;//Long要在数字后面加个L
//小数:浮点数
float num5 = 50.1F;//flaot要在数字后面加个F
double num6 = 3.141592653564564564;
//字符
char num7 = 'A';
//字符串
String num8 = "你好";
//布尔值:是非
boolean flag = true;
//boolean flag = false;

引用类型(reference type)

 public static void main(String[] args) {
        //整数拓展
        int a = 10;
        int b = 010;//八进制0
        int c = 0x10;//十六进制0x 0~9 A~F
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
        System.out.println("===========================");
        //浮点数拓展
        //BigDecimal 数学工具类
        //float 有限的 离散的 舍入误差 大约 接近但不等于
        //double
        //最好完全使用浮点数去进行比较
        float e = 0.1f;
        double f = 0.1/1;
        System.out.println(e==f);
        System.out.println(e);
        System.out.println(f);
        float d1 = 123564321f;
        float d2 = d1 + 1;
        System.out.println(d1 == d2);
        System.out.println("===========================");
        //字符类拓展
        char c1 = 'a';
        char c2 = '中';
        System.out.println(c1);
        System.out.println((int)c1);//强制转换
        System.out.println(c2);
        System.out.println((int)c2);//强制转换
        //强制转换 (所有的字符本质还是数字)
        //编码  Unicode 2字节 0~65536
        char c3 = '\u0061';
        System.out.println(c3);
        //转义字符
        // \t  制表符  \n 换行
        System.out.println("===========================");
        String sc = "hello world";
        String sd = "hello world";
        System.out.println(sc==sd);
        //对象 从内存分析
        //布尔值拓展
        boolean flag = true;
        if(flag == true){}
        if (flag){}
        //Less is More! 代码要精简易读
    }![在这里插入图片描述](https://img-blog.csdnimg.cn/b2ab092c50584a488a149ba226c2e696.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAbmluZV9vbmVfc2l4,size_14,color_FFFFFF,t_70,g_se,x_16#pic_center)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

nine_one_six

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值