Monday 28 April 2014

Get the Machine Details in Java


import java.net.*;
public class SystemDetails {
    
    public static String getSystemDetails()throws Exception{
        
        String details ="";
        String nameOS = "os.name";  
        String versionOS = "os.version";  
        String architectureOS = "os.arch";
        String userName = System.getProperty("user.name");
        InetAddress addr = InetAddress.getLocalHost();
        
        details = details + "Name of the OS: ";
        details = details + System.getProperty(nameOS) +"\n";
    
        details = details + "Version of the OS: ";
        details = details + System.getProperty(versionOS) +"\n";
    
        details = details + "Architecture of The OS: ";
        details = details + System.getProperty(architectureOS)+"\n";
    
        details = details + "Available processors (cores): ";
        details = details + Runtime.getRuntime().availableProcessors()+"\n";
    
        details = details + "User Name="+userName +"\n";
    
        details = details +  "Os Name= ";
        details = details + System.getProperty("os.name")+"\n";
    
        details = details + "hostname= " + addr.getHostName()+"\n";
        details = details + "Address= " + addr.getHostAddress()+"\n"; 
    
        return details;
    }
  
    public static void main(String args[])throws Exception{
         System.out.println(getSystemDetails());
    }  
}
                                                   
Output

Name of the OS: Windows 7
Version of the OS: 6.1
Architecture of The OS: amd64
Available processors (cores): 4
User Name=harikrishna
Os Name= Windows 7
hostname= 7QKM4CE9CGE
Address= 169.254.12.248


                                                             Home

No comments:

Post a Comment