软件打开方式、注释、标识符和关键字、数据类型及其拓展

软件打开方式

  1. new project

select java and jdk1.8

then location

then it will involve module and environment

in "src" you can new a java class

  1. empty project

location

nothing

new a module and select jdk1.8

then in the project structure

on the project page

select jdk1.8 in SDK and 8 in language level

then in "src" you can new a java class

注释、标识符和关键字

public class HelloWorld {
    public static void main(String[] args) {
        //单行注释
        //输出一个Hello,World!
        System.out.println("Hello,World!");
    }
    /*
        多行注释
        多行注释
        多行注释
         */
    /**
     * @Description HelloWorld
     * @Author lcj
     */
}


public class Demo01 {
    public static void main(String[] args) {
        String Ahello = "lcj";
        String hello = "1lcj";
        String $hello = "lcj";
        String _hello = "lcj";
        String Hello = "lcj";
        String 阿萨大 = "付款码";
        String 阿萨s = "付款码";
        System.out.println(阿萨大);
    }
}

数据类型


八进制 十六进制

调试

public class Demo02 {
    public static void main(String[] args) {
        String a = "10";
        int num = 30;
        System.out.println("a");
        System.out.println(num);
        //八大数据类型

        //整数
        int num1 = 100;
        byte num2 = 20;
        short num3 = 30;
        long num4 = 40L;//数字后加L
        //浮点数
        float num5 = 0.1F;//float后要加F
        double num6 = 3.1415926;
        //字符
        char name = '是';
        //字符串,不是关键字,是类
        String namea = "阿萨大";
        //布尔值:是非
        boolean flag = true;
        boolean flag1 = false;
    }
}

数据类型拓展

public class Demo03 {
    public static void main(String[] args) {
        //整数拓展 进制   二进制0b   十进制    八进制0    十六进制0x
        int n1 = 10;
        int n2 = 0b10;
        int n3 = 010;
        int n4 = 0x12;//0~9 A~F 16
        System.out.println(n1);
        System.out.println(n2);
        System.out.println(n3);
        System.out.println(n4);
        System.out.println("========================================================");
        //==============================================================================
        //浮点数拓展 银行业务怎么表示? 钱
        //应该用 BigDecimal 数学工具类
        //===============================================================================
        //float 有限 离散 舍入误差 大约 接近但不等于
        //double
        //最好避免使用浮点数进行比较

        float f = 0.1f;
        double d = 1.0/10;
        System.out.println(f==d);//不相等
        float m1 = 121231313131f;
        float m2 = m1 + 1;
        System.out.println(m1==m2);//true
        //==============================================================================
        //字符拓展
        //===============================================================================
        System.out.println("========================================================");
        char a1 = 'a';
        char a2 = '中';
        System.out.println(a1);
        System.out.println(a2);
        System.out.println((int)a1);
        System.out.println((int)a2);//强制转换
        //所有字符本质还是数字
        //编码 Unicode 表:( 97 = a ) 占2字节  可以表示0-65536   Excel   2^16 = 65536
        //U0000   UFFFF
        char a3 = '\u0061';
        System.out.println(a3);
        //转义字符
        // \t  table
        // \n  换行
        //...
        System.out.println("Hello\nWorld");
        System.out.println("========================================================");
        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);
        //对象 从内存分析

        //布尔值拓展
        boolean flag = true;
        int asd = 55;
        if (flag==true){
            System.out.println(asd);
        }
        if (flag){
            asd = 1;
            System.out.println(asd);
        }
        //Less is More!
    }
}
posted @ 2022-10-03 19:59  uque  阅读(66)  评论(0编辑  收藏  举报