Question

I am new to Java programming ,and there is a topic of networking,and my networking concept are weak,so could any one help me out with these methods What does getAllByName() method returns,it is written that it returns IP addresses of the host?what does this host mean?and does the host doesn't only have one IP address?

If someone could explain the basic concept of networking,so that I get to know what basically is IP address what does host mean,what does that method return

how come google.com is a host?

Was it helpful?

Solution

Every machine connected to a communications network is identified by a unique number.

In the case of the telephone network, each phone has a unique phone number associated with it, otherwise it cannot be used. Similarly, in an IP network, like the Internet, every machine (also called a host) must have at least one unique number, called the IP address (it may actually have more, e.g. routers have multiple IP addresses). Otherwise, that machine (host) cannot be used in (connected to) the IP network.

IP addresses (like telephone numbers) are difficult for people to remember, so we use host names (usually similar to domain names) to refer to machines, e.g. google.com or www.microsoft.com instead of an IP address (similarly, we save telephone numbers in the memory of our cell phone under the corresponding people's names). Each host name is translated automatically into an IP address (e.g., using DNS), because computers do not "understand" names, they "understand" numbers (IP addresses).

So, the machine (host) where the website of Google is stored, will have an IP address, to which the domain google.com will be translated every time a user puts that domain name in the browser. (Actually, there are many such machines, but let's assume the simplest case.)

With respect to the InetAddress class, the getAllByname() method just returns all the IP addresses associated with the host name supplied to the method as a string parameter, as per the Oracle documentation. Java encapsulates each IP address in an InetAddress object, so the return value of the method is an array of InetAddress objects, with as many members as IP addresses in the machine (host) specified in the string supplied to the method. Typically, the first of these IP addresses is the one the getByName() method returns.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top