Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Jul 012012
 

How to find a class in a Jar file

Answer:

To find a class file in a given Java Jar file, e.g. to find the class "KeyToken" in the file "selenium-server-standalone.jar",

# jar -tf selenium-server-standalone.jar | grep KeyToken
org/yaml/snakeyaml/tokens/KeyToken.class
Feb 292012
 

How to get the hostname of a local machine using Java

Answer:

The following codes illtsraeted how to get the hostname of the local machine using Java.

import java.net.InetAddress;

public class Test {

    public static void main(String[] args) {

        try {
            InetAddress addr = InetAddress.getLocalHost();

            // Get hostname
            String hostName = addr.getHostName();

            System.out.println(hostName);

        } catch (Exception e) {}
    }
}