URL in Java C343 Lab (Week 13).

Slides:



Advertisements
Similar presentations
Networking with Java 1. Introduction to Networking 2.
Advertisements

Programming TCP Clients Version InetAddress Class An IP address identifies uniquely a host in the internet, which consists of 4 numbers (1 byte.
Prepared By E. Musa Alyaman1 URLs, InetAddresses, and URLConnections Chapter 9.
Java Sockets Source:
Programming TCP Clients. InetAddress Class An IP address identifies uniquely a host in the internet, which consists of 4 numbers (1 byte each one) in.
Networking Support In Java 2 Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 Java Networking CS , Spring 2008/9. 2 Today’s Menu Networking Basics  TCP, UDP, Ports, DNS, Client-Server Model TCP/IP in Java Sockets URL 
Internet Programming In Java. References Java.sun.com Java552 Many of the programs shown.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L24 (Chapter 25) Networking.
CIS – Spring Instructors: Geoffrey Fox, Bryan Carpenter Computational Science and.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
Networking with Java 1: The Client Side. Introduction to Networking.
Programming TCP Clients. InetAddress Class An IP address identifies uniquely a host in the internet, which consists of 4 numbers (1 byte each one) in.
Networking Support In Java Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
1 Java Networking – part I CS , Winter 2007/8.
13-Jul-15 Sockets and URLs. 2 Sockets A socket is a low-level software device for connecting two computers together Sockets can also be used to connect.
1 Networking with Java. 2 Introduction to Networking.
1 Java Networking CS , Spring Today’s Menu Networking Basics  TCP, UDP, Ports, DNS, Client-Server Model TCP/IP in Java Sockets URL  The.
JAVA - Network DUT Info - Option ISI (C) Philippe Roose , 2005.
An program As a simple example of socket programming we can implement a program that sends to a remote site As a simple example of socket.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
CSE 143 Lecture 21 I/O Streams; Exceptions; Inheritance read 9.3, 6.4 slides created by Marty Stepp
Appendix F: Network Programming in Java ©SoftMoore ConsultingSlide 1.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Application Protocols: HTTP CSNB534 Semester 2, 2007/2008 Asma Shakil.
© 1997 Elliotte Rusty Harold10/7/2015 URLs, InetAddresses, and URLConnections High Level Network Programming Elliotte Rusty Harold
Import java.net.*; import java.io.*; public class LowPortScanner { public static void main(String[] args) { String host = "localhost"; if (args.length.
DBI Representation and Management of Data on the Internet.
Servlet Communication Other Servlets, HTML pages, objects shared among servlets on same server Servlets on another server with HTTP request of the other.
Lecture 9 Network programming. Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on the Internet.
NETWORK PROGRAMMING.
Networks Sockets and Streams. TCP/IP in action server ports …65535 lower port numbers ( ) are reserved port echo7 time13 ftp20 telnet23.
StreamTokenizer Break up a stream of text into pieces called tokens A token is the smallest unit recognized by a text parsing algorithm (words, symbols,
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 15 IO Using http Rob Pooley
Java IO. Why IO ? Without I/O, your program is a closed box. Without I/O, your program is a closed box. I/O gives your Java program access to your hard.
Chapter 12: Accessing the Web URL (Uniform Resource Locator) class Applet methods –for audio clips –for images –context interface.
MIDP Programming Networking. Chapter Objectives The CLDC Streams Model Generic Connection Framework (GCF) Supported Protocols Creating a Connection Review.
Project Scenario for OpX. High-level Overview In the Test GUI Controller, opXController, for the opX command there is conceptually a call to an appropriate.
Java Programming II Java Network (I) Java Programming II.
1 Lecture 9: Network programming. 2 Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on.
URL Programming Mimi Opkins CECS277. What is a URL?  URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on.
Building Java Programs Bonus Slides I/O Streams; Exceptions; Inheritance Copyright (c) Pearson All rights reserved.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
자바네트워크 제 13 주 URLConnection 클래스 IP 멀티캐스팅 소켓. 여러분들의 질문 지난 주 실습 내용 질문.
Network Programming. These days almost all devices.
Sequential files creation & writing
Java.net CS-328 Dick Steflik.
Secure Sockets SSL (Secure Sockets Layer) is a standard security technology for establishing an encrypted link between a server and a client—typically.
Source: Java Sockets Source:
CSE 143 Lecture 22 I/O Streams; Exceptions; Inheritance read 9.3, 6.4
Network Programming Introduction
Network Programming Introduction
Network Programming Introduction
I/O Basics.
Sockets and URLs 17-Sep-18.
Sockets and URLs 13-Nov-18.
Clients and Servers 19-Nov-18.
Clients and Servers 1-Dec-18.
Networking.
Sockets and URLs 3-Dec-18.
HTTP and Sockets Lecture 6
Lecture 25: I/O Streams; Exceptions; Inheritance
Networking.
Java Socket Programming
CSE 143 Lecture 25 I/O Streams; Exceptions; Inheritance read 9.3, 6.4
Web APIs API = Application Programmer Interface
Uniform Resource Locator: URL
Programming TCP Clients
Clients and Servers 19-Jul-19.
Clients and Servers 13-Sep-19.
Presentation transcript:

URL in Java C343 Lab (Week 13)

A Java program can communicate with URLs (Uniform Resource Locator) A Java program can communicate with URLs (Uniform Resource Locator). These can also be used to create a URL object to represent a URL address.

Using URL in Java The java.net.URL class represents a URL and has complete set of methods to manipulate URL in Java. The URL class has several constructors for creating URLs, including the following: SN Methods with Description 1 public URL(String protocol, String host, int port, String file) throws MalformedURLException.   Creates a URL by putting together the given parts. 2 public URL(String protocol, String host, String file) throws MalformedURLException Identical to the previous constructor, except that the default port for the given protocol is used. 3 public URL(String url) throws MalformedURLException Creates a URL from the given String 4 public URL(URL context, String url) throws MalformedURLException Creates a URL by parsing the together the URL and String arguments

The URL class contains many methods for accessing the various parts of the URL being represented. Some of the methods in the URL class include the following: SN Methods  Description 1 public String getPath() Returns the path of the URL. 2 public String getQuery() Returns the query part of the URL. 3 public String getAuthority() Returns the authority of the URL. 4 public int getPort() Returns the port of the URL. 5 public int getDefaultPort() Returns the default port for the protocol of the URL. 6 public String getProtocol() Returns the protocol of the URL. 7 public String getHost() Returns the host of the URL. 8 9 public String getFile() Returns the filename of the URL. 10 public String getRef() Returns the reference part of the URL. 11 public URLConnection openConnection() throws IOException Opens a connection to the URL, allowing a client to communicate with the resource.

URLConnections Class Methods The openConnection() method returns a java.net.URLConnection, an abstract class whose subclasses represent the various types of URL connections. For example: If you connect to a URL whose protocol is HTTP, the openConnection() method returns an HttpURLConnection object. If you connect to a URL that represents a JAR file, the openConnection() method returns a JarURLConnection object. etc... The URLConnection class has many methods for setting or determining information about the connection

URLConnections Class Methods: SN Methods Description 1 Object getContent()  Retrieves the contents of this URL connection. 2 Object getContent(Class[] classes)  3 String getContentEncoding()  Returns the value of the content-encoding header field. 4 int getContentLength()  Returns the value of the content-length header field. 5 String getContentType()  Returns the value of the content-type header field. 6 int getLastModified()  Returns the value of the last-modified header field. 7 long getExpiration()  Returns the value of the expires header field. 8 long getIfModifiedSince()  Returns the value of this object's ifModifiedSince field. 9 public void setDoInput(boolean input) Passes in true to denote that the connection will be used for input. The default value is true because clients typically read from a URLConnection. 10 public void setDoOutput(boolean output) Passes in true to denote that the connection will be used for output. The default value is false because many types of URLs do not support being written to. 11 public InputStream getInputStream() throws IOException Returns the input stream of the URL connection for reading from the resource. 12 public OutputStream getOutputStream() throws IOException Returns the output stream of the URL connection for writing to the resource 13 public URL getURL() Returns the URL that this URLConnection object is connected to

Examples in URLDemo.java & URLConnDemo.java

Resources http://www.tutorialspoint.com/java/java_url_processing.htm