System类及Math类概述

System类概述

System表示当前运行的JVM,System提供了标准输入,标准输出和错误输出流对象

1.对外部定义的属性和环境变量的访问;

2.加载文件和库的方法;

3.还有快速复制数组的一部分的实用方法;

4.以及获取系统时间和显示告知垃圾回收器回收垃圾释放内存空间的方法

System是只读的不能被实例化

System实用方法1

获取输入,输出流:

System.out获取标准输出流

System.in获取标准的输入流

System.err获取错误输出流

public static void exit(int status)//退出系统
public static void gc()//通知垃圾回收系统期望快速回收垃圾以释放内存空间
public static long currentTimeMillis()//获取当前系统时间毫秒显示
public static Properties getProperties()//获取当前系统属性map集合
public static String getProperty (String key)//按照给定的名称获取当前系统属性字符串表示

实体类:

package com.ax.pojo;

public class User {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public User() {
    }

    public User(String name) {
        this.name = name;
    }
}

测试类:

package com.ax.test;

import com.ax.pojo.User;

public class TestSystemClass {
    public static void main(String[] args) {
        User[] usersList = new User[100000];
        long begin = System.currentTimeMillis();//开始时间
        for (int i = 0; i < 100000; i++) {
            usersList[i] = new User("用户"+i);
        }
        long end = System.currentTimeMillis();//结束时间
        System.out.println("存储100000个User对象用时:"+(end - begin)+"毫秒");//存储100000个User对象用时:39毫秒
    }
}
System实用方法2
public static native void arraycopy(Object src,int srcPos,Object dest,int destPos,int lenght)//复制数组
public static Map <String,String>getenv()//获取当前JVM所在本地系统信息视图
package com.ax.test;

import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class TestSystemClass1 {
    public static void main(String[] args) {
        //查看当前系统JVM信息
        Properties properties = System.getProperties();
        //System.out.println(properties.toString());
        //拷贝数组
        int []srcs = {1,2,3,4,5,6,7,8,9};
        int []dest = new int[srcs.length-2];

        System.arraycopy(srcs,1,dest,0,dest.length);
        for(int n:dest){
            System.out.print(n+" ");
        }

        //利用system获取本地计算机信息
        Map<String ,String> maps = System.getenv();
        Set<String > keys = maps.keySet();//获取所有信息名称

        for (String name:keys){
            System.out.println(name+" = "+maps.get(name));
        }
    }
}

Math计算类功能应用

Math类定义了数学运算的基本功能,Math类中所有属性及功能方法都定义为static的,Math类不需要创建实例,Math类是final修饰的终极类,不能被继承

Math类常量字段

public static final double E//自然对数的底数,通常用于科学领域的计算使用
public static final double PI//圆的周长和直径的比,即圆周率表示值(3.141592653589793)
package com.ax.test;

public class TestMath {
    public static void main(String[] args) {
        System.out.println("自然对数的底数"+Math.E);//自然对数的底数2.718281828459045
        System.out.println("圆周率"+Math.PI);//圆周率3.141592653589793

        System.out.println(Math.sqrt(5));//2.23606797749979
        System.out.println(Math.ceil(3.4));//4.0
        System.out.println(Math.floor(3.6));//3.0


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值