Java基础入门

DOC命令

dir       查看目录下文件
cd /c d:        文件切换目录
cd ...       返回上一级目录
cls       清除窗口的记录
exit       退出CMD
ipconfig       查看TCP/IP配置的值
ping       可以测试网络
md       新建文件夹
rd       删除文件
cd>name.text       新建文件
del       删除文件

Hello Word

public class HelloWord{
	public static void main(String[] args) {
    System.out.println("Helo,Word!");
    }
}

关键字

基本数据类型

//整数
int i = 10;
byte b = 20;
short s = 30;
long l = 40L;

//小数,浮点数
float f  = 50.1F;
double d = 3.14159265358979;

//字符 单引号
shar name = ‘A’;

//字符串
String name = "Right-A";

//布尔值
boolean T = true;
boolean F = false;

变量

  1. 类变量
  2. 实例变量
  3. 局部变量
public class Demo04 {

    //属性:变量

    //实例变量:从属于对象:如果不自行初始化默认值为 0   0.0
    //布尔值默认值为:false
    //除了基本类型,其他的默认值为 null
    String name;
    int age;

    //类变量    static
    static double salary = 2500;

    //main方法
    public static void main(String[] args) {

        //局部变量:必须声明初始值
        int i = 10;
        System.out.println(i);

        //变量类型
        Demo04 Demo04 = new Demo04();
        System.out.println(Demo04.age);//默认值 0
        System.out.println(Demo04.name);//默认值 null

        //类变量    static
        System.out.println(salary);
    }

    //其他方法
    public void add(){

    }
}

常量 final

public class Demo05 {

    //修饰符,不存在先后顺序
    static final double PI = 3.14;
    final static double PO = 3.14;

    public static void main(String[] args) {
        System.out.println(PI);
        System.out.println(PO);
    }
}

运算符

算术运算
public static void main(String[] args) {
    int a = 10;
    int b = 20;

    System.out.println(a + b);	//30
    System.out.println(a - b);	//-10
    System.out.println(a * b);	//200
    System.out.println(a / (double) b);	//0.5
}
public static void main(String[] args) {
        //++    --  自增   自减     一元运算
        int a = 3;
        System.out.println(a);  //3
        
        int b = a++;
        System.out.println(b);  //3
        
        int c = ++b;
        System.out.println(c);  //4

        //工具类Math
        double pow = Math.pow(2, 3);
        System.out.println(pow);
}
不同类型的数相加
public static void main(String[] args) {
    long a = 1235153215321L;
    int b = 123;
    short c = 10;
    byte d = 5;

    System.out.println(a+b+c+d);	//1235153215459
    System.out.println(b+c+d);	//138
    System.out.println(c+d);	//15
}
关系运算
public static void main(String[] args) {
    int a = 10;
    int b = 20;
    int c = 32;

    System.out.println(c % b);

    System.out.println(a > b);  //false
    System.out.println(a < b);  //true
    System.out.println(a == b); //false
    System.out.println(a != b); //true
}
逻辑运算
public static void main(String[] args) {
        //与(and)    或(or)    非(取反)
        boolean a = true;
        boolean b = false;

        // 逻辑与运算:两个变量都为真,结果为true
        System.out.println("a && b :" + (a && b));  //a && b :false

        // 逻辑或运算:两个变量有一个为真,结果才为真
        System.out.println("a || b :" + (a || b));  //a || b :true

        // 如果是真,则变为假,如果是假则变为真
        System.out.println("!(a && b) :" + !(a && b));  //!(a && b) :true

        //短路运算
        int c = 5;
        boolean d = (c < 4) && (c++ < 7);
        System.out.println(d);  //false
        System.out.println(c);  //5
}
位运算
public static void main(String[] args) {
        /*
        A = 0011 1100
        B = 0000 1101

        A & B = 0000 1100
        A / B = 0011 1101
        A ^ B = 0011 0001
        ~ B = 1111 0010

        2*8 = 16 	2*2*2*2

        <<      *2   左移
        >>      /2   右移

        0000 0000       0
        0000 0010       2
        0000 0100       4
        0000 1000       8
        0001 0000       16

        */
        System.out.println(2 << 3); //16
}
条件运算(三元运算)
public static void main(String[] args) {
        //x ? y : z
        //如果x==true, 则结果为y, 否则结果为z

        int score = 80;
        String type = score < 60 ? "不及格" : "及格";
        System.out.println(type);   //及格
    }
拓展赋值运算符
public static void main(String[] args) {
        int a = 10;
        int b = 20;

        a += b; //a = a+b;
        a -= b; //a = a-b;
        System.out.println(a);  //10
        
        //字符串连接符  +  ,String
        System.out.println("" + a + b); //1020
        System.out.println(a + b + ""); //30
}

包机制

特定取名方式名字 www.Right.com 【颠倒】

com.Right.operator.

导包 [import]
package com.Right.operator; 

import com.Right.operator.Demo01;

阿里巴巴Java开发手册 无规矩不成方圆,无规矩不能协作

Java DOC

  • @author 作者名
  • @version 版本号
  • @since 指明需要最早使用的JDK版本
  • @param 参数名
  • @return 返回值参数情况
  • @throws 异常抛出情况
package com.Right.base;

/**
 * @author Right
 * @version 1.0
 * @since 1.8
 */
public class Doc {
    String name;

    /**
     *
     * @param name
     * @return
     * @throws Exception
     */
    public String test(String name) throws Exception{
        return name;
    }
}
cmd Java Doc文档生成

javadoc -encoding UTF-8 -charset UTF-8 Doc.java

IDEA生成 Java Doc

  1. 选择是整个项目还是模块还是单个文件
  2. 文档输出路径
  3. 文档的语言,中文 zh_CN
  4. -encoding utf-8 -charset utf-8

学习中的一些笔记

原文地址:https://www.cnblogs.com/Right-A/p/13269660.html