今日学习内容:
1.java的值传递和所谓的引用传递
本质上Java只有值传递,所有的赋值传参都是一次值得拷贝
引用数据类型拷贝的就是引用地址,基本数据类型拷贝的是值,不会传入实例
2.常用API(Application Programming Interface)应用程序接口
JDK给我们提供的一些已经写好的类,可以直接调方法解决问题
String
我们类的方法在宏观上就可以称为接口
3.日期类(Date)
Date date=new Date(); System.out.println(date);
4.
Date date1=new Date(1658974415756L);//10:13 Date date2=new Date(); // System.out.println(date2.after(date1)); /** * 当返回负数时,说明调用者时间是在参数时间之前 * 当返回0时,调用者时间和参数时间相同 * 当返回正数时,说明调用者时间是在参数时间之后 */ System.out.println(date1.compareTo(date2));
5.日历类:日期
Calendar calendar =Calendar.getInstance(); System.out.println(calendar.get(Calendar.YEAR)); System.out.println(calendar.get(Calendar.DAY_OF_YEAR)); System.out.println(calendar.get(Calendar.DAY_OF_WEEK)); System.out.println(calendar.get(Calendar.MONTH)); System.out.println(calendar.get(Calendar.HOUR)); System.out.println(calendar.get(Calendar.HOUR_OF_DAY)); System.out.println(calendar.get(Calendar.MILLISECOND));
6.时区:
System.out.println(TimeZone.getDefault()); Calendar calendar=Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("GMT-8:00"));
7.ZoneId
ZoneId zoneId=ZoneId.of("America /New_York"); System.out.println(TimeZone.getTimeZone(zoneId));
8.日期格式化:
SimpleDateFormat
Date date=new Date(); System.out.println(date); /** * yyyy:代表年 * yy:年的后两位 * MM:月 * dd:日 * HH:小时24小时制 * hh:小时12小时制 * mm:分 * ss:秒 * SSS:毫秒 */ SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日"); String s = sdf.format(date); System.out.println(s);
9.
Instant instant=Instant.now(); System.out.println(instant.atZone(ZoneId.systemDefault())); //获取纪元秒数 System.out.println(instant.getEpochSecond()); //获取毫秒数 System.out.println(instant.toEpochMilli()); long millis=System.currentTimeMillis(); System.out.println(Instant.ofEpochMilli(millis)); System.out.println("--------------------------------------"); String text="2022-07-28T14:06:50.174Z"; Instant parse=Instant.parse(text); System.out.println(parse);
10.持续时间:
Instant instant=Instant.now(); Instant plus = instant.plus(Duration.ofDays(5)); System.out.println(plus);
11.
LocalDate:获取当前日期
LocalDate now=LocalDate.now(); System.out.println(now); System.out.println(now.getMonth()); System.out.println(now.getDayOfWeek()); System.out.println(now.getDayOfMonth()); LocalDate of = LocalDate.of(2024, 5, 6); System.out.println(of); //判断是否为闰年 // 能被4整除不被100,被400整除 System.out.println(of.isLeapYear());
12.
LocalTime获取本地时间
LocalTime now=LocalTime.now(); System.out.println(now);
13.
LocalDateTime:获取日期和时间
System.out.println(LocalDateTime.now());
14.
DateTimeFormatter处理日期格式化问题
LocalDate now=LocalDate.now(); DateTimeFormatter dateTimeFormatter=DateTimeFormatter.ofPattern("yyyy/MM/dd"); System.out.println(now.format(dateTimeFormatter));
15.
BigDecimal统计类
BigDecimal bigDecimal1=new BigDecimal("0.7"); BigDecimal bigDecimal2=new BigDecimal("0.1"); System.out.println(bigDecimal1.add(bigDecimal2));
16.
随机 * Random
Random random=new Random(); System.out.println(random.nextInt(2));
17.
Arrays数组工具类
int []arr=new int[]{1,2,3,4,5,6}; System.out.println(Arrays.toString(arr)); Arrays.sort(arr); System.out.println(Arrays.binarySearch(arr,4)); int [] ints=Arrays.copyOf(arr,2); System.out.println(Arrays.toString(ints)); System.out.println(Arrays.equals(arr, ints));
18.
System类 * 系统类
Properties properties = System.getProperties(); System.out.println(properties);
19.
Objects
System.out.println(Objects.isNull(""));
20.
StringBuffer和StringBuilder * 可变的字符序列,和String是有本质区别的 * * String怎么反转??? * * StringBuffer是同步的。安全,效率低 * StringBuilder是异步的。不安全。效率高
StringBuffer stringBuffer = new StringBuffer("你好"); // System.out.println(stringBuffer); stringBuffer.append(",我好").append(",大家好"); // System.out.println(stringBuffer); // stringBuffer.delete(4,7); // stringBuffer.deleteCharAt(0); // stringBuffer.insert(1,"哈哈"); stringBuffer.reverse(); System.out.println(stringBuffer); // String str = "hello"; // String s = str.concat(",world!!"); // System.out.println("str = " + str); // System.out.println("s = " + s); }