1 API概述
    什么是API
    API (Application Programming Interface) :应用程序编程接口
    java中的API
    指的就是 JDK 中提供的各种功能的 Java类,这些类将底层的实现封装了起来,我们不需要关心这些类是如何实现的,只需要学习这些类如何使用即可,我们可以通过帮助文档来学习这些API如何使用。
    2.1 Math
    1、Math类概述
    Math 包含执行基本数字运算的方法
    2、Math中方法的调用方式
    Math类中无构造方法,但内部的方法都是静态的,则可以通过 类名.进行调用
    3、Math类的常用方法
    public static int abs(int a) 返回参数的绝对值
    public static double ceil(double a) 向上取整
    public static double floor(double a) 向下取整
    public static int round(float a) 按照四舍五入返回最接近参数的
    intpublic static int max(int a,int b) 返回两个int值中的较大值
    public static int min(int a,int b) 返回两个int值中的较小值
    public static double pow (double a,double b) 返回a的b次幂的值
    public static double random() 返回值为double的正值,[0.0,1.0)
    2.2 System
    常用方法

    public static void exit(int status) 终止当前运行的 Java 虚拟机,非零表示异常终止
    public static long currentTimeMillis() 返回当前时间(以毫秒为单位)

    2.3.1 Object类的toString方法

    • Object类概述

      • Object 是类层次结构的根,每个类都可以将 Object 作为超类。所有类都直接或者间接的继承自该类,换句话说,该类所具备的方法,所有类都会有一份
    • 查看方法源码的方式

      • 选中方法,按下Ctrl + B
    • 重写toString方法的方式

      1. 1. Alt + Insert 选择toString
      2. 1. 在类的空白区域,右键 -> Generate -> 选择toString
    • toString方法的作用:

    以良好的格式,更方便的展示对象中的属性值
    2.3.2 Object类的equals方法

    • equals方法的作用
      • 用于对象之间的比较,返回true和false的结果
      • 举例:s1.equals(s2); s1和s2是两个对象
    • 重写equals方法的使用场景
      • 不希望比较对象的地址值,想要结合对象属性进行比较的时候。
    • 重写equals方法的方式
      1. 1. alt + insert 选择equals() and hashCode(),IntelliJ Default,一路next,finish即可
      2. 1. 在类的空白区域,右键 -> Generate -> 选择equals() and hashCode(),后面的同上。

    2.4 Objects

    常用方法
    | public static String toString(对象) | 返回参数中对象的字符串表示形式
    | public static String toString(对象, 默认字符串) | 返回对象的字符串表示形式
    | public static Boolean isNull(对象) | 判断对象是否为空
    | public static Boolean nonNull(对象) | 判断对象是否不为空
    2.5 BigDecimal

    • 作用

    可以用来进行精确计算

    • 构造方法 | 方法名 | 说明 | | :—- | :—- | | BigDecimal(double val) | 参数为double | | BigDecimal(String val) | 参数为String |

    • 常用方法 | 方法名 | 说明 | | :—- | :—- | | public BigDecimal add(另一个BigDecimal对象) | 加法 | | public BigDecimal subtract (另一个BigDecimal对象) | 减法 | | public BigDecimal multiply (另一个BigDecimal对象) | 乘法 | | public BigDecimal divide (另一个BigDecimal对象) | 除法(不能除尽时报错) | | public BigDecimal divide (另一个BigDecimal对象,精确几位,舍入模式) | |

    总结

    1. BigDecimal是用来进行精确计算的
    2. 创建BigDecimal的对象,构造方法使用参数类型为字符串的。
    3. 四则运算中的除法,如果除不尽请使用divide的三个参数的方法

    3.1 基本类型包装类

    • 基本类型包装类的作用

    将基本数据类型封装成对象的好处在于可以在对象中定义更多的功能方法操作该数据
    常用的操作之一:用于基本数据类型与字符串之间的转换

    • 基本类型对应的包装类 | 基本数据类型 | 包装类 | | :—- | :—- | | byte | Byte | | short | Short | | int | Integer | | long | Long | | float | Float | | double | Double | | char | Character | | boolean | Boolean |

    3.1.2 Integer类(应用)

    • Integer类概述

    包装一个对象中的原始类型 int 的值

    • Integer类构造方法 | 方法名 | 说明 | | :—- | :—- | | public Integer(int value) | 根据 int 值创建 Integer 对象(过时) | | public Integer(String s) | 根据 String 值创建 Integer 对象(过时) | | public static Integer valueOf(int i) | 返回表示指定的 int 值的 Integer 实例 | | public static Integer valueOf(String s) | 返回一个保存指定值的 Integer 对象 String |

    3.2 int和String类型的相互转换
    int转换为String
    转换方式
    方式一:直接在数字后加一个空字符串
    方式二:通过String类静态方法toString()
    String转换为int
    转换方式
    方式一:先将字符串数字转成Integer,再调用valueOf()方法
    方式二:通过Integer静态方法parseInt()进行转换
    4. 时间日期类
    4.1 date类
    4.1.1 构造方法

    方法名 说明
    public Date() 分配一个 Date对象,并初始化,以便它代表它被分配的时间,精确到毫秒
    public Date(long date) 分配一个 Date对象,并将其初始化为表示从标准基准时间起指定的毫秒数

    4.1.2 常用方法

    方法名 说明
    public long getTime() 获取的是日期对象从1970年1月1日 00:00:00到现在的毫秒值
    public void setTime(long time) 设置时间,给的是毫秒值

    4.1.3 格式化 SimpleDateForment

    public SimpleDateFormat() 构造一个SimpleDateFormat,使用默认模式和日期格式
    public SimpleDateFormat(String pattern) 构造一个SimpleDateFormat使用给定的模式和默认的日期格式

    SimpleDateFormat类的常用方法

    • 格式化(从Date到String)
      • public final String format(Date date):将日期格式化成日期/时间字符串
    • 解析(从String到Date)
      • public Date parse(String source):从给定字符串的开始解析文本以生成日期

    5.JDK8时间日期类
    5.1 JDK8新增日期类 (理解)

    • LocalDate 表示日期(年月日)
    • LocalTime 表示时间(时分秒)
    • LocalDateTime 表示时间+ 日期 (年月日时分秒)

    5.2 LocalDateTime创建方法 (应用)

    • 方法说明 | 方法名 | 说明 | | :—- | :—- | | public static LocalDateTime now() | 获取当前系统时间 | | public static LocalDateTime of (年, 月 , 日, 时, 分, 秒) | 使用指定年月日和时分秒初始化一个LocalDateTime对象 |

    5.3 LocalDateTime获取方法 (应用)

    • 方法说明 | 方法名 | 说明 | | :—- | :—- | | public int getYear() | 获取年 | | public int getMonthValue() | 获取月份(1-12) | | public int getDayOfMonth() | 获取月份中的第几天(1-31) | | public int getDayOfYear() | 获取一年中的第几天(1-366) | | public DayOfWeek getDayOfWeek() | 获取星期 | | public int getMinute() | 获取分钟 | | public int getHour() | 获取小时 |

    5.4 LocalDateTime转换方法 (应用)

    • 方法说明 | 方法名 | 说明 | | :—- | :—- | | public LocalDate toLocalDate () | 转换成为一个LocalDate对象 | | public LocalTime toLocalTime () | 转换成为一个LocalTime对象 |

    5.5 LocalDateTime格式化和解析 (应用)

    • 方法说明 | 方法名 | 说明 | | :—- | :—- | | public String format (指定格式) | 把一个LocalDateTime格式化成为一个字符串 | | public LocalDateTime parse (准备解析的字符串, 解析格式) | 把一个日期字符串解析成为一个LocalDateTime对象 | | public static DateTimeFormatter ofPattern(String pattern) | 使用指定的日期模板获取一个日期格式化器DateTimeFormatter对象 |

    5.6 LocalDateTime减少或者增加时间的方法以及修改方法 (省略)
    6 Period (应用)

    • 方法说明 | 方法名 | 说明 | | :—- | :—- | | public static Period between(开始时间,结束时间) | 计算两个“时间”的间隔 | | public int getYears() | 获得这段时间的年数 | | public int getMonths() | 获得此期间的总月数 | | public int getDays() | 获得此期间的天数 | | public long toTotalMonths() | 获取此期间的总月数 |

    7 Duration (应用)

    • 方法说明 | 方法名 | 说明 | | :—- | :—- | | public static Durationbetween(开始时间,结束时间) | 计算两个“时间”的间隔 | | public long toSeconds() | 获得此时间间隔的秒 | | public int toMillis() | 获得此时间间隔的毫秒 | | public int toNanos() | 获得此时间间隔的纳秒 |