{"id":10196,"date":"2015-08-25T07:34:30","date_gmt":"2015-08-25T11:34:30","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/?p=10196"},"modified":"2015-08-01T08:33:14","modified_gmt":"2015-08-01T12:33:14","slug":"urltest-java-demonstrates-the-ease-in-which-the-various-components-of-an-url-can-be-determined-host-port-protocol-etc","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=10196","title":{"rendered":"UrlTest.java Demonstrates the ease in which the various components of an URL can be determined (host, port, protocol, etc.)"},"content":{"rendered":"<pre>\u099c\u09be\r\nimport java.net.*;\r\n\r\n\/** Read a URL from the command line, then print\r\n\u00a0*\u00a0 the various components.\r\n\u00a0*\r\n\u00a0*\u00a0 Taken from Core Web Programming from\r\n\u00a0*\u00a0 Prentice Hall and Sun Microsystems Press,\r\n\u00a0*\u00a0 .\r\n\u00a0*\u00a0 \u00a9 2001 Marty Hall and Larry Brown;\r\n\u00a0*\u00a0 may be freely used or adapted.\r\n\u00a0*\/\r\n\r\npublic class UrlTest {\r\n\u00a0 public static void main(String[] args) {\r\n\u00a0\u00a0\u00a0 if (args.length == 1) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 try {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 URL url = new URL(args[0]);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (\"URL: \" + url.toExternalForm() + \"\\n\" +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\u00a0 File:\u00a0\u00a0\u00a0\u00a0\u00a0 \" + url.getFile() + \"\\n\" +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\u00a0 Host:\u00a0\u00a0\u00a0\u00a0\u00a0 \" + url.getHost() + \"\\n\" +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\u00a0 Port:\u00a0\u00a0\u00a0\u00a0\u00a0 \" + url.getPort() + \"\\n\" +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\u00a0 Protocol:\u00a0 \" + url.getProtocol() + \"\\n\" +\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\u00a0 Reference: \" + url.getRef());\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 } catch(MalformedURLException mue) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(\"Bad URL.\");\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 } else\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(\"Usage: UrlTest \");\r\n\u00a0 }\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u099c\u09be import java.net.*; \/** Read a URL from the command line, then print \u00a0*\u00a0 the various components. \u00a0* \u00a0*\u00a0 Taken from Core Web Programming from \u00a0*\u00a0 Prentice Hall and Sun Microsystems Press, \u00a0*\u00a0 . \u00a0*\u00a0 \u00a9 2001 Marty Hall and Larry Brown; \u00a0*\u00a0 may be freely used or adapted. \u00a0*\/ public class UrlTest { \u00a0 &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=10196\">Continue reading<\/a><\/p>\n","protected":false},"author":130,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1417,1424],"tags":[706,308,963,285],"class_list":["post-10196","post","type-post","status-publish","format-standard","hentry","category-code-programming-samples--","category-javaj2eej2me","tag-code","tag-java","tag-url","tag-285","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":26595,"url":"http:\/\/bangla.sitestree.com\/?p=26595","url_meta":{"origin":10196,"position":0},"title":"UrlTest.java  Demonstrates the ease in which the various components of an URL can be determined (host, port, protocol, etc.). #Programming Code Examples #Java\/J2EE\/J2ME #Network Programming","author":"Author-Check- Article-or-Video","date":"April 29, 2021","format":false,"excerpt":"UrlTest.java Demonstrates the ease in which the various components of an URL can be determined (host, port, protocol, etc.). import java.net.*; \/** Read a URL from the command line, then print * the various components. * * Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press,\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10192,"url":"http:\/\/bangla.sitestree.com\/?p=10192","url_meta":{"origin":10196,"position":1},"title":"UrlRetriever.java Accepts an URL from the command line, parses the host, port, and URI components from the URL and then retrieves the document. Requires the following classes","author":"","date":"August 24, 2015","format":false,"excerpt":"UrlRetriever.java\u00a0 Accepts an URL from the command line, parses the host, port, and URI components from the URL and then retrieves the document. Requires the following classes: import java.util.*; \/** This parses the input to get a host, port, and file, then \u00a0*\u00a0 passes these three values to the UriRetriever\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26591,"url":"http:\/\/bangla.sitestree.com\/?p=26591","url_meta":{"origin":10196,"position":2},"title":"UrlRetriever.java  Accepts an URL from the command line, parses the host, port, and URI components from the URL and then retrieves the document. Requires the following classes: #Programming Code Examples #Java\/J2EE\/J2ME #Network Programming","author":"Author-Check- Article-or-Video","date":"April 29, 2021","format":false,"excerpt":"UrlRetriever.java Accepts an URL from the command line, parses the host, port, and URI components from the URL and then retrieves the document. Requires the following classes: import java.util.*; \/** This parses the input to get a host, port, and file, then * passes these three values to the UriRetriever\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10501,"url":"http:\/\/bangla.sitestree.com\/?p=10501","url_meta":{"origin":10196,"position":3},"title":"URLTest.java Demonstrates try\/catch blocks.","author":"","date":"August 29, 2015","format":false,"excerpt":"\/** Taken from Core Web Programming from \u00a0*\u00a0 Prentice Hall and Sun Microsystems Press, \u00a0*\u00a0 . \u00a0*\u00a0 \u00a9 2001 Marty Hall and Larry Brown; \u00a0*\u00a0 may be freely used or adapted. \u00a0 \u00a0*\/ \u00a0 \u00a0\/\/ Further simplified getURL method. \u00a0 \u00a0public URL getURL() { \u00a0\u00a0\u00a0 if (url != null) {\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26958,"url":"http:\/\/bangla.sitestree.com\/?p=26958","url_meta":{"origin":10196,"position":4},"title":"URLTest.java Demonstrates try\/catch blocks. #Programming Code Examples #Java\/J2EE\/J2ME #Basic Java","author":"Author-Check- Article-or-Video","date":"May 6, 2021","format":false,"excerpt":"\/** Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press, * . * \u00a9 2001 Marty Hall and Larry Brown; * may be freely used or adapted. *\/ \/\/ Further simplified getURL method. public URL getURL() { if (url != null) { return(url); } System.out.print(\"Enter URL:\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26489,"url":"http:\/\/bangla.sitestree.com\/?p=26489","url_meta":{"origin":10196,"position":5},"title":"UriRetriever.java  Accepts a host, port, and file from the command line and retrieves the implied URL from the HTTP server by issuing a GET request. Uses the following classes: #Programming Code Examples #NULL #Network Programming","author":"Author-Check- Article-or-Video","date":"April 26, 2021","format":false,"excerpt":"UriRetriever.java Accepts a host, port, and file from the command line and retrieves the implied URL from the HTTP server by issuing a GET request. Uses the following classes: import java.net.*; import java.io.*; \/** Retrieve a URL given the host, port, and file as three * separate command-line arguments. A\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10196","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/130"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10196"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10196\/revisions"}],"predecessor-version":[{"id":10197,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/10196\/revisions\/10197"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10196"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}