跟着老侯玩编程 跟着老侯玩编程
首页
  • 基础语法
  • 网络编程
  • 设计模式
  • 基础篇
  • 进阶篇
  • 框架篇
  • Redis
  • Alibaba
  • 课程目录
  • 码农宝典
留言
首页
  • 基础语法
  • 网络编程
  • 设计模式
  • 基础篇
  • 进阶篇
  • 框架篇
  • Redis
  • Alibaba
  • 课程目录
  • 码农宝典
留言
  • 基础篇

    • 聊聊环境变量
    • 永不过时的HelloWorld
    • 标识符
    • 数据类型
    • 运算符
    • 语句
    • 数组
    • 方法详解
    • 类和对象
    • 类的成员
    • 类的继承
    • 类的形式
    • 封装和多态
    • 接口和Lambda表达式
    • 泛型编程
    • 常用API之函数式接口
    • 常用API
      • Math
      • System
        • 案例
      • Arrays
      • 时间日期
        • SimpleDateFormat 类
        • Calendar 类
        • 案例 - 控制台版的日历
    • 异常机制
    • 多线程
    • 常用API之File类
    • IO流
    • 集合
    • 常用API之Stream流
    • 网络编程
    • 枚举
    • 注解和反射
  • 进阶篇

    • MySQL基础
    • 数据库-JDBC
    • HTML基础
    • CSS基础
    • JavaScript-基础
    • 服务器-Servlet
    • 服务器-Servlet3
    • 动态网页-JSP
    • Ajax
    • 前端项目工程化
    • ECMA2015
    • 模块化规范
  • 框架篇

    • 工具-Maven
    • 框架-MyBatis
    • 框架-Spring
    • 框架-SpringMVC
    • 工具-SpringBoot
    • 工具-Nginx
  • Java
  • 基础篇
舞动的代码
2022-05-17
目录

常用API

# Math

Math 包含执行基本数字运算的方法。Math 类中无构造方法,但内部的方法都是静态的,则可以通过 类名。进行调用

方法名 说明
public static int abs(int a) 返回参数的绝对值
public static double ceil(double a) 返回大于或等于参数的最小 double 值,等于一个整 数
public static double floor(double a) 返回小于或等于参数的最大 double 值,等于一个整 数
public static int round(float a) 按照四舍五入返回最接近参数的 int
public 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)

# System

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

# 案例

需求:在控制台输出 1-10000 ,计算这段代码执行了多少毫秒

public class SystemDemo {
    public static void main(String[] args) {
        // 获 取 开 始 的 时 间 节 点
        long start = System.currentTimeMillis();
        for (int i = 1;i <= 10000; i++) {
            System.out.println(i);
        }
        // 获取代 码 运 行 结 束 后 的 时 间 节 点
        long end = System.currentTimeMillis();
        System.out.println("共 耗 时 : " + (end ­ start) + "毫秒");     }
}

1
2
3
4
5
6
7
8
9
10
11
12

# Arrays

工具类的设计思路

  • 构造方法用 private 修饰

  • 成员用 public static 修饰

方法名 描述
public static String toString(int[] a) 返 返回指定数组的内容的字符串表示形式
public static void sort(int[] a) 按照数字顺序排列指定的数组

# 时间日期

#### Date 类

Date 代表了一个特定的时间,精确到毫秒

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

# SimpleDateFormat 类

SimpleDateFormat 是一个具体的类,用于以区域设置敏感的方式格式化和解析日期。

方法名 说明
public SimpleDateFormat() 构造一个 SimpleDateFormat ,使用默认模式和日期格式
public SimpleDateFormat(Stringpattern) 构造一个 SimpleDateFormat 使用给定的模式和默认的日期格式

# Calendar 类

Calendar 为特定瞬间与一组日历字段之间的转换提供了一些方法,并为操作日历字段提供了一些方法

Calendar 提供了一个类方法 getInstance 用于获取这种类型的一般有用的对象。该方法返回一个 Calendar 对象。

其日历字段已使用当前日期和时间初始化:Calendar rightNow = Calendar.getInstance();

方法名 说明
public int get(int field) 返回给定日历字段的值
public abstract void add(int field, int amount) 根据日历的规则,将指定的时间量添加或减去给定的日 历字段
public final void set(int year,int month,int date) 设置当前日历的年月日

# 案例 - 控制台版的日历

rili

常用API之函数式接口
异常机制

← 常用API之函数式接口 异常机制→

Theme by Vdoing | Copyright © 2013-2023 冀ICP备16006233号-1
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×