Java--day1

一.入门

1.常用快捷键

ctrl + Z 撤销

Alt + F4 关闭窗口

shift + del 永久删除

Win + E 打开我的电脑

 

2.基本Dos命令

命令提示符 ProwerShell

# 盘符切换  C:  

# 查看目录下所有内容 dir

# 切换目录 cd /d f:\IDE     不同盘级之间切换

  返回上一级 cd..

  cd abc  进入目录下级中是文件(dir列出来的文件)

# 清理屏幕 cls

# 退出终端 exit(输入)

# 查询IP  ipconfig

# 计算器 calc

# 画图工具 mspaint

# 记事本 notepad

# 鼠标右键直接粘贴

# 创建文件夹 

 

3.JDK JRE JVM

JDK Java开发者工具 包括 jre、jvm(开发工具)

JRE JAVA运行环境

JVM JAVA虚拟机

 

 二. 基础语法

1.注释

psvm

sout

public class HelloWorld {
    public static void main(String[] args) {
//输出
System.out.println("HelloWorld!");
}
}

/*
多行注释
*/

/**
* 文档注释 有内容和功能
* @Description Hello World
* @Author 作者
*
* */
 

 

2.标识符 关键字

public class Demo01 {
    public static void main(String[] args) {

        String hello = "1230.";
        String _$11 = "123";
        String 乌拉 = "111";
        //可以用中文做变量名
        System.out.println(乌拉);

    }
}

 

 3.数据类型

 

public class Demo02 {
    public static void main(String[] args) {
        //八大基本数据类型     
        int num = 10;
        byte num2 = 127;
        short num3 = 20;
        long num4 = 30L;  //jia L
        
        float num5 = 0.2F;  //F
        double num10 = 1.2;
        
        char name = 'A';boolean flag = true;

        String a = "10";//引用数据类型
} }

 

 

fori 生成for循环for (int i = 0; i< ; i++) { }
iter 生成增强for循环
itar 生成array for代码块
itit 生成iterator 迭代
itli 生成List的遍历
itco 生成Collection迭代

 

 

 

大数字比较 BigDecimal 数学类工具

  //数据拓展 进制  二进制0b  十进制 八进制0  十六进制0x
        int i = 10;
        int i1 = 010;
        int i2 = 0x10;  //十六进制的10  16+0

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


        //字符拓展
        char c1 = 'a';  //单引号
        char c2 = '中';
        System.out.println(c1);
        System.out.println((int)c1);

        System.out.println(c2);
        System.out.println((int)c2);//强制转化 把字符转化成数字

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


        //转义字符
        System.out.println("Hello\tworld");
        System.out.println("Hello\nworld");

        //
        String sa = new String("hello");
        String sb = new String("hello");

        System.out.println(sa==sb);  //false

        String sc = "hello";
        String sd = "hello";
        System.out.println(sc==sd);  //ture


        //布尔拓展
        boolean flag = true;
        if (flag==true){}
        if (flag){}

 

 4.类型转换

小数的优先级高于整数

 

 int i = 128;
        byte b = (byte) i;    //由高到低强制转化
        double c = i;   //由低到高自动转换
        System.out.println(i);
        System.out.println(b);  //-128  byte最大到127,强制转化要考虑范围,内存溢出
        System.out.println(c);  //128.0

 

98  、、b

 

5.变量 常量 作用域

 

//变量
public class Demo06 {
    //属性 变量

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

    //实例变量:从属于对象;
    //布尔值 默认false
    String name;
    int age;

    //main方法
    public static void main(String[] args) {
        //局部变量,必须声明和初始化
        int i = 10;
        System.out.println(i);

        //变量类型 变量名 =
        Demo06 demo06 = new Demo06();  //new demo06() alt回车再回车
        System.out.println(demo06.age);  //0
        System.out.println(demo06.name); //null

        //类变量 static
        System.out.println(salary);  //用static在类外定义的 删了static 就不能引用了
    }
    //其他方法
    public void add(){
    }
}

 

//常量
public
class Demo07 { static final Double PI = 3.14; //final 常量 double 数据类型 public static void main(String[] args) { //修饰符 不区分前后 System.out.println(PI); } }

 

 

 

6.运算符

 

public class Demo01 {
    public static void main(String[] args) {
        //运算符
        int a1 =10;
        int b1 = 15;
        System.out.println(a1/(double)b1);  //除法不出错

        long a = 121212121121L;
        int b =123;
        short c = 10;
        byte d = 8;

        System.out.println(a+b+c+d);  //Long
        System.out.println(b+c+d); //Int
        System.out.println(c+d); //Int
        //int->float->double->long  

        double pow = Math.pow(3,2);   //3^2
System.out.println(pow); //9.0
} }
        boolean x = true;
        boolean y = false;
        System.out.println("x&&y" + (x&&y));
        System.out.println("x||y" + (x||y));  //或 在第一个为真的时候短路了
        System.out.println("!(x&&y)" + !(x&&y));
//位运算  与二进制有关
        /*
         A&B 都是1 为1
         A|B 有1 就是1
         A^B 非 不同是1
         ~B 取反
         
         0000 0000    0
         0000 0001    1
         0000 0010    2
         0000 0100    4
         
          */
        System.out.println(2<<3);  //二进制左移变成8

输出“”  + a + b 变string  注意顺序

public class Demo02 {
    public static void main(String[] args) {
        int a = 10;
        int b = 20;
        //字符串连接符  +  ,变成string类型
        System.out.println(""+a+b); //1020
        System.out.println(a+b+""); //30
    }
} 

//三元运算符

x?y:z      x为真输出为y  假输出z

7.包机制

 

8.JavaDoc生成文档

 

package com.fxh.base;
/**
 * @author fxh
 * @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;
    }
}

 

index.html  主页 写的文档信息  since  jdk版本

 

  

 

posted @ 2023-11-15 12:09  ``飘``  阅读(23)  评论(0)    收藏  举报