|
Do you need help with your Java programming?
Click here for instant help with your Java code. |
Get Name of User Currently Logged In to the Computer
| This code example shows how to display the current user logged on to the computer. There is a system property called 'user.name' which holds the value of the current user. The property is obtained by calling the getProperty() method of the System class. |
| /** * * @author www.javadb.com */ public class Main { public void getCurrentUser() { String currentUser = System.getProperty("user.name"); System.out.println("Current user is " + currentUser); } /** * @param args the command line arguments */ public static void main(String[] args) { new Main().getCurrentUser(); } } |
| Do you know your Java? | |
| Take a Ten-Question-Java-Quiz! | |
Search for code examples on this site
