栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

JAVA学习20220708

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

JAVA学习20220708

标识符

java 所有的组成部分都需要名字。类名、变量名以及方法名都被称为标识符。

所有的标识符都应该以字母(a~z ,A-Z),美元符( ) 、 或 者 下 划 线 ( ) 开 始 ; 首 字 母 之 后 可 以 是 : 字 母 ( a   z , A − Z ) , 美 元 符 ( )、或者下划线(_)开始; 首字母之后可以是:字母(a~z ,A-Z),美元符( )、或者下划线()​开始;首字母之后可以是:字母(a z,A−Z),美元符()、或者下划线(_)或数字的任意字符组合
不能使用关键字作为变量名或者方法名
标识符大小写是敏感的
不使用拼音命名

关键字

数据类型

强类型语言
所有变量都必须先定义后才能使用

java数据类型分为两大类
primitive type
reference type

ctrl + 鼠标右键,点击,可以查看ider 中元素的源代码

public class Demo02 {
    public static void main(String[] args) {
        String a = "HelloWorld";
        int num = 10;

        Integer

        //八大基本数据类型
        int num1 = 10;
        byte num2 = 20;  //1个字节,8个 bit;8位
        short num3 = 30;
        long num4 = 30L; //long类型要在后面加个L

        

        //小数;浮点数
        float num5 = 50.1F;
        double mum6 = 3.141592653589793238462643;

        //字符
        char name = 'a';
        //字符串
        String names = "宇宙";
        //布尔值 是非
        boolean flag = ture;
        boolean flag1 = false;


        System.out.println(a);
        System.out.println(num);
    }
}
public class Demo03 {
    public static void main(String[] args) {
        //整数拓展    进制     二进制0b          十进制         八进制 0        十六进制0x
        int i =10;
        int i2=010;//八进制0
        int i3=0x10;//十六进制0x
        System.out.println(i);
        System.out.println(i2);
        System.out.println(i3);
        System.out.println("====================================");
        //===========================================
        //浮点数拓展?  银行业务怎么表示,钱?
        //BigDecimal 数学工具类
        //===========================================
        //float  有限  离散  舍入误差 大约 接近但不等于
        //double


        float f=0.1f;
        double d=1.0/10;
        System.out.println(f==d);
        System.out.println(f);
        System.out.println(d);

        //===========================================
        //字符拓展?
        //===========================================
        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字节    65536    Excel    2^16=65536
        //Unicode 表 97=a  65=A   20013=中  U0000~UFFFF

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

        //转义字符
        //  t 制表符
        //   n 换行
        System.out.println("hellot world");

        //
        System.out.println("==================================");
        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 flag = true;
        if(flag==true){}  //新手
        if(flag){}  //老手
        //less is more 代码要精简易读

    }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1008236.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号