您的位置:首页 > 编程语言 > Java开发

java:通过代码得到服务器和操作系统信息

2011-09-27 17:07 531 查看
In this example we are learn how we can get information about our operation system.

Operating System Information










In this example we are learn how we can get information about our operation system. In this example we are getting the OS name, its version and architecture of OS. We are using
getProperty(String key) to get the property of the OS. To get OS name we have key value
os.name,to get version we have os.version and to get architecture we have
os.orch.

The System class contains several useful class fields and methods. It cannot be instantiated.

The method and its keys:

String getProperty(String key):

This method is used to get the system property.

S/No.KeyDescription
1java.versionThe version of Java Runtime Environment.
2java.vendorThe name of Java Runtime Environment vendor
3java.vendor.urlThe URL of Java vendor
4java.homeThe directory of Java installation
5java.vm.specification.versionThe specification version of Java Virtual Machine
6java.vm.specification.vendorThe name of specification vendor of Java Virtual Machine
7java.vm.specification.nameJava Virtual Machine specification name
8java.vm.versionJVM implementation version
9java.vm.vendorJVM implementation vendor
10java.vm.nameJVM implementation name
11java.specification.versionThe name of specification version Java Runtime Environment
12java.specification.vendorJRE specification vendor
13java.specification.nameJREspecification name
14java.class.versionJava class format version number
15ava.class.pathPath of java class
16java.library.pathList of paths to search when loading libraries
17java.io.tmpdirThe path of temp file
18java.compilerThe Name of JIT compiler to use
19java.ext.dirsThe path of extension directory or directories
20os.nameThe name of OS name
21os.archThe OS architecture
22os.versionThe version of OS
23file.separatorThe File separator
24path.separatorThe path separator
25line.separatorThe line separator
26user.nameThe name of account name user
27user.homeThe home directory of user
28user.dirThe current working directory of the user
The code of the program is given below:

public class
OpertingSystemInfo

{

public static
void main(String[]
args)

{

String nameOS =
"os.name";

String versionOS =
"os.version";

String architectureOS =
"os.arch";

System.out.println("\n The information about OS");

System.out.println("\nName of the OS: "
+

System.getProperty(nameOS));

System.out.println("Version of the OS: "
+

System.getProperty(versionOS));

System.out.println("Architecture of THe OS: "
+

System.getProperty(architectureOS));

}

}
The output of the program is given below:

C:\convert\rajesh\completed>javac OpertingSystemInfo.java

C:\convert\rajesh\completed>java OpertingSystemInfo

The information about OS

Name of the OS: Windows 2000
Version of the OS: 5.0
Architecture of The OS: x86

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐