Create a new file called Application.java and paste the following:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import javax.swing.*;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class Application {
    public static void main(String...args) throws UnknownHostException {
        JFrame frame = new JFrame("Sample App");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(300,300);

        String user = System.getProperty("user.name");
        String host = InetAddress.getLocalHost().getHostName();

        JTextArea txt = new JTextArea();
        txt.setText(
                "\n" +
                "  User: "+user+"\n" +
                "  Host: "+host+"\n"
        );
        frame.getContentPane().add(txt);

        frame.setVisible(true);
    }
}

Now open the terminal/command-line and type:

1
java Application.java

This will show a GUI application that will have a textarea with two lines of text:

  1. Your logged-in username
  2. The machine’s hostname