Java get windows Username

Ads
 

Java get windows Username

In this section, you will learn how to obtain the window's username. We are providing you an example which will obtain the window's username by using the System.getProperty().

In this section, you will learn how to obtain the window's username. We are providing you an example which will obtain the window's username by using the System.getProperty().

Java get windows Username

     

In this section, you will learn how to obtain the window's username. We are providing you an example which will obtain the window's username by using the System.getProperty(). This will provide all the properties of the windows.

System.getProperty("user.name")- This method retrieve the username of the particular system from all the properties of Windows.

On the Windows operating system or any other system user must first login to the OS to work on it. So, its mandatory to login to the system before using it. In Java program you may have to find the current logged in user to the system either to display the logged in user information in the appliation or to save this information in database.

This program explains you the code to get the currently logged in user name( user which is running the Java program) and then display on the console.

The system property "user.name" is used to identify the currently logged in user.

Here is the video tutorial which explains you how to run this Java program in Eclipse and get the name of currently logged in user.

Here is the video tutorial of "How to get windows Username in Java?":

Here is the code of GetWindowUsername.java

public class GetWindowUsername {
public static final void main( String args[] ) {
String userName = System.getProperty("user.name");
System.out.println("Window's Username: "+userName);
}
}

Output will be displayed as:

Download Source Code

Ads

Ads