System
System类中的方法都是静态的
方法都是使用static定义的,所以在使用时直接使用类名称就可以调用,如:System.gc()
范例:计算一个程序的执行时间
public class test3 { public static void main(String[] args) { long startTime = System.currentTimeMillis(); int sum = 0; for (int i = 0; i < 30000000; i++) { sum += i; } long endTime = System.currentTimeMillis(); System.out.println(endTime - startTime); } }
结果:
29
范例:取得本机的全部环境属性
public class test3 { public static void main(String[] args) { long startTime = System.currentTimeMillis(); int sum = 0; for (int i = 0; i < 30000000; i++) { sum += i; } long endTime = System.currentTimeMillis(); System.out.println(endTime - startTime); System.getProperties().list(System.out); } }
31
-- listing properties --
java.runtime.name=Java(TM) SE Runtime Environment
sun.boot.library.path=C:\Program Files (x86)\Java\jre6\bin
java.vm.version=11.0-b15
java.vm.vendor=Sun Microsystems Inc.
java.vendor.url=http://java.sun.com/
path.separator=;
java.vm.name=Java HotSpot(TM) Client VM
file.encoding.pkg=sun.io
user.country=CN
sun.java.launcher=SUN_STANDARD
sun.os.patch.level=
java.vm.specification.name=Java Virtual Machine Specification
user.dir=E:\javawork\test9
java.runtime.version=1.6.0_10-rc2-b32
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs=C:\Program Files (x86)\Java\jre6\lib\...
os.arch=x86
java.io.tmpdir=C:\Users\ADMINI~1\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=C:\Program Files (x86)\Java\jre6\bin;...
java.specification.name=Java Platform API Specification
java.class.version=50.0
sun.management.compiler=HotSpot Client Compiler
os.version=6.1
user.home=C:\Users\Administrator
user.timezone=
java.awt.printerjob=sun.awt.windows.WPrinterJob
file.encoding=GBK
java.specification.version=1.6
user.name=Administrator
java.class.path=E:\javawork\test9\bin
java.vm.specification.version=1.0
sun.arch.data.model=32
java.home=C:\Program Files (x86)\Java\jre6
java.specification.vendor=Sun Microsystems Inc.
user.language=zh
awt.toolkit=sun.awt.windows.WToolkit
java.vm.info=mixed mode, sharing
java.version=1.6.0_10-rc2
java.ext.dirs=C:\Program Files (x86)\Java\jre6\lib\...
sun.boot.class.path=C:\Program Files (x86)\Java\jre6\lib\...
java.vendor=Sun Microsystems Inc.
file.separator=\
java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport...
sun.cpu.endian=little
sun.io.unicode.encoding=UnicodeLittle
sun.desktop=windows
sun.cpu.isalist=pentium_pro+mmx pentium_pro pentium+m...
********************
可以用gc()来进行垃圾的回收,