java基础学习12(System Date Math)

System

常用函数

  • arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
    src - 源数组
    srcPos - 源数组中的起始位置
    dest - 目标数组
    destPos - 目标数据中的起始位置
    length - 要复制的数组元素的数量
  • currentTimeMillis() 获取当前系统时间
  • exit(int status) 退出jvm 参数0表示正常退出jvm,非0表示异常退出jvm
  • gc() 建议jvm赶快启动垃圾回收期回收垃圾
  • getProperties() 获取所有系统变量
  • getProperty(key) 根据key获取系统变量
  • getenv() 获取所有环境变量
  • getenv(String name) 根据key获取环境变量
class Student{
    public Student(){}


    @Override
    protected void finalize() throws Throwable {
        System.out.println("被回收");
    }
}


public class Test {

    public static void main(String[] args) throws Exception {
        //获取系统时间
        System.out.println(System.currentTimeMillis());

        //数组拷贝
        int[] arr1 = {1,3,5,7,9};
        int[] arr2 = {2,4,6,8,10};
        System.arraycopy(arr1,1,arr2,1,3);
        System.out.println(Arrays.toString(arr1));//[1, 3, 5, 7, 9]
        System.out.println(Arrays.toString(arr2));//[2, 3, 5, 7, 10]

        //推出jvm
        System.exit(0);
        System.out.println("1111");

        //建议gc启动
        for (int i = 0; i<4; i++){
            Student s = new Student();
            System.gc();
        }


        //获取系统变量
        Properties properties = System.getProperties();
        properties.list(System.out);

        //根据key获取获取系统变量
        System.out.println(System.getProperty("JAVA_HOME"));

        //获取环境变量
        Map<String, String> env = System.getenv();
        Set<Map.Entry<String, String>> entries = env.entrySet();
        for (Map.Entry<String, String> entry:entries) {
            System.out.println(entry.getKey()+"----"+entry.getValue());
        }

        //根据key获取环境变量
        System.out.println(System.getenv("JAVA_HOME"));
    }
}

RunTime

该类类主要代表了应用程序运行的环境。

  • getRuntime() 返回当前应用程序的运行环境对象。
  • exec(String command) 根据指定的路径执行对应的可执行文件。
  • freeMemory() 以字节为单位返回 Java 虚拟机中的空闲内存量。
  • maxMemory() 以字节为单位返回 Java 虚拟机试图使用的最大内存量。
  • totalMemory() 以字节为单位返回 Java 虚拟机中的内存总量
public class Test {

    public static void main(String[] args) throws Exception {
        Runtime runtime = Runtime.getRuntime();
		Process process = runtime.exec("C:\\Windows\\notepad.exe");
		Thread.sleep(3000); //让当前程序停止3秒。
		process.destroy();
        System.out.println(" Java虚拟机中的空闲内存量。"+runtime.freeMemory());
        System.out.println("Java 虚拟机试图使用的最大内存量:"+ runtime.maxMemory());
        System.out.println("返回 Java 虚拟机中的内存总量:"+ runtime.totalMemory());
    }
}    

日期类

SimpleDateFormat中常用的常量
在这里插入图片描述```
public class Test {

public static void main(String[] args) throws Exception {
    Date date = new Date();
    System.out.println(date.getTime());

    Calendar calendar = Calendar.getInstance();
    System.out.println(calendar.get(Calendar.YEAR));
    System.out.println(calendar.get(Calendar.MONTH)+1);
    System.out.println(calendar.get(Calendar.DATE));
    System.out.println(calendar.get(Calendar.HOUR));
    System.out.println(calendar.get(Calendar.MINUTE));
    System.out.println(calendar.get(Calendar.SECOND));


    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
    String dateTime = simpleDateFormat.format(new Date());
    System.out.println(dateTime);//2019年08月23日 14时42分19秒
	
	//parse函数在使用时参数格式必须与SimpleDateFormat在构造时传递的参数格式保持一致
    Date d = simpleDateFormat.parse("2019年08月23日 14时42分19秒");//Fri Aug 23 14:42:19 CST 2019
    System.out.println(d);


}

 # Math 
 数学类, 主要是提供了很多的数学公式。
 
 - abs(double a)  获取绝对值
 - ceil(double a)  向上取整
 - floor(double a)  向下取整
 - round(float a)   四舍五入
 - random()   产生一个随机数. 大于等于 0.0 且小于 1.0 的伪随机 double 值

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值