Java 5.20 知识点---常用类

Math 类
直接通过类名调用,数学类中还有两个静态常量PI和E
利用帮助文档,查阅相关方法说明

在这里插入图片描述
random 类
jdk的Java.util包中,指定的取值范围内随机产生数字
使用帮助文档

在这里插入图片描述
使用random类的方法
在这里插入图片描述

包装类
通过包装类将基本数据类型的值包装为引用数据类型的对象
自动装箱、拆箱是包装类进行数据类型转换的方式

在这里插入图片描述
日期与时间类
calendar类:一个抽象类,无法实例化,需要调用静态方法getInstance()得到一个Calender对象
Calender calender=Calender.getInstance();

int get(int field)//返回指定日历字段的值
field参数接收calender类定义的常量值(时间日期等等)
calender类获取计算机日期和时间

在这里插入图片描述
calender日历容错模式和非容错模式
演示案例:
在这里插入图片描述
说明:
常用类中,要学会使用帮助文档:
1、注意类所在的包的导入
2、类是不是抽象类 ,如果是抽象类,存在一个静态方法可以获取该类的对象。不是抽象类 ,则new 一个对象,通过对象调用方法

格式化类
1、DateFormat类
在这里插入图片描述

jdk8版本使用的:——————————————
LocalDateTime date = LocalDateTime.now();
// 1、使用常量创建DateTimeFormatter
System.out.print(“使用常量创建DateTimeFormatter:”);
System.out.println(DateTimeFormatter
.ISO_LOCAL_DATE.format(date));
// 2、使用Long类型风格的DateTimeFormatter
System.out.print(“使用Long类型风格的DateTimeFormatter:”);
DateTimeFormatter dtf = DateTimeFormatter
.ofLocalizedDateTime(FormatStyle.LONG);
System.out.println(dtf.format(date));
// 3、根据模式字符串来创建DateTimeFormatter格式器
System.out.print(“根据模式字符串来创建DateTimeFormatter:”);
DateTimeFormatter formatter = DateTimeFormatter
.ofPattern(“yyyy MM dd HH:mm:ss”);
// 使用LocalDateTime的format()方法格式化
String text = date.format(formatter);
// 使用格式化程序解析文本,返回日期时间
LocalDateTime parsedDate = LocalDateTime.parse(text, formatter);
System.out.println(parsedDate);

运行结果:

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值