Skip to content

How to get the Current Machine Name and Logged In User in Java

It’s very easy to get the current machine name and logged in user using Java.

Get the Currently Logged in User

String username = System.getProperty("user.name"); System.out.println("Username logged in: " + username);
Code language: Java (java)

This is also platform-independent.

Get the Hostname of the Machine

java.net.InetAddress localMachine = java.net.InetAddress.getLocalHost(); String hostname = localMachine.getHostName(); System.out.println("Hostname of local machine: " + hostname);
Code language: Java (java)

See also  Credit Card Mask in Java
Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x