Full width home advertisement

Electronics Hub

Internet of Networks

Post Page Advertisement [Top]

Q. Define and implement hostname and host address by JAVA.


Ans.

Before we jump into the programming of how to implement the hostname and host address, we need figure out first what is a hostname and a host address.

So, What is a Hostname?


A hostname is an unique name given to a computer that is connected to the internet. A name is a label that could be used to distinguish from one computer to another. 

Mainly, a hostname is an unique identifier that serves as a name of your computer or the server that can be as long as 255 characters and consists of numbers and letters.

While defining a hostname people has been seem to confuse it with a domain name.

In reality, a Domain Name is used to recognize an IP Address of a computer. Domain names are used in URL's to recognize particular webpages. 

For Example in the URL, https://www.spiralcomputing.com/index.html , the domain is spiralcomputing.com  

Every domain name has an extension that indicates which top level domain (TLD) it belongs to. For example; such domains are limited to, 

·  gov - Government agencies
·  edu - Educational institutions
·  org - Organizations (nonprofit)
·  mil - Military
·  com - commercial business
·  net - Network organizations
·  ca - Canada
·  th - Thailand  

Now, because the internet is based on IP Addresses not the Host names, every web server a Domain Name System (DNS) server to translate domain names into IP Addresses.

What is a Host Address?


By definition of the host address of a computer, the Physical address/MAC address is the host address of a computer in a network. But on the internet, the IP address is the host address of the machine. 

Note: Any address that takes place between the Network and Broadcast Addresses are Host Addresses which means that, these addresses can be assigned to a Host and are NOT reserved for any specific purpose, unlike the Network and Broadcast Addresses.

Well, lets move to Socket Programming

import java.io.*,
import java.net.*,

public class hostname
{
  public static void main(String[] args) throws Exception
  {
    InetAddress ob=InetAddress.getByName("50.87.249.83");
    System.out.println("Hostname is:" +ob.getHostName());
    System.out.println("IP Address:" +ob.getHostAddress());
   }
 }

Output:

javac hostname.java (//enter)
java hostname (//enter)

Hostname is: box1283.bluehost.com
IP Address is: 50.87.249.83

Free picture downloaded from unsplash.com

No comments:

Post a Comment

Bottom Ad [Post Page]

| Designed by Sriparna Sarkar