News:

GinGly.com - Used by 85,000 Members - SMS Backed up 7,35,000 - Contacts Stored  28,850 !!

Main Menu

URI GetHost() Example

Started by VelMurugan, Dec 28, 2008, 12:00 AM

Previous topic - Next topic

VelMurugan

URI GetHost() Example

Returns the host component of this URI.

URIclass GetHost() method example. This example shows you how to use GetHost() method.This method Returns the host component of this URI.

Here is the code:-

/**
* @Program that Returns the host component of this URI.
* GetHost.java
* Author:-RoseIndia Team
* Date:-24-jun-2008
*/
import java.net.*;

public class GetHost {

    public static void main(String[] args) throws Exception {
        String scheme = "http";
        String userInfo = "girish";
        String host = "tewari.com";
        int port = -1;
        String path = "/mail/";
        String query = "open";
        String fragment = "inbox";
        URI uri = new URI(scheme, userInfo, host, port, path, query, fragment);
        System.out.println("Given uri is: " + uri);
        //Returns the host component of this URI.
        System.out.println("Given host is: " + uri.getHost());
    }
}


Output of the program:-

Given uri is: http://girish@tewari.com/mail/?open#inbox
Given host is: tewari.com

Source : coding diary