JAVA An Introduction to Problem Solving Programming 8
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](https://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-1.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-2.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-3.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-4.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-5.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-6.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-7.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-8.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-9.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-10.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-11.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-12.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-13.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-14.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-15.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-16.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-17.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-18.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-19.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-20.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-21.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-22.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-23.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-24.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-25.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-26.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-27.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-28.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-29.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-30.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-31.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-32.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-33.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-34.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-35.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-36.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-37.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-38.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-39.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-40.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-41.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-42.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-43.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![FIGURE 10. 7 1. Client/Server Network Communication via Sockets The Java server program listens FIGURE 10. 7 1. Client/Server Network Communication via Sockets The Java server program listens](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-44.jpg)
FIGURE 10. 7 1. Client/Server Network Communication via Sockets The Java server program listens and waits for a connection on port 6789. Different programs may be listening on other ports. Server Computer port 0 port 1 Java server program In Listing 10. 13 the server and client are running on the same computer which is identified by the special address of “localhost”. … port 6789 … 2. The Java client program connects to the server on port 6789. It uses a local port that is assigned automatically, in this case, port 8312. Server Computer Java server program 3. Client Computer port 0 port 1 … Network … port 6789 port 8312 … … Java client program The Java server program can now communicate over a socket bound locally to port 6789 and remotely to the client’s address at port 8312, while the client communicates over a socket bound locally to port 8312 and remotely to the server’s address at port 6789. JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![LISTING 10. 12 Network Server Program import java. util. Scanner; import java. io. Input. LISTING 10. 12 Network Server Program import java. util. Scanner; import java. io. Input.](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-45.jpg)
LISTING 10. 12 Network Server Program import java. util. Scanner; import java. io. Input. Stream. Reader; import java. io. Data. Output. Stream; import java. io. Print. Writer; import java. net. Socket; import java. net. Server. Socket; public class Socket. Server { public static void main(String[] args) { String s; Scanner input. Stream = null; Print. Writer output. Stream = null; Server. Socket server. Socket = null; try { // Wait for connection on port 6789 System. out. println("Waiting for a connection. "); server. Socket = new Server. Socket(6789); Socket socket = server. Socket. accept(); // Connection made, set up streams input. Stream = new Scanner(new Input. Stream. Reader(socket. get. Input. Stream())); output. Stream = new Print. Writer(new Data. Output. Stream(socket. get. Output. Stream())); JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![// Read a line from the client s = input. Stream. next. Line(); // Read a line from the client s = input. Stream. next. Line();](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-46.jpg)
// Read a line from the client s = input. Stream. next. Line(); // Output text to the client output. Stream. println("Well, "); output. Stream. println(s + " is a fine programming language!"); output. Stream. flush(); System. out. println("Closing connection from " + s); input. Stream. close(); output. Stream. close(); } catch (Exception e) { // If any exception occurs, display it System. out. println("Error " + e); } } } Screen Output After running the client program in Listing 10. 13. Waiting for a connection. Closing connection from Java JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![LISTING 10. 13 Network Client Program import java. util. Scanner; import java. io. Input. LISTING 10. 13 Network Client Program import java. util. Scanner; import java. io. Input.](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-47.jpg)
LISTING 10. 13 Network Client Program import java. util. Scanner; import java. io. Input. Stream. Reader; import java. io. Data. Output. Stream; import java. io. Print. Writer; import java. net. Socket; public class Socket. Client { public static void main(String[] args) { String s; Scanner input. Stream = null; Print. Writer output. Stream = null; try { // Connect to server on same machine, port 6789 Socket client. Socket = new Socket("localhost", 6789); // Set up streams to send/receive data input. Stream = new Scanner(new Input. Stream. Reader(client. Socket. get. Input. Stream())); output. Stream = new Print. Writer(new Data. Output. Stream(client. Socket. get. Output. Stream())); // Send "Java" to the server output. Stream. println("Java"); output. Stream. flush(); // Sends data to the stream JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![// Read everything from the server until no // more lines and output // Read everything from the server until no // more lines and output](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-48.jpg)
// Read everything from the server until no // more lines and output it to the screen while (input. Stream. has. Next. Line()) { s = input. Stream. next. Line(); System. out. println(s); } input. Stream. close(); output. Stream. close(); } catch (Exception e) { // If any exception occurs, display it System. out. println("Error " + e); } } } Screen Output After running the client program in Listing 10. 12. Well, Java is a fine programming language! JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![URL Class URL website = new URL("http: //www. wikipedia. org"); Scanner input. Stream = URL Class URL website = new URL("http: //www. wikipedia. org"); Scanner input. Stream =](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-49.jpg)
URL Class URL website = new URL("http: //www. wikipedia. org"); Scanner input. Stream = new Scanner( new Input. Stream. Reader( website. open. Stream())); while (input. Stream. has. Next. Line()) { String s = input. Stream. next. Line(); System. out. println(s); } input. Stream. close(); JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-50.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-51.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-52.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-53.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-54.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-55.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
![JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch](http://slidetodoc.com/presentation_image_h/a66be66876f60b4ee07ad39c0984c54c/image-56.jpg)
JAVA: An Introduction to Problem Solving & Programming, 8 th Ed. By Walter Savitch ISBN 0134462033 © 2018 Pearson Education, Inc. , Hoboken, NJ. All Rights Reserved
- Slides: 56