Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 10, Problem 12PP
Program Plan Intro
HTTP URL connection
Program Plan:
Filename: Http_URL_Connection.java
- Import the required header files.
- Declare the class “Http_URL_Connection”.
- Declare the main method.
- Declare the variable and assign the URL to the variable.
- Declare the variable and assign the user agent.
- Create an object for URL.
- Open the URL connection.
- Set the request methods.
- Get the response code.
- Display the URL.
- Display the response code.
- If the “res” is equal to “HttpURLCinection.HTTP_OK”, read the file line by line and display it.
- Finally close the stream.
- Otherwise, display error message.
- Declare the main method.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
I need a help with my python activity. This requires 2 clients and 1 server. This is a system to support an online math contest.
Rule:
There are two participants answering at the same time.
The host is responsible in starting up the server, after that they wait for the clients. When the two clients are connected, they must send the message: READY to the server. When the server receives the two READY from the clients, the contest starts.
The server will display 3 questions one after another which can be answered in 30 secs each.
11+10 = 21
10+22 = 32
10+10 = 20
The participant with most correct answers wins.
At the end of the program, the server must show the results.
ex: Client1 WINS! 2/3
Client2: 1/3
HTTP is the protocol that governs communications between web servers and web clients (i.e. browsers). Part of the protocol includes a status code returned by the server to
tell the browser the status of its most recent page request. Some of the codes and their meanings are listed below:
• 200, OK (fulfilled)
• 403, forbidden
• 404, not found
• 500, server error
Given an int variable status, write a switch statement that prints out, on a line by itself, the appropriate label from the above list based on status.
Answer the Qusetion:
“The Java URL class represents an URL. URL is an acronym for Uniform Resource Locator.It points to a resource on the World Wide Web”With reference to the above context, please answer the following:a) Write the full java program to get the protocol name, host name and port name of any URL of your choice for example:“https://www.tutorialspoint.com/java/java_applet_basics.htm "
b) Explain the different constructors in java.net.URL package using the code snippets.
c) Discuss the exception thrown when creating a URL for an unknown protocol.
d) Write a code in Java to find the InetAddress of a machine , InetAddress of host of any URL of your choice for example: “www.tutorialspoint.com” website. Give any two methods.
Chapter 10 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 10.1 - Why would anybody write a program that sends its...Ch. 10.1 - When we discuss input, are we referring to data...Ch. 10.1 - What is the difference between a text file and a...Ch. 10.2 - Write some code that will create a stream named...Ch. 10.2 - Prob. 5STQCh. 10.2 - Prob. 6STQCh. 10.2 - Prob. 7STQCh. 10.2 - Write some code that will create a stream named...Ch. 10.2 - Suppose you run a program that writes to the text...Ch. 10.2 - Prob. 10STQ
Ch. 10.3 - Prob. 11STQCh. 10.4 - Write some Java code to create an output stream of...Ch. 10.4 - Give three statements that will write the values...Ch. 10.4 - Give a statement that will close the stream toFile...Ch. 10.4 - What import statement(s) do you use when creating...Ch. 10.4 - Prob. 16STQCh. 10.4 - Give three statements that will read three numbers...Ch. 10.4 - Give a statement that will close the stream...Ch. 10.4 - Can you use writeInt to write a number to a file...Ch. 10.4 - Can you use readUTF to read a string from a text...Ch. 10.4 - Prob. 21STQCh. 10.4 - Prob. 22STQCh. 10.4 - Does the class FileInputStream have a method named...Ch. 10.4 - Does the class FileOutputStream have a constructor...Ch. 10.4 - Does the class ObjectOutputStream have a...Ch. 10.4 - Prob. 26STQCh. 10.4 - Suppose that a binary file contains exactly three...Ch. 10.4 - The following code appears in the program in...Ch. 10.4 - Prob. 29STQCh. 10.5 - Prob. 30STQCh. 10.5 - Prob. 31STQCh. 10.5 - Prob. 32STQCh. 10.5 - Prob. 33STQCh. 10.6 - Prob. 34STQCh. 10.6 - Prob. 35STQCh. 10 - Write a program that will write the Gettysburg...Ch. 10 - Modify the program in the previous exercise so...Ch. 10 - Write some code that asks the user to enter either...Ch. 10 - Write a program that will record the purchases...Ch. 10 - Modify the class LapTimer, as described in...Ch. 10 - Write a class TelephoneNumber that will hold a...Ch. 10 - Write a class contactInfo to store contact...Ch. 10 - Write a program that reads every line in a text...Ch. 10 - Repeat the previous exercise, but write the new...Ch. 10 - Write a program that will make a copy of a text...Ch. 10 - Suppose you are given a text file that contains...Ch. 10 - Suppose that you have a binary file that contains...Ch. 10 - Suppose that we want to store digitized audio...Ch. 10 - Write a program RecoverSignal that will read the...Ch. 10 - Even though a binary file is not a text file, it...Ch. 10 - Write a program that searches a file of numbers...Ch. 10 - Write a program that reads a file of numbers of...Ch. 10 - The following is an old word puzzle: Name a common...Ch. 10 - The Social Security Administration maintains an...Ch. 10 - The following is a list of scores for a game....Ch. 10 - Write a program that checks a text file for...Ch. 10 - Prob. 5PPCh. 10 - Prob. 6PPCh. 10 - Revise the class Pet, as shown in Listing 6.1 of...Ch. 10 - Write a program that reads records of type Pet...Ch. 10 - Prob. 12PP
Knowledge Booster
Similar questions
- Write a program to Validate an IPv4 Address. According to Wikipedia, IPv4 addresses are canonically represented in dot-decimal notation, which consists of four decimal numbers, each ranging from 0 to 255, separated by dots, e.g., 172.16.254.1 . The generalized form of an IPv4 address is (0-255).(0-255).(0-255).(0-255). Here we are considering numbers only from 0 to 255 and any additional leading zeroes will be considered invalid. Your task is to complete the function isValid which returns 1, if the ip address is valid else returns 0. The function takes a string s as its only argument . **************************************************************************/ // SOLUTION (in C++): #include <bits/stdc++.h> using namespace std; int isValid(string s) { s += '.'; int countDots = 0; string str = ""; for (int i = 0; i < s.length(); i++) {…arrow_forwardCreate a web page with a single text box that accepts a link to any working web site. Using PHP, create a program that will read through the source code of whatever site is associated with that link, take every other link included in the source code for it, then print those links out into an ordered list. After it has gotten the links from each of those sites, it should then visit each of those links and do the exact same thing for each of those pages (while ignoring all links it has already archived, whether from a duplicate link existing on that page or because that link was also on a different page it already scanned).arrow_forwardWrite a script using PHP that takes a link from the user and parses through its associated web page to print a list of every link embedded on that site. This program must work recursively, so for each link that gets printed, the program should automatically take each of those links as a new input and do the same for them until there are no more links left. If the same link exists twice on the same page, or if it exists on more than one page, the program should ignore all duplicate instances of the link.arrow_forward
- Write a JAVA program for HTML is the language of web pages. Items start and end with tags. A table starts with <table> and ends with </table>. In a table, a row starts with <tr> and ends with </tr>. In a row, a column starts with <td> and ends with </td>. Given two integers for rows and columns, generate an appropriately sized html table. Place the character c in each table cell. If the input is 2 3, the output is: <table> <tr> <td> c </td> <td> c </td> <td> c </td> </tr> <tr> <td> c </td> <td> c </td> <td> c </td> </tr> </table>arrow_forwardCreate a java program that establishes a connection between a client and a server socket. The client should send a request to the server and the server should accept the request. The client should then send a number to the server; the server will receive the number and square it. For example, if the client sends the number 8, the server should respond with 64; if the client sends 10, server should respond with 100. The client should then display the squared number. You are required to use the InetAddress class to get the localhost address and use 2415 as the port number for the server socket. Make sure that you close the socket connectionarrow_forwardIn Java Every computer on the Internet has a unique identifying number, called an Internetprotocol (IP) address. To contact a computer on the Internet, you send a message tothe computer’s IP address. Here are some typical IP addresses:216.27.6.136224.0.118.62There are different formats for displaying IP addresses, but the most commonformat is the dotted decimal format. The above two IP addresses use the dotteddecimal format. It’s called “dotted” because dots are used to split up the big IPaddress number into four smaller numbers. It’s called “decimal” because decimalnumbers are used (as opposed to binary) for the four smaller numbers.Each of the four smaller numbers is called an octet because each number representseight bits (oct means eight). For example, the 216 octet represents 11011000 andthe 27 octet represents 00011011.Implement an IpAddress class that stores an IP address as a dotted-decimal stringand as four octet ints. You must implement all of the following:Instance…arrow_forward
- Done in Perl. Showing process would be nice. Write a program to accept in an HTML string. search through the string and use a regular expression to pick out all valid URLs. A URL is enclosed in quotes and should begin with "http://. Display a list of all the valid URLsarrow_forwardWrite down a program for summing up the total vehicle trip counts between a source location and destination location where each trip data has to get from the user where each trip data is in the following format: SourceLocationID-DestinationLocationID:Trip Counts The output must be sorted based on the Source Location ID Input Format 402-401:15 401-404:05 404-401:03 402-401:15 401-404:09 402-401:15 401-404:15 404-401:03 405-404:03arrow_forwardwrite a program in php where a user XYZ must complete the registration form and upload a number of personal documents. You must write a script that will upload all of the supplied files to the server's XYZ/documents/ directory. You have to also check that the server will only accept documents only in the PDF and PNG format.arrow_forward
- Write a program in JavaScript that receives the age of the person who is applying for the driving licence. The messages should be displayed on the basis of the following table: Age age>=0 and age=18 and age=65 Message You are too young to apply for the licence you can apply for the License You are not eligible to apply for the licensearrow_forwardyou are required to write two classes: one that represents a UDP server and the other represents a UDP client. The operation of the program can be concluded in the client sending double values to the server, and the server returning these doubles sorted in ascending order. 1. The server must bind to port number 7000, and keep on waiting for requests (packets) to be received from clients. The client packet must include double values, which the server will send back to the client sorted in ascending order. In addition, the server keeps a log file named log.txt, in which it logs the date/time info and info of clients addressing (IP address in dotted decimal notation and port number) and their sorted numbers, each client on a new line as follows: date-time client-ip:client-port# sorted_numbers (space separated) 2. The client must read the double values from the user, until the user enters -1 (positive doubles are only assumed to be entered). It must send these double values to the server,…arrow_forwardwrite a client-server program in C: Copy the program, compile and run(to ensure it is functional). Hint: IP address 0.0.0.0 and 127.0.0.1 (Loopback IP address); Insert appropriate comments in your example program to highlight the following aspects of the API: Creating a socket Endpoint addresses (IP + Port number) used Client connecting to server Server accepting to connect to client Client communicating with (sending request to) server Server accepting client request Server processing client request Server communicating with (sending reply back to) client Client receiving server’s response Client closing the connection Server closing a connection.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,