标签:操作 local standard cal 位置 zha nic charset 运行
System类:提供了一些系统属性信息和系统操作。
例如:
(1)currentTimeMillis() 获取当前系统时间,为毫秒值。
public class SystemDemo { public static void main(String[] args) { System.out.println("当前系统的毫秒值为:"+System.currentTimeMillis()); } }
可用于时间测量:
public class TimeDemo{ public static void main(String[] args){ long startTime=System.currentTimeMillis(); int a = 0; for(long i=0;i<999999999;i++){ a++;; } long endTime=System.currentTimeMillis(); System.out.println("执行此程序用了"+(endTime-startTime)+"毫秒。"); } }
(2)exit(int status)
参数传入一个数字即可,通常记为传入0为正常状态,其他为异常状态。
public class ExitDemo { public static void main(String[] args) { for (int i = 0; i <= 99; i++) { if (i < 9) System.out.println(i); else System.exit(0); } System.out.println("System类"); } }
由运行结果可知,在执行了System.exit(0);后,程序直接结束运行,没有去运行后面的 System.out.println("System类");语句。
(3)gc();
运行JVM中的垃圾回收器。
class Person { public void finalize() { // 清除垃圾时,会默认调用被清空对象的finalize方法。 System.out.println("垃圾已经被收取啦!"); } }
public class PersonTest { public static void main(String[] args) { new Person(); new Person(); new Person(); new Person(); new Person(); new Person(); new Person(); System.gc(); } }
(4)getProperties()
public class GetPropertiesDemo { public static void main(String[] args) { System.out.println(System.getProperties()); } } {java.runtime.name=Java(TM) SE Runtime Environment, sun.boot.library.path=D:\Program Files (x86)\Eclipse\MyEclipse\Common\binary\com.sun.java.jdk.win32.x86_64_1.6.0.013\jre\bin, java.vm.version=11.3-b02, java.vm.vendor=Sun Microsystems Inc., java.vendor.url=http://java.sun.com/, path.separator=;, java.vm.name=Java HotSpot(TM) 64-Bit Server VM, file.encoding.pkg=sun.io, sun.java.launcher=SUN_STANDARD, user.country=CN, sun.os.patch.level=, java.vm.specification.name=Java Virtual Machine Specification, user.dir=D:\Workspaces\MyEclipse 10\System类, java.runtime.version=1.6.0_13-b03, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=D:\Program Files (x86)\Eclipse\MyEclipse\Common\binary\com.sun.java.jdk.win32.x86_64_1.6.0.013\jre\lib\endorsed, os.arch=amd64, java.io.tmpdir=C:\Users\zhai\AppData\Local\Temp\, line.separator= , java.vm.specification.vendor=Sun Microsystems Inc., user.variant=, os.name=Windows Vista, sun.jnu.encoding=GBK, java.library.path=D:\Program Files (x86)\Eclipse\MyEclipse\Common\binary\com.sun.java.jdk.win32.x86_64_1.6.0.013\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;"C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\SysWOW64;D:\Program Files (x86)\apache-tomcat-9.0.10\lib;D:\Program Files (x86)\apache-tomcat-9.0.10\bin;D:\Program Files (x86)\Eclipse\Jdk;D:\Program Files (x86)\Eclipse\Jdk\jre";C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;D:\Program Files (x86)\Sql Server2008\sql server\100\Tools\Binn\;D:\Program Files (x86)\Sql Server2008\100\Tools\Binn\;D:\Program Files (x86)\Sql Server2008\100\DTS\Binn\;D:\Program Files (x86)\Sql Server2008\sql server\100\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\;D:\Program Files (x86)\Sql Server2008\sql server\100\DTS\Binn\;D:\Program Files (x86)\Eclipse\Jdk\bin;D:\Program Files (x86)\mysql\bin;"SystemRoot%System32;C:\WindowsSystem32WindowsPowerShellv1.0";, java.specification.name=Java Platform API Specification, java.class.version=50.0, sun.management.compiler=HotSpot 64-Bit Server Compiler, os.version=6.2, user.home=D:, user.timezone=, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=GBK, java.specification.version=1.6, java.class.path=D:\Workspaces\MyEclipse 10\System类\bin, user.name=zhai, java.vm.specification.version=1.0, java.home=D:\Program Files (x86)\Eclipse\MyEclipse\Common\binary\com.sun.java.jdk.win32.x86_64_1.6.0.013\jre, sun.arch.data.model=64, user.language=zh, java.specification.vendor=Sun Microsystems Inc., awt.toolkit=sun.awt.windows.WToolkit, java.vm.info=mixed mode, java.version=1.6.0_13, java.ext.dirs=D:\Program Files (x86)\Eclipse\MyEclipse\Common\binary\com.sun.java.jdk.win32.x86_64_1.6.0.013\jre\lib\ext;C:\Windows\Sun\Java\lib\ext, sun.boot.class.path=D:\Program Files (x86)\Eclipse\MyEclipse\Common\binary\com.sun.java.jdk.win32.x86_64_1.6.0.013\jre\lib\resources.jar;D:\Program Files (x86)\Eclipse\MyEclipse\Common\binary\com.sun.java.jdk.win32.x86_64_1.6.0.013\jre\lib\rt.jar;D:\Program Files (x86)\Eclipse\MyEclipse\Common\binary\com.sun.java.jdk.win32.x86_64_1.6.0.013\jre\lib\sunrsasign.jar;D:\Program Files (x86)\Eclipse\MyEclipse\Common\binary\com.sun.java.jdk.win32.x86_64_1.6.0.013\jre\lib\jsse.jar;D:\Program Files (x86)\Eclipse\MyEclipse\Common\binary\com.sun.java.jdk.win32.x86_64_1.6.0.013\jre\lib\jce.jar;D:\Program Files (x86)\Eclipse\MyEclipse\Common\binary\com.sun.java.jdk.win32.x86_64_1.6.0.013\jre\lib\charsets.jar;D:\Program Files (x86)\Eclipse\MyEclipse\Common\binary\com.sun.java.jdk.win32.x86_64_1.6.0.013\jre\classes, java.vendor=Sun Microsystems Inc., file.separator=\, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, sun.desktop=windows, sun.cpu.isalist=amd64}
(5)arraycopy
src:源数组名
srcPos:要复制的源数组的起始位置
dest:目标数组名
destPos:目标数组的起始位置
length:复制的元素的个数
将数组a中的第二个元素,复制到数组b的最后一个位置。
public class ArrayCopyDemo { public static void main(String[] args) { int [] a=new int[]{1,2,3,4,5,6}; int [] b=new int[]{1,2,3,4,5,6,6,6,6,6}; System.arraycopy(a, 1, b, 9, 1); for(int i=0;i<b.length;i++){ System.out.print(b[i]); } } }
标签:操作 local standard cal 位置 zha nic charset 运行
原文地址:https://www.cnblogs.com/zhai1997/p/11352490.html