Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. (10 points) Read chapter 22 of Big Java 5th Ed. (provided as a PDF file on Bl

ID: 3685979 • Letter: 1

Question

1. (10 points) Read chapter 22 of Big Java 5th Ed. (provided as a PDF file on BlackBoard) and provide short answers to the following questions. Submit your answers in a text document (plain text or Microsoft Word format, please).

a. What is the difference between an IP address and a DNS domain name? How do we get one from the other?

b. What does the IP protocol do? What does the TCP protocol do?

c. What is the difference between the Socket class and the URLConnection class?

d. What is the difference between an URL instance and an URLConnection instance?

2. (20 points) Write programs to satisfy the following programming problem: One can obtain a table of moon phases for a specified year at the URL http://aa.usno.navy.mil/cgi-bin/aa_moonphases.pl?year=NNNN where NNNN is the year for which the chart is requested. The web server returns a page containing an text table showing the moon phases in a given year. Write a program that asks the user for a year, asks the aa.usno.navy.mil server for the moon phase table, and then prints only the table showing the phases of the moon for that year. Note that the year needs to be included in the URL string as the parameter to the request. A good strategy for solving this problem is to use a Boolean variable inTable to determine whether we are currently printing lines of data as we receive them from the server. Initially set the Boolean variable inTable to false. After you read a line of data from the server, do these three steps in order:

1. If inTable is true, check to see if the line contains the “” string, which indicates we’re finished receiving the moon phase table, so change inTable to false so we won’t print any more lines.

2. If inTable is true, print the line.

3. If inTable is false, check to see if the line contains the tag that starts the moon phase table, "<table ". . If you find this string, set the inTable variable to true so the following lines will be printed.

Files: https://onedrive.live.com/redir?resid=A1E5259BDD065B48!4479&authkey=!AMAxhiMrUuX1XRA&ithint=folder%2cpdf

Explanation / Answer

1.a) IP address: IP address is a way of giving address to every computer over the Network.

IP address is an identifier for a computer or device on a TCP/IP network.

Networks route messages based on the IP address of the destination. The format of an IP address is four numbers separated by periods. Each number can be zero to 255.

For example, 1.160.10.240 could be an IP address.

Domain Name: Domain Name are used instead of IP address as its easier to remember Names rather than Numbers for humans.

A domain name is a name that identifies one or more IP addresses.

Domain names are used in URLs to identify particular Web pages.

For example, the domain name microsoft.com represents about a dozen IP addresses.

1.b) IP protocol : It standardizes the way machines over the Internet or any IP networkforward or route their packets based on their IP addresses.

Every machine on the Internet has a unique identifying number, called an IP Address. The IP stands forInternet Protocol, which is the language that computers use to communicate over the Internet.

A protocol is the pre-defined way that someone who wants to use a service talks with that service. The "someone" could be a person, but more often it is a computer program like a Web browser.

TCP protocol : Transmission Control Protocol is one of the most used protocols in digital network communications and is part of the Internet protocol suite, commonly known as the TCP/IP suite. Primarily, TCP ensures end-to-end delivery of data between distinct nodes.

TCP works in collaboration with Internet Protocol, which defines the logical location of the remote node, whereas TCP transports and ensures that the data is delivered to the correct destination.

Before transmitting data, TCP creates a connection between the source and destination node and keeps it live until the communication is active. TCP breaks large data into smaller packets and also ensures that the data integrity is intact once it is reassembled at the destination node.

1.c) Socket class : A socket is an endpoint for communication between two machines

Sockets are low-level connections involving byte streams.

URLConnection class : Class URL represents a Uniform Resource Locator, a pointer to a "resource" on the World Wide Web. A resource can be something as simple as a file or a directory, or it can be a reference to a more complicated object, such as a query to a database or to a search engine.

URL/URLConnection/HttpURLConnection are abstractions of some protocol (HTTP, FTP).

1.d) Difference between an URL instance and an URLConnection instance :

A URL instance represents the location of a resource, and a URLConnection instance represents a link for accessing or communicating with the resource at the location.

URLConnection is a class under java.net package. The abstract class URLConnection is the superclass of all classes that represent a communications link between the application and a URL. Instances of this class can be used both to read from and to write to the resource referenced by the URL.