Thursday, 5 March 2009

Java™ How to Program, Sixth Edition - Part24

Few weeks back i started reading Java™ How to Program, Sixth Edition By H. M. Deitel - Deitel & Associates, Inc., P. J. Deitel - Deitel & Associates, Inc.

Nice book written By H. M. Deitel - Deitel & Associates, Inc., P. J. Deitel - Deitel & Associates, Inc.

I wanted to share few quotations found the book from the 24rd chapter.

1) Java provides stream sockets and datagram sockets. With stream sockets, a process establishes a connection to another process. While the connection is in place, data flows between the processes in streams. Stream sockets are said to provide a connection-oriented service. The protocol used for transmission is the popular TCP (Transmission Control Protocol).

2) With datagram sockets, individual packets of information are transmitted. UDP (User Datagram Protocol) is a connectionless service that does not guarantee that packets will not can be lost, duplicated or arrive out of sequence. Extra programming is required on the programmer's part to deal with these problems.

3) The HTTP protocol (Hypertext Transfer Protocol) that forms the basis of the Web uses URIs (Uniform Resource Identifiers) to locate data on the Internet. Common URIs represent files or directories and can represent complex tasks such as database lookups and Internet searches. A URI that represents a document is called a URL (Uniform Resource Locator).

4) Web browsers often restrict an applet so that it can communicate only with the machine from which it was originally downloaded.

5) Applet method getAppletContext returns a reference to an AppletContext object that represents the applet's environment (i.e., the browser in which the applet is executing). AppletContext method showDocument receives a URL as an argument and passes it to the AppletContext (i.e., the browser), which displays the Web resource associated with that URL. A second version of showDocument enables an applet to specify the target frame in which to display a Web resource. Special target frames include _blank (display in a new Web browser window), _self (display in the same frame as the applet) and _top (remove the current frames, then display in the current window).

6) JEditorPane method setPage downloads the document specified by its argument and displays it in the JEditorPane.

7) Typically, an HTML document contains hyperlinkstext, images or GUI components that, when clicked, link to another document on the Web. If an HTML document is displayed in a JEditorPane and the user clicks a hyperlink, the JEditorPane generates a HyperlinkEvent and notifies all registered HyperlinkListeners of the event.

8) HyperlinkEvent method getEventType determines the event type. HyperlinkEvent contains nested class EventType, which declares three hyperlink event types: ACTIVATED (hyperlink clicked), ENTERED (mouse over a hyperlink) and EXITED (mouse moved away from a hyperlink). HyperlinkEvent method getURL obtains the URL represented by the hyperlink.

9) Stream-based connections are managed with Socket objects.

10) A ServerSocket object establishes the port where a server waits for connections from clients. The second argument to the ServerSocket constructor is the number of connections that can wait in a queue to connect to the server. If the queue of clients is full, client connections are refused. The ServerSocket method accept waits indefinitely (i.e., blocks) for a connection from a client and returns a Socket object when a connection is established.

11) Socket methods getOutputStream and getInputStream get references to a Socket's OutputStream and InputStream, respectively. Socket method close terminates a connection.

12) A server name and port number are specified when creating a Socket object to enable it to connect a client to the server. A failed connection attempt throws an IOException.

13) InetAddress method getByName returns an InetAddress object containing the host name of the computer for which the host name or IP address is specified as an argument. InetAddress method getLocalHost returns an InetAddress object containing the host name of the local computer executing the program.

14) Connection-oriented transmission is like the telephone systemyou dial and are given a connection to the telephone of the person with whom you wish to communicate. The connection is maintained for the duration of your phone call, even when you are not talking.

15) Connectionless transmission with datagrams is similar to mail carried via the postal service. A large message that will not fit in one envelope can be broken into separate message pieces that are placed in separate, sequentially numbered envelopes. All the letters are then mailed at once. They could arrive in order, out of order or not at all.

16) DatagramPacket objects store packets of data that are to be sent or that are received by an application. DatagramSockets send and receive DatagramPackets.

17) The DatagramSocket constructor that takes no arguments binds the application to a port chosen by the computer on which the program executes. The DatagramSocket constructor that takes an integer port number argument binds the application to the specified port. If a DatagramSocket constructor fails to bind the application to a port, a SocketException occurs. DatagramSocket method receive blocks (waits) until a packet arrives, then stores the packet in its argument.

18) DatagramPacket method getAddress returns an InetAddress object containing information about the host computer from which the packet was sent. Method getPort returns an integer specifying the port number through which the host computer sent the DatagramPacket. Method getLength returns an integer representing the number of bytes of data in a DatagramPacket. Method geTData returns a byte array containing the data in a DatagramPacket.

19) The DatagramPacket constructor for a packet to be sent takes four argumentsthe byte array to be sent, the number of bytes to be sent, the client address to which the packet will be sent and the port number where the client is waiting to receive packets.

20) DatagramSocket method send sends a DatagramPacket out over the network.

21) If an error occurs when receiving or sending a DatagramPacket, an IOException occurs.

22) Reading data from a Socket is a blocking callthe current thread is put in the blocked state while it waits for the read operation to complete. Method setSoTimeout specifies that if no data is received in the given number of milliseconds, the Socket is to issue an InterruptedIOException, which the current thread can catch, then continue executing. This prevents the current thread from blocking indefinitely if no more data is available from the Socket.

23) Multicast is an efficient way to send data to many clients without the overhead of broadcasting it to every host on the Internet. Using multicast, an application can "publish" DatagramPackets to be delivered to subscriber applications. An application multicasts DatagramPackets by sending them to a multicast addressan IP address in the range from 224.0.0.0 to 239.255.255.255, reserved for multicast.

24) Clients that wish to receive DatagramPackets can join the multicast group that will receive the DatagramPackets published to the multicast address.

25) Multicast DatagramPackets are not reliablepackets are not guaranteed to reach any destination or to arrive in any particular order.

26) The MulticastSocket constructor takes as an argument the port to which the MulticastSocket connects to receive incoming DatagramPackets.

27) Method joinGroup of class MulticastSocket takes as an argument the InetAddress of the multicast group to join. Method receive of class MulticastSocket reads an incoming DatagramPacket from a multicast address.

About the Authors

Dr. Harvey M. Deitel, Chairman and Chief Strategy Officer of Deitel & Associates, Inc., has 43 years experience in the computing field, including extensive industry and academic experience. Dr. Deitel earned B.S. and M.S. degrees from the Massachusetts Institute of Technology and a Ph.D. from Boston University. He worked on the pioneering virtual-memory operating-systems projects at IBM and MIT that developed techniques now widely implemented in systems such as UNIX, Linux and Windows XP. He has 20 years of college teaching experience, including earning tenure and serving as the Chairman of the Computer Science Department at Boston College before founding Deitel & Associates, Inc., with his son, Paul J. Deitel. He and Paul are the co-authors of several dozen books and multimedia packages and they are writing many more. With translations published in Japanese, German, Russian, Spanish, Traditional Chinese, Simplified Chinese, Korean, French, Polish, Italian, Portuguese, Greek, Urdu and Turkish, the Deitels' texts have earned international recognition. Dr. Deitel has delivered hundreds of professional seminars to major corporations, academic institutions, government organizations and the military.

Paul J. Deitel, CEO and Chief Technical Officer of Deitel & Associates, Inc., is a graduate of the MIT's Sloan School of Management, where he studied Information Technology. Through Deitel & Associates, Inc., he has delivered Java, C, C++, Internet and World Wide Web courses to industry clients, including IBM, Sun Microsystems, Dell, Lucent Technologies, Fidelity, NASA at the Kennedy Space Center, the National Severe Storm Laboratory, Compaq, White Sands Missile Range, Rogue Wave Software, Boeing, Stratus, Cambridge Technology Partners, Open Environment Corporation, One Wave, Hyperion Software, Adra Systems, Entergy, CableData Systems and many other organizations. Paul is one of the most experienced Java corporate trainers having taught about 100 professional Java training courses. He has also lectured on C++ and Java for the Boston Chapter of the Association for Computing Machinery. He and his father, Dr. Harvey M. Deitel, are the world's best-selling Computer Science textbook authors.

No comments: