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

System类

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

System类

System类 源码位置

rt.jar/java.lang包下

源码类
public final class System
认识
System类
概念:表示系统类
类常量:out,err
类方法:
		获取当前时间戳:		currentTimeMillis(1秒=1000毫秒)	
		获取当前纳秒:		nanoTime(1纳秒=0.000001毫秒)
		获取系统环境相关:	getenv
		获取系统属性:		getProperties,getProperty
		数组复制:			arraycopy
		程序退出:			exit(0是正常退出,非0是非正常退出)
		垃圾回收:			gc

这里只介绍其中部分常用方法

类方法
public static native long currentTimeMillis()
public static native long nanoTime()
public static java.util.Map getenv()
public static String getenv(String name)
public static Properties getProperties() 
public static String getProperty(String key)
public static native void arraycopy(Object src,  int  srcPos,Object dest, int destPos,int length)    
public static void exit(int status)
public static void gc()     
例子
//类常量:out,err
System.out.print("HelloWorld");
System.out.println();
System.out.printf("test %d %s", 1,"test");
System.out.println();
System.err.print("HelloWorld");
System.err.println();
System.err.printf("test %d %s", 1,"test");
System.err.println();
//获取当前时间戳
System.out.println(System.currentTimeMillis());
//获取当前纳秒
System.out.println(System.nanoTime());
//获取系统环境相关
Map map = System.getenv();
for (Entry entry : map.entrySet()) {
    System.out.println(entry.getKey() + " => " + entry.getValue());
}

System.out.println("MAVEN_HOME  " + System.getenv("MAVEN_HOME"));
//获取系统属性
for (Entry entry : System.getProperties().entrySet()) {
    System.out.println(entry.getKey().toString() + " => " + entry.getValue().toString());
}

System.out.println(System.getProperty("java.home"));
//数组复制
int[] a = {1,3,5,7,9};
int[] b = new int[4];//{0,0,0,0}
System.arraycopy(a, 1, b, 2, 2);
System.out.println(Arrays.toString(b));
//程序退出
System.exit(1);
//垃圾回收
System.gc();
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/490457.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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