java源码分析:从System类中获取系统关键属性信息

我们来看一下java系统关键类System:public final class System,这是一个final类型的类,不能被继承。


/**
 * The <code>System</code> class contains several useful class fields
 * and methods. It cannot be instantiated.
 *
 * <p>Among the facilities provided by the <code>System</code> class
 * are standard input, standard output, and error output streams;
 * access to externally defined properties and environment
 * variables; a means of loading files and libraries; and a utility
 * method for quickly copying a portion of an array.
 *
 * @version 1.159, 11/27/07
 * @since   JDK1.0
 */


我们可以通过System.getProperties();获取java的一些关键信息和方法,例如通过以下代码,我们可以获取本机的JDK的环境变量:


public class GetJavaPath {

	public static void main(String[] args) {
		//获取JDK安装路径
		System.out.println("System.getProperty(‘java.library.path’):" + System.getProperty("java.library.path"));
	}
}

通过
System.getPropertys()能够获得哪些信息呢,

<pre name="code" class="java">public class GetJavaPath {

	public static void main(String[] args) {
		//获取JDK安装路径
		System.out.println("System.getPropertys():" + System.getPropertys());
	}
}

下面是我运行以后获得的运行结果:

{
java.runtime.name=Java(TM) SE Runtime Environment, 
sun.boot.library.path=E:\myeclipse\myeclipse10InstallFile\Common\binary\com.sun.java.jdk.win32.x86_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) Client VM, 
file.encoding.pkg=sun.io, 
sun.java.launcher=SUN_STANDARD, 
user.country=CN, 
sun.os.patch.level=Service Pack 3, 
java.vm.specification.name=Java Virtual Machine Specification, 
user.dir=E:\myeclipse\myeclipse10InstallFile\Spring, 
java.runtime.version=1.6.0_13-b03, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=E:\myeclipse\myeclipse10InstallFile\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\jre\lib\endorsed, 
os.arch=x86, 
java.io.tmpdir=C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\, 
line.separator=, 
java.vm.specification.vendor=Sun Microsystems Inc., 
user.variant=, 
os.name=Windows XP, 
sun.jnu.encoding=GBK, 
java.library.path=E:\myeclipse\myeclipse10InstallFile\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.01\bin;.;
C:\WINDOWS\Sun\Java\bin;
C:\WINDOWS\system32;
C:\WINDOWS;
E:/myeclipse/myeclipse10InstallFile/Common/binary/com.sun.java.jdk.win32.x86_1.6.0.013/jre/bin/client;
E:/myeclipse/myeclipse10InstallFile/Common/binary/com.sun.java.jdk.win32.x86_1.6.0.013/jre/bin;
E:/myeclipse/myeclipse10InstallFile/Common/binary/com.sun.java.jdk.win32.x86_1.6.0.013/jre/lib/i386;
C:\WINDOWS\system32;C:\WINDOWS;
C:\WINDOWS\System32\Wbem;
C:\Program Files\Common Files\Thunder Network\KanKan\Codecs;
E:\mysql5.5\mysql5InstallFile\bin;
E:\JDKInstallFile\Program Files\Java\jdk1.7.0_79\bin;
E:\JDKInstallFile\Program Files\Java\jdk1.7.0_79\jre\bin, 
java.specification.name=Java Platform API Specification, 
java.class.version=50.0, 
sun.management.compiler=HotSpot Client Compiler, 
os.version=5.1, 
user.home=C:\Documents and Settings\Administrator, 
user.timezone=, 
java.awt.printerjob=sun.awt.windows.WPrinterJob, 
file.encoding=GBK, 
java.specification.version=1.6, 
java.class.path=
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\classes;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\aopalliance1.0.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\aspectjweaver-1.5.0.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\cglib-nodep-2.1_3.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\commons-codec-1.3.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\commons-collections-3.1.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\commons-dbcp.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\commons-fileupload-1.2.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\commons-io-1.4.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\commons-lang-2.2.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\commons-logging-1.0.4.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\commons-pool.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\gson-2.2.4.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\httpcore-4.3.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\jackson-core-asl-1.9.13.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\jackson-mapper-asl-1.9.13.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\jaudiotagger-2.2.0-20130321.145334-2.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\json-lib-2.3-jdk15.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\jstl.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\log4j-1.2.17.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\slf4j-api-1.6.6.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\slf4j-log4j12-1.6.6.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\spring-aop-3.2.5.RELEASE.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\spring-beans-3.2.5.RELEASE.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\spring-context-3.2.5.RELEASE.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\spring-context-support-3.2.5.RELEASE.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\spring-core-3.2.5.RELEASE.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\spring-expression-3.2.5.RELEASE.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\spring-jdbc-3.2.5.RELEASE.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\spring-jms-3.2.5.RELEASE.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\spring-orm-3.2.5.RELEASE.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\spring-test-3.2.5.RELEASE.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\spring-tx-3.2.5.RELEASE.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\spring-web-3.2.5.RELEASE.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\spring-webmvc-3.2.5.RELEASE.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\spring-webmvc-portlet-3.2.5.RELEASE.jar;
E:\myeclipse\myeclipse10InstallFile\Spring\WebRoot\WEB-INF\lib\standard.jar;
E:\SSH整合\SSH整合完整项目-MyEclipse10\MySQL数据库驱动\mysql-connector-java-5.1.10-bin.jar, 
user.name=Administrator, 
java.vm.specification.version=1.0, 
java.home=E:\myeclipse\myeclipse10InstallFile\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\jre, 
sun.arch.data.model=32, 
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=E:\myeclipse\myeclipse10InstallFile\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\jre\lib\ext;C:\WINDOWS\Sun\Java\lib\ext, 
sun.boot.class.path=
E:\myeclipse\myeclipse10InstallFile\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.01\jre\lib\resources.jar;
E:\myeclipse\myeclipse10InstallFile\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.01\jre\lib\rt.jar;
E:\myeclipse\myeclipse10InstallFile\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\jre\lib\sunrsasign.jar;
E:\myeclipse\myeclipse10InstallFile\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\jre\lib\jsse.jar;
E:\myeclipse\myeclipse10InstallFile\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\jre\lib\jce.jar;
E:\myeclipse\myeclipse10InstallFile\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\jre\lib\charsets.jar;
E:\myeclipse\myeclipse10InstallFile\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\jre\classes;
E:\myeclipse\myeclipse10InstallFile\Common\plugins\com.genuitec.eclipse.j2eedt.core_10.5.0.me201207171805\data\libraryset\EE_6\bean-validator.jar;
E:\myeclipse\myeclipse10InstallFile\Common\plugins\com.genuitec.eclipse.j2eedt.core_10.5.0.me201207171805\data\libraryset\EE_\javax.annotation.jar;
E:\myeclipse\myeclipse10InstallFile\Common\plugins\com.genuitec.eclipse.j2eedt.core_10.5.0.me201207171805\data\libraryset\EE_6\javax.ejb.jar;
E:\myeclipse\myeclipse10InstallFile\Common\plugins\com.genuitec.eclipse.j2eedt.core_10.5.0.me201207171805\data\libraryset\EE_6\javax.enterprise.deploy.jar;
E:\myeclipse\myeclipse10InstallFile\Common\plugins\com.genuitec.eclipse.j2eedt.core_10.5.0.me201207171805\data\libraryset\EE_6\javax.jms.jar;
E:\myeclipse\myeclipse10InstallFile\Common\plugins\com.genuitec.eclipse.j2eedt.core_10.5.0.me201207171805\data\libraryset\EE_\javax.management.j2ee.jar;
E:\myeclipse\myeclipse10InstallFile\Common\plugins\com.genuitec.eclipse.j2eedt.core_10.5.0.me201207171805\data\libraryset\EE_6\javax.persistence.jar;
E:\myeclipse\myeclipse10InstallFile\Common\plugins\com.genuitec.eclipse.j2eedt.core_10.5.0.me201207171805\data\libraryset\EE_6\javax.resource.jar;
E:\myeclipse\myeclipse10InstallFile\Common\plugins\com.genuitec.eclipse.j2eedt.core_10.5.0.me201207171805\data\libraryset\EE_6\javax.security.auth.message.jar;
E:\myeclipse\myeclipse10InstallFile\Common\plugins\com.genuitec.eclipse.j2eedt.core_10.5.0.me201207171805\data\libraryset\EE_6\javax.security.jacc.jar;
E:\myeclipse\myeclipse10InstallFile\Common\plugins\com.genuitec.eclipse.j2eedt.core_10.5.0.me201207171805\data\libraryset\EE_6\javax.servlet.jar;
E:\myeclipse\myeclipse10InstallFile\Common\plugins\com.genuitec.eclipse.j2eedt.core_10.5.0.me201207171805\data\libraryset\EE_\javax.servlet.jsp.jar;
E:\myeclipse\myeclipse10InstallFile\Common\plugins\com.genuitec.eclipse.j2eedt.core_10.5.0.me201207171805\data\libraryset\EE_6\javax.servlet.jsp.jstl.jar;
E:\myeclipse\myeclipse10InstallFile\Common\plugins\com.genuitec.eclipse.j2eedt.core_10.5.0.me201207171805\data\libraryset\EE_6\javax.transaction.jar;
E:\myeclipse\myeclipse10InstallFile\Common\plugins\com.genuitec.eclipse.j2eedt.core_10.5.0.me201207171805\data\libraryset\EE_6\jaxb-api-osgi.jar;
E:\myeclipse\myeclipse10InstallFile\Common\plugins\com.genuitec.eclipse.j2eedt.core_10.5.0.me201207171805\data\libraryset\EE_6\jsf-api.jar;
E:\myeclipse\myeclipse10InstallFile\Common\plugins\com.genuitec.eclipse.j2eedt.core_10.5.0.me201207171805\data\libraryset\EE_6\jsf-impl.jar;
E:\myeclipse\myeclipse10InstallFile\Common\plugins\com.genuitec.eclipse.j2eedt.core_10.5.0.me201207171805\data\libraryset\EE_6\jsr311-api.jar;
E:\myeclipse\myeclipse10InstallFile\Common\plugins\com.genuitec.eclipse.j2eedt.core_10.5.0.me201207171805\data\libraryset\EE_6\jstl-impl.jar;
E:\myeclipse\myeclipse10InstallFile\Common\plugins\com.genuitec.eclipse.j2eedt.core_10.5.0.me201207171805\data\libraryset\EE_6\mail.jar;
E:\myeclipse\myeclipse10InstallFile\Common\plugins\com.genuitec.eclipse.j2eedt.core_10.5.0.me201207171805\data\libraryset\EE_6\webservices-api-osgi.jar;
E:\myeclipse\myeclipse10InstallFile\Common\plugins\com.genuitec.eclipse.j2eedt.core_10.5.0.me201207171805\data\libraryset\EE_6\weld-osgi-bundle.jar, 
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=pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86
}


 
 

你可能感兴趣的:(java,java编程,java基础知识)