栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

java System和Runtime注意项总结

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java System和Runtime注意项总结

package test;

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

public class test6 {
    public static void main(String[] args) {
        time();
        property();
        copy();
    }
//System
//          系统属性相关:getProperties getProperty(String key)
//          时间相关:返回值long 代表从19**到现在的时间间隔
//          数组copy:可能发生数组越界异常
    public static void property() {
        Properties properties = System.getProperties();
        System.out.println(properties);
        //
        Set propertynames = properties.stringPropertyNames();
        for (String key : propertynames) {
            System.out.println(key + "----->" + System.getProperty(key));
        }
    }


    public static void time() {
        long startTime = System.currentTimeMillis();
        int sum = 0;
        for (int i = 0; i < 100000000; i++) {
            sum += i;
        }
        long endTime = System.currentTimeMillis();
        System.out.println("程序运行时间为:" + (endTime - startTime));
    }


    public static void copy() {
        int[] source = {102, 102, 103, 104, 105, 106};
        int[] target = {201, 202, 203, 204, 205, 206, 207};
        System.arraycopy(source, 2, target, 3, 4);//可能发生数组越界
        for (int i = 0; i < target.length; i++) {
            System.out.println(i + ":" + target[i]);
        }
    }
}

package test;

public class test7 {
    public static void main(String[] args) {
//Runtime
//          功能:对应当前JAVA程序对应的虚拟机环境,可以获取JAVA虚拟机占据的内存等信息
        Runtime runtime = Runtime.getRuntime();

        System.out.println(runtime.totalMemory());

        System.out.println(runtime.maxMemory());

        System.out.println(runtime.freeMemory());

        System.out.println(runtime.availableProcessors());
    }

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/327990.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号