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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值