Share on Google+Share on Google+

Overview of Networking through JAVA

This page discusses - Overview of Networking through JAVA

Find Your Host Name/IP Address


In this section you will learn about the getLocalHost() method to print the Host name as well as the IP Address of the local system. For do for the same we have to call InetAddress class then we need to create a object, in which we store the local host information. Then after we use the print command to print the stored value of the InetAddress object local. The example for the above process is as under.

Here is the Code of the Example :


public class Ipaddress{
  public static void main(String args[]){
  InetAddress local= InetAddress.getLocalHost();
  System.out.println ("Local IP Address is : " + local);
  catch (UnknownHostException e){
  System.err.println ("Can't detect IP Address : " + e);

The output of the above example is as under, In which the host name of the local system is Comp20 and the IP address is

Here is the Output of the Example :


C:\roseindia>java Ipaddress
Local IP Address is : comp20/

Download of this example



Posted on: April 17, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Overview of Networking through JAVA  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
August 27, 2013
ip adddress

Thiss program. Is. Running. On. Without. Net