Java program to get System Name for Windows or Linux Machine

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

Java Most Popular & Searched Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.