Q:

Java program to get System Name for Windows or Linux Machine

0

Java program to get System Name for Windows or Linux Machine

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Get System Name of Linux or Windows based Machine: This java program will get and print the system name of Linux or Windows Operating System based Machine.

package com.includehelp;

import java.net.InetAddress;

/**
 * Program to get system Name for windows and Linux Machine
 * @author includehelp
 */
public class SystemName {
    /** 
     * Method for Get System Name
     * @return  System Name
     */
    public static String getSystemName(){
	try{
            String systemName  =InetAddress.getLocalHost().getHostName();
            return systemName;    
        }
	catch(Exception E){
            System.err.println("System Name Exp : "+E.getMessage());
            return null;
	}
    }
    
    public static void main(String[] args) {
        String SystmName = getSystemName();
        System.out.println("Computer Name : "+SystmName);
    }
}

Output

Computer Name : DESKTOP-13DO19X

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now