Java基础

Java基础

注释、标识符、关键字

Java中的注释有三种:
1. 单行注释://
2. 多行注释:/* */
3. 文档注释:/** */

数据类型

什么是字节

位(bit):是计算机中内部数据储存的最小单位,11001100是一个八位二进制数。

字节(byte):是计算机中数据处理的基本单位,习惯上用大写B来表示。

1B(byte,字节) = 8bit(位)

字符:是指计算机中使用的字母、符号、数字和字。

基本类型

数值类型:

整数类型:

byte占1个字节范围:-128-127
short占2个字节范围:-32768-322767
int占4个字节范围:-2147483648-2147483647
long占8个字节范围

int i = 10;
        int i2 = 010; //八进制0
        int i3 = 0x10; //十六进制0x     0-9 A-F 16
        System.out.println(i);
        System.out.println(i2);
        System.out.println(i3);
浮点类型:

float占4个字节

double占8个字节

 //浮点数拓展  银行业务怎么表示?
       //BigDecimal 数学工具类
       //float        有限   离散    舍入误差        大约接近但不等于
       //double
       //最好完全避免使用浮点数进行比较
       //最好完全避免使用浮点数进行比较
       //最好完全避免使用浮点数进行比较
           float f = 0.1f; //0.1
           double d = 1.0 / 10;  //0.1
           System.out.println(f == d); //float
            
           float d1 = 2131231212f;
           float d2 = d1 + 1;
           System.out.println(d1 == d2);
字符类型:

字符类型char占2个字节

	char c1 = 'a';
        char c2 = '中';
        System.out.println(c1);
        System.out.println((int) c1);    //强制转换
        System.out.println(c2);
        System.out.println((int) c2);    //强制转换

        //所有的字符本质还是数字
        //编码    Unicode 表:97 = a    2字节     65536      2^16 = 65536

        char c3 = '\u0061';
        System.out.println(c3);

        //转义字符
        // \t   制表符
        // \n   换行
        System.out.println("HellO\tWorld");

        //
        String sa = new String("hello world!");
        String sb = new String("hello world!");
        System.out.println(sa == sb);

        String sc = "hello world";
        String sd = "hello world";
        System.out.println(sc == sd);
        // 对象   从内存分析
boolean类型:

占1位,其值只有True和False两个

boolean falg = true;

        if (falg == true) { } //新手
        if (falg) { } //老手
        //Less is More! 代码要精简易读

引用类型

类型转换

变量、常量

运算符

包机制、JavaDoc

posted @ 2021-12-20 19:41  DS-dx  阅读(37)  评论(0)    收藏  举报