java基础知识

 

 

java基础语法

注释

  1. 单行注释 //

    //单行注释
  2. 多行注释 /* */

    /*
    多行注释
    多行注释
    */

     

  3. 文档注释

    • //JavaDos注释 /** */

      /***
      *                   .::::.
      *                 .::::::::.
      *                 ::::::::::: love YOU
      *             ..:::::::::::'
      *           '::::::::::::'
      *             .::::::::::
      *       '::::::::::::::..
      *             ..::::::::::::.
      *           ``::::::::::::::::
      *           ::::``:::::::::'       .:::.
      *           ::::'   ':::::'       .::::::::.
      *         .::::'     ::::     .:::::::'::::.
      *       .:::'       ::::: .:::::::::' ':::::.
      *       .::'       :::::.:::::::::'     ':::::.
      *     .::'         ::::::::::::::'         ``::::.
      * ...:::           ::::::::::::'             ``::.
      * ```` ':.         ':::::::::'                 ::::..
      *                   '.:::::'                   ':'````..
      */
      /***
      * ┌───┐   ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┐
      * │Esc│   │ F1│ F2│ F3│ F4│ │ F5│ F6│ F7│ F8│ │ F9│F10│F11│F12│ │P/S│S L│P/B│ ┌┐   ┌┐   ┌┐
      * └───┘   └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┘ └┘   └┘   └┘
      * ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───────┐ ┌───┬───┬───┐ ┌───┬───┬───┬───┐
      * │~ `│! 1│@ 2│# 3│$ 4│% 5│^ 6│& 7│* 8│( 9│) 0│_ -│+ =│ BacSp │ │Ins│Hom│PUp│ │N L│ / │ * │ - │
      * ├───┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─────┤ ├───┼───┼───┤ ├───┼───┼───┼───┤
      * │ Tab │ Q │ W │ E │ R │ T │ Y │ U │ I │ O │ P │{ [│} ]│ | \ │ │Del│End│PDn│ │ 7 │ 8 │ 9 │   │
      * ├─────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴─────┤ └───┴───┴───┘ ├───┼───┼───┤ + │
      * │ Caps │ A │ S │ D │ F │ G │ H │ J │ K │ L │: ;│" '│ Enter │               │ 4 │ 5 │ 6 │   │
      * ├──────┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴────────┤     ┌───┐     ├───┼───┼───┼───┤
      * │ Shift │ Z │ X │ C │ V │ B │ N │ M │< ,│> .│? /│ Shift   │     │ ↑ │     │ 1 │ 2 │ 3 │   │
      * ├─────┬──┴─┬─┴──┬┴───┴───┴───┴───┴───┴──┬┴───┼───┴┬────┬────┤ ┌───┼───┼───┐ ├───┴───┼───┤ E││
      * │ Ctrl│   │Alt │         Space         │ Alt│   │   │Ctrl│ │ ← │ ↓ │ → │ │   0   │ . │←─┘│
      * └─────┴────┴────┴───────────────────────┴────┴────┴────┴────┘ └───┴───┴───┘ └───────┴───┴───┘
      */

       

       

标识符和关键字

关键字

java 常用的关键字有

 

image-20200912011500872

abstract, assert,boolean, break, byte, case, catch, char, class, const, continue, default, do, double, else, enum,extends, final, finally, float, for, if, implements, import, instanceof, int, interface, long, native, new, package, private, protected, public, return, short, static, strictfp, super, switch, synchronized, this, throw, throws, transient, try, void, volatile, while

标识符

  1. 所有的标识符都应该以字符(A~Z |a~z),美元符号($)或者(_)

  2. 不能以关键字作为变量名或者方法

  3. 标识符是大小写敏感

     

    image-20200912012044860

数据类型

强类型语言 :

要求变量使用严格规定,所有变量都必须先定义后使用

弱类型语言:

 

 

image-20200912012535724

 

Java的数据类型分为两大类

  • 基本数据类型

    • 整数

      1. byte

      2. short

      3. int

      4. long

    • 浮点数

      1. float

      2. double

    • 字符数据类型

      char

    • 布尔

      boolean 占一位 true or false

       

  • 引用数据类型

    1. 接口

    2. 数组

       

//八大基本数据类型
//整数
int num = 10;
byte num1 = 20;
short num2 = 30;
long num3 = 40;
//小数,浮点数
float num4 = 50.1F;
double num5 = 50.2;
// 字符
char name = 'A';
//String 字符串不是关键字,是类
// String name = "monkey";

//布尔值
boolean flag = true;
字节和位

 

image-20200912014224915

数据类型扩展

// 整数扩展  进制 二进制 0b 八进制 0 十六进制 0x
       int i = 0b10;
       int i1 = 010;
       int i2 = 0x10;

       System.out.println(i);
       System.out.println(i1);
       System.out.println(i2);

       // ==================================
       // 浮点数扩展
//银行业务用BigDecimal
       // ========================================
       float f = 0.1f;
       double d = 1.0/10;
       System.out.println(d == f);
       float d1 = 234444444444444445555f;
       float d2 = d1 + 1;
       System.out.println(d1 == d2);
       // ==================================
       // 字符扩展
       // ========================================
       char c1 = '猴';
       char c2 = 'c';
       System.out.println(c1);
       System.out.println((int) c1);
       System.out.println(c2);
       System.out.println((int) c2);

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

       System.out.println("=======================");
       String sa = new String("helloworld");
       String sb = new String("helloworld");
       System.out.println(sa == sb);
       System.out.println("==========================");
       String sc = "helloworld";
       String sd = "helloworld";
       System.out.println(sc == sd);
       // ================================
       // 布尔值的扩转
       boolean flag1 = true;
       if(flag1 == true){} //新手
       if(flag1){} //老手
posted @ 2020-09-12 15:37  monkeykitty  阅读(183)  评论(0)    收藏  举报