How To Use Java.net.inetaddress Class For Java Networking ?.

Hello friends,

Today I am presenting to you with a Java program which deals with Networking. It demonstrates functioning of java.net.InetAddress class in Java. This Class has many powerful methods which can provide Java developer a powerful API. One of the important method is getLocalHost( ). This method displays the local host address over the console. The User can also print the name of address by calling getByName method. This method takes an parameter of String which is the name of the domain name for which we want the name.

Program to demonstrate working of InetAddress class and the methods of the

InetAddress class for Java Networking

package com.hubberspot.networking.example ;

import java.net.* ;

public class InetAddressDemo
{

public static void main( String [ ] args )
{
try
{
InetAddress address1 = InetAddress.getLocalHost( ) ;


/> System.out.println("Local host's address : "
+ address1 ) ;
address2 = InetAddress.getByName( "www.ExpertsColumn.com" ) ;

System.out.println( " ExpertsColumn's address : "
+ address2 ) ;

InetAddress[ ] addresses = InetAddress
.getAllByName( "www.ExpertsColumn.com" ) ;

for( int i = 0 ; i < addresses.length ; i++ )
System.out.println( " Address " + i + 1 + " : "
+ addresses[ i ] ) ;
}
catch( UnknownHostException e )
{
e.printStackTrace( ) ;
}
}
}


For more of such hot topics read my other posts here :

Visit my new website



Article Written By jontymagicman

I am DInesh Varyani.

Last updated on 26-07-2016 278 0

Please login to comment on this post.
There are no comments yet.
Creating And Running A Thread Using Runnable Interface
What Is Difference Between Equals() Method And == Operator In Java ?