System类对读者来说并不陌生,因为在之前所学知识中,需要打印结果时,
使用的都是“System.out.println();”语句,
这句代码中就使用了System类。System类定义了一些与系统相关的属性和方法,
它所提供的"属性和方法都是静态的",因此,想要引用这些属性和方法,直接使用System类调用即可。
System类:和系统相关的类
成员方法:
1.static long currentTimeMillis ()获取当前系统时问(单位毫秒)
2.static void exit (int status)退出JVM,非0表示异常终止
3.static void gc ()运行垃圾回收器,自动调用finalize()方法
4.static Properties getProperties()获取系统相关信息
5.static String getProperty(String Key )获取指定的系统信息
比较重要,此方法作用是:复制数组 :static void arraycopy (源数组,源数组起始索引,目标数组,目标数组起始索引,数量)
package sk;
public class zuoye5 {
public static void main(String[] args){
1 .long time=System.currentTimeMillis(); 获取当前系统时问(单位毫秒)
System.out.println(time); //结果:1683356388646(当前系统时间)
2. static void exit (int status) 退出JVM,非0表示异常终止
System.exit(0); //遇到0正常终止
System.out.println("是否运行");//无法运行此句
3. static void gc ()运行垃圾回收器,自动调用finalize()方法 //了解即可
4. static Properties getProperties()获取多个系统相关信息
Properties pop=System.getProperties();
System.out.print(pop);//打印出电脑系统相关信息
static String getProperty(String Key)获取指定的系统信息
String name=System.getProperty("os.name");//获取系统信号(名字)
System.out.println(name);//运行结果:Windows 10
5. static void arraycopy (源数组,源数组起始索引,目标数组,目标数组起始索引,数量)复制数组
int arr1[]={11,22,33,44,89,98,67,45};//静态创建数组
int arr2[]=new int[8];//动态创建数组0 0 0 0 0 0 0 0
System.arraycopy(arr1,1 , arr2, 1, 3);//将22 33 44元素 赋值给arr2数组
for(int i=0;i<arr2.length;i++)
{System.out.print(arr2[i]);}//运行结果:0 22 33 44 0 0 0 0
}
}
Java System类(和系统相关的类)
最新推荐文章于 2024-05-16 10:23:10 发布