Support Me ��


SUBSCRIBE NOW

Advanced JAVA 5


Advanced JAVA 5

Java Networking

Java Networking is a concept of connecting two or more computing devices together so that we can share resources.

Java socket programming provides facility to share data between different computing devices.

Advantage of Java Networking

1. sharing resources.

2. centralize software management.

java.net package encapsulate large number of classes and interface that provides an easy-to use means to access network resources. Here are some important classes and interfaces of java.net package.

Some Important Classese

CacheRequest,     CookieHandler,
CookieManager,   Datagrampacket,
Inet Address,        ServerSocket,
Socket,                  DatagramSocket,
Proxy,                    URL,
URLConnection

Some Important Interfaces

CookiePolicy,             CookieStore,
FileNameMap,            SocketOption,
InetAddress,              ServerSocket,
SocketImplFactory,   ProtocolFamily

Java InetAddress class

Inet Address encapsulates both numerical IP address and the domain name for that address. Inet address can handle both IPv4 and IPv6 addresses. Inet Address class has no visible constructor. To create an Inet Address object, you have to use Factory methods.

Method Description
public static InetAddress getLocalHost() throws UnknownHostExceptionit returns the instance of InetAdddress containing local host name and address.
public static InetAddress getByName(String hostname) throws UnknownHostExceptionit returns the instance of InetAddress containing LocalHost IP and name.
public static InetAddress[ ] getAllByName(String hostname) throws UnknownHostExceptionit returns the instance of InetAddress containing all LocalHost IP and name.
static String format(Locale l, String format, Object... args)returns formatted string with given localer.
public String getHostName()it returns the host name of the IP address.
public String getHostAddress()it returns the IP address in string format.

 

Example using InetAddress class

import java.net.*;
class Test
{
public static void main(String[] args)
{
InetAddress address = InetAddress.getLocalHost();
System.out.println(address);
address = InetAddress.getByName("www.bethedeveloper.com");
System.out.println(address);
InetAddress sw[] = InetAddress.getAllByName("www.google.com");
for(int i=0; i< sw.length; i++)
{
System.out.println(sw[i]);
}
}
}
Output:

Welcome-PC/59.161.87.227
www.bethedeveloper.com/208.91.198.55
www.google.com/74.125.236.115
www.google.com/74.125.236.116
www.google.com/74.125.236.112
www.google.com/74.125.236.113
www.google.com/74.125.236.114
www.google.com/2404:6800:4009:802:0:0:0:1014

Dinesh Kumar S is a 23-year-old System Administrator who enjoys playing games, listening to music and learning new technology. He is friendly and generous, but can also be very lazy and crazy.

Share this

Backlinks

Website Design Company in Coimbatore
Website Design Company in Tamil nadu
Website Design Company in Karur
Website Design Company in Erode
Website Design Company in ooty
Website Design Company in theni
Website Design Company in thoothukudi
Website Design Company in Chennai
Website Design Company in Sathy
Website Design Company in Coimbatore Tamilnadu
Cheap Website Design Company in Coimbatore
Adsense Website Design Company in Coimbatore
ecommerce Website Design Company in Coimbatore
school Website Design Company in Coimbatore
Academy Website Design Company in Coimbatore
Test Website Design Company in Coimbatore
Best Website Design Company in Coimbatore
Adsense Website Design Company in Coimbatore
Adsense Website Design Company in Tamil nadu
Adsense Website Design Company in Karur
Adsense Website Design Company in Erode
Adsense Website Design Company in ooty
Adsense Website Design Company in theni
Adsense Website Design Company in thoothukudi
Adsense Website Design Company in Chennai
Adsense Website Design Company in Sathy
Free SEO Tools online
Free SEO Tools online Website
Free SEO Tools online Plagiarism
Free SEO Tools online article rewriter tool
Free SEO Tools online article reading and writing criticism
Free SEO Tools online seo backlink
Free SEO Tools online Free backlink maker
Free SEO Tools online seo backlink strategy
Free SEO Tools online content writting
360 help SEO Tools online Plagiarism checker
360 help SEO Tools online seo backlink
360 help SEO Tools online Free backlink maker
360 help SEO Tools online content writting
360 help SEO Tools online article rewriter tool
360 help SEO Tools
360 help SEO Tools India
360 help SEO Tools Tamil
360 help SEO Tools website