20165205 2017-2018-2 "Java Programming" Nineth Week study Summary

Source: Internet
Author: User

20165205 2017-2018-2 "Java program design" Nineth Week study summary textbook study summary
  • Learn how to use URL classes
    • How to construct a URL class:
      • public URL(String spec) throws MaldormedURLExceptionThis construction method initializes a URL object with a string
      • public URL (String protocol,String host,String file)throws MaldormedURLExceptionThe protocol, address, and resources used by this construction method are specified by the parameter protocol,host and file, respectively
    • The protocol in the above URL object is the HTTP protocol.
    • Reads the resource in the URL: The calling InputStream openStresm() method returns an input stream.
  • mastering InetAddress class
    • means of addressing: domain name and IP address
    • address representation: The InetAddress class object in the Java.net package contains the domain name or IP address of a host address.
    • get address
      • Gets the address of the host on InetAddress: Getbyname (String s) gets a domain name or IP address; GetHostName () Gets the domain name contained in the InetAddress object; geth Ostaddress () Gets the IP address contained in the InetAddress object.
      • Gets the address of the local machine: Getlocalhost () gets a InetAddress object that contains the domain name and IP address of the local computer.
  • Mastering the use of sockets
    • Overview
      • port Provisions for 0~65535
      • 0~1023 pre-occupied
    • client sockets
      • Socket (String host,iint port), the parameter host is the IP address of the server and port is a port number. The
      • method for setting up a socket object may have an IOException exception, so take the Try-catch method
    • ServerSocket object and server-side socket
        constructor Method: (int port), port is one. The port must be the same as the port number that the customer is calling. You also use the Try-catch method.
      • After a connection is established, the server socket object calls the Getinetaddress () method to obtain a InetAddress object that contains the IP address and domain name of the client.
      • After the communication between the two parties is complete, the socket should use the close () method to close the socket connection.
    • Multithreading technology
      • You can create a socket object with a socket () using the socket class's constructor without parameters, which calls public void connect (socket Ad Dress endpoint) throws IOException request and parameters socketaddress the specified server docking.
      • There are two basic principles in socket communication: (1) The server should start a dedicated thread that interfaces with the client's socket. (2) The client and server side need to read the information on a separate thread because the socket's input stream may be blocked while reading the message.
  • Mastering UDP datagrams
    • Basic mode based on UDP communication
      • Package data, become a packet, and then send the packet to the destination
      • Receive the sent packets, and then view the contents of the packet
    • Sending a packet
    • Receiving packets
  • Learn Java remote calls

    Textbook Learning Code debugging problems and the process of solving:
  • Issue one: Send bytes unsuccessful (none)
  • Problem One solution: The reason for the Internet search may be string () to restore the string when garbled, that is, the buffer left the data, the method is to pw.println(msg) write it out, and then successfully run.

    Code Hosting

Summary of the wrong question

Last week's wrong question

Summarize

This week focused on learning the URL class, socket class, and so on, learned to establish an interface, so that local and network connections better, but also more experienced the Java language (or API) powerful features. More in-depth learning let me have a deeper understanding of Java.

20165205 2017-2018-2 "Java Programming" Nineth Week study Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.