miluframe({ /*个人链接地址*/ Youself:'https://www.cnblogs.com/miluluyo/', /*导航栏信息*/ custom:[{ name:'留言板', link:'https://www.cnblogs.com/miluluyo/p/11578505.html', istarget:false },{ name:'技能树', link:'https://miluluyo.github.io/', istarget:true }], /*自己的友链页面后缀*/ Friends_of_the:'p/11633791.html', /*自己的友链信息*/ resume:{ "name":"麋鹿鲁哟", "link":"https://www.cnblogs.com/miluluyo", "headurl":"https://images.cnblogs.com/cnblogs_com/elkyo/1558759/o_o_my.jpg", "introduction":"大道至简,知易行难。" }, /*友链信息*/ unionbox:[{ "name":"麋鹿鲁哟", "introduction":"生活是没有标准答案的。", "url":"https://www.cnblogs.com/miluluyo", "headurl":"https://images.cnblogs.com/cnblogs_com/elkyo/1558759/o_o_my.jpg" },{ "name":"麋鹿鲁哟的技能树", "introduction":"大道至简,知易行难。", "url":"https://miluluyo.github.io/", "headurl":"https://images.cnblogs.com/cnblogs_com/elkyo/1558759/o_o_my.jpg" }], /*点击页面时候的弹出文本显示*/ clicktext:new Array("ヾ(◍°∇°◍)ノ゙加油哟~ ——麋鹿鲁哟","生活是没有标准答案的。 ——麋鹿鲁哟"), /*github链接*/ githuburl:'https://github.com/miluluyo' })

2022 07 28 第三小组 陈迪 学习笔记

Java的值传递和所谓的引用传递

本质上Java只有值传递,所有的赋值传参都是一次值的拷贝。

引用数据类型拷贝的就是引用地址,基本数据类型拷贝的是值,不会传入实例对象。

常用api

API(Application Programming Interface)应用程序接口。

JDK给我们提供的一些已经写好的类,我们可以直接调方法来解决问题。

我们类的方法,在宏观上都可以称为接口。

api文档,介绍api

时间相关api

  • 2个字段(注册时间,最后一次修改时间)
  • 时间:
  • 格林尼治天文台,伦敦
  • 时区:东八区
  • 北京时间:+8
  • 时间戳:1970.1.1 00:00:00 到今天2022.7.28 9:29:30的毫秒数
  • 1s=1000ms 1min=60s 1h=60min 1day=24h 时间戳在全国各地都是固定的。
  • 获取时间戳
  • 可以通过时间戳转换成我们当前所在地的具体时间和日期
日期类
/*
* date
*/
public class Ch03 {
    public static void main(String[]args){
        //获取系统当前日期时间
        Date date= new Date();
        System.out.println(date);
    }
}

当返回负数时,说明调用者时间是在参数时间之前。

当返回0时,调用者时间和参数时间相同。

当返回正数时,说明调用者时间在阐述时间之后。

public class Ch04 {
    public static void main(String[] args) {
        Date date1=new Date();
        Date date2=new Date();
        System.out.println();
    }
}

日历类:日期

  • Calendar是一个抽象类。
  • 初始化:
  • 提供了一组对“年月日时分秒星期”等信息的操作函数。操作不同时区的信息。
  • Calendar要比Date强大的多
时区:偏移量
public class Ch06 {
    public static void main(String[] args) {
     System.out.println(TimeZone.getDefault());
        System.out.println(new Date());
            }
          }

日期格式化

  • simpleDateFormat
  • format:格式化Date类型,把Date类型转成String类型
  • 从客户端传过来的时间,一般都是String类型,存入数据库。
public class Test {
    public static void main(String[] args) {
        Date date=new Date(System.currentTimeMillis()+1000*60*60*24*7);
        System.out.println(date);

    }
}

设计一个工具类

对date类型的日期进行格式化,转成string
format方法 参数是Date 返回值是String
string格式化转换成Date
parse方法 参数是string 返回值是Date

public class Test1 {
public static final String dateToString(){
    return dateToString();
    }
    public static final Date StringToDate() {
    return StringToDate();
    }
}

JDK8的日期时间类

  • 在JDK8之前,处理日期和时间,基本上就是用上面的几个类。
  • Date和Calendar,获取到的月份都是0-11,而不是我们生活中的1--12;

阿里巴巴规约明确要求:

  • 如果是JDK8的应用,可以使用
  • Instant代替Date
  • LocalDateTime代替Calendar
  • DateTimeFormatter代替DateTimeFormat

新的实践类:

  • Instant
  • LocalTime
  • LocalDateTime
  • DateTimeFormatter
  • atzone 在某一个时区
public class Ch01 {
    public static void main(String[] args) {
        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.28 12:23:21";
        Instant parse=Instant.parse(text);
        System.out.println(parse);
    }
}

持续时间Duration

image-20220728201311889

LocalDate:获取当前日期

public class Ch03 {
    public static void main(String[] args) {
        LocalDate now=LocalDate.now();
        System.out.println(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(2022,9,10);
        System.out.println(of);

    }
}
public class Ch04 {
    public static void main(String[] args) {
        Instant instant=Instant.now();
        Date date=Date.from(instant);
        LocalDateTime localDateTime= LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
    }
}

math数学类

  • random()随机数
  • ceil()向上取整
  • floor()向下取整
  • round()四舍五入

BigDecimal统计类

public class Ch06 {
    public static void main(String[] args) {
        BigDecimal bigDecimal=new BigDecimal("0.7");
        BigDecimal bigDecimal1=new BigDecimal("0.1");
        //使用BigDecimal的构造器,开发中,传入的参数必须是字符串
        System.out.println(bigDecimal.add(bigDecimal1));

    }
}

Random 随机

public class Ch07 {
    public static void main(String[] args) {
        Random random=new Random();
        System.out.println(random.nextInt(21));
    }
}

Arrays数组的工具类

public class Ch08 {
    public static void main(String[] args) {
        int arr[]=new int[]{1,2,3,4,5};
        System.out.println(Arrays.toString(arr));
        Arrays.sort(arr);
        System.out.println(Arrays.binarySearch(arr,4));
    }
}

Objects

public class Ch09 {
    public static void main(String[] args) {
        System.out.println(Objects.isNull(""));//阿里规约判断空
    }
}

StringBuffer和StringBuilder

  • 可变的字符序列,和String是有本质区别的;

  • 有缓冲区,从缓存里拿东西

用法一模一样

  • StringBuffer是同步的。安全,效率低。

  • StringBuilder是异步的。不安全,同时处理多个请求。

  • 做开发三大准则:成本,质量,进度。

    面试题:三个字符串的区别

posted @   jinjidecainiao  阅读(23)  评论(1编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· AI 智能体引爆开源社区「GitHub 热点速览」
@media only screen and (max-width: 767px){ #sidebar_search_box input[type=text]{width:calc(100% - 24px)} } L2Dwidget.init({ "model": { jsonPath: "https://unpkg.com/live2d-widget-model-hijiki/assets/hijiki.model.json", "scale": 1 }, "display": { "position": "left", "width": 100, "height": 200, "hOffset": 70, "vOffset": 0 }, "mobile": { "show": true, "scale": 0.5 }, "react": { "opacityDefault": 0.7, "opacityOnHover": 0.2 } }); window.onload = function(){ $("#live2dcanvas").attr("style","position: fixed; opacity: 0.7; left: 70px; bottom: 0px; z-index: 1; pointer-events: none;") } 参数说明 名称 类型 默认值/实例 描述Youself 字符串 https://www.cnblogs.com/miluluyo/ 个人博客园首链接 custom 数组 [{ name:'相册', link:'https://www.cnblogs.com/elkyo/gallery.html', istarget:false },{ name:'技能树', link:'https://miluluyo.github.io/', istarget:true },{ name:'留言板', link:'https://miluluyo.github.io/p/11578505.html', istarget:false }] 导航信息 name 导航名 link 导航链接 istarget true跳转到新页面上,false当前页面打开 Friends_of_the 字符串 11633791 友链文章的后缀名,若字符串为空则不显示友链 resume 对象 { "name":"麋鹿鲁哟", "link":"https://www.cnblogs.com/miluluyo/", "headurl":"https://images.cnblogs.com/cnblogs_com/ elkyo/1558759/o_o_my.jpg", "introduction":"大道至简,知易行难。" } 自己的友链信息 name 导航名 link 导航链接 headurl 头像 introduction 语录 unionbox 数组 [{ "name":"麋鹿鲁哟", "introduction":"生活是没有标准答案的。", "url":"https://www.cnblogs.com/miluluyo", "headurl":"https://images.cnblogs.com/cnblogs_com/ elkyo/1558759/o_o_my.jpg" },{ "name":"麋鹿鲁哟的技能树", "introduction":"大道至简,知易行难。", "url":"https://miluluyo.github.io/", "headurl":"https://images.cnblogs.com/cnblogs_com/ elkyo/1558759/o_o_my.jpg" }] 友链数组 name 昵称 introduction 标语 url 链接地址 headurl 头像地址 clicktext 新数组 new Array("ヾ(◍°∇°◍)ノ゙加油哟~ ——麋鹿鲁哟", "生活是没有标准答案的。 ——麋鹿鲁哟"), 点击页面时候的弹出显示 githuburl 字符串 https://github.com/miluluyo github链接
点击右上角即可分享
微信分享提示