20165237 2017-2018-2 "Java Programming" Week 9 Learning Summary

20165237 2017-2018-2 "Java Programming" Week 9 Learning Summary

Textbook learning content summary

1. The URL class is an important class in the java.net package. An instance of a URL encapsulates a Uniform Resource Locator. An application that uses a URL to create an object is called a client program.

2. A URL object usually contains the most basic three parts of information: protocol, address, and resource.

3. The URL class usually uses the following constructor to create a URL object:

  • public URL(String spec) throws MalformedURLException
  • public URL(String protocol, String host,String file) throws MalformedURLException

4. Socket: An
IP address identifies a computer on the Internet, and a port number identifies a process (program) that is running on the computer. The port number is specified as a 16-bit integer between 0 and 65535.

5. When two programs need to communicate, they can create a socket object by using the Socket class and connect them together (the combination of the port number and the IP address results in a network socket).

6. UDP-based communication is different from TCP-based communication. UDP-based information transfer is faster, but it does not provide reliability guarantees.

7. The basic mode of communication based on UDP is:

  • Data is packaged, called a packet (like a letter is put into an envelope), and the packet is sent to its destination.
  • Accept packets from others (like receiving envelopes), and then look at the contents of the packets.

8. Receive data packets:

  • First use another constructor of DatagramSocket, DatagramSocket(int port), to create an object whose parameters must be the same as the port number of the data packet to be received. For example, if the port of the packet sent by the sender is 5666, then create a DatagramSocket object as follows:
    DatagramSocket mail_in=new DatagramSocket(5666);

  • Then the object mail_in uses the method receive(DatagramPacket pack) to accept the packet.

  • Use another constructor of the DatagramPack class: DatagramPack(byte data[],int length) to create a data packet for receiving data packets, for example:

     byte data[]=new byte[100];
     int length=90;
           DatagramPacket pack=new DatagramPacket(data,length);
     mail_in.receive(pack); 
  • The packet pack puts the received data of length bytes into data.

9. Java remote invocation, RMI (Remote Method Invocation) is a distributed technology. Using RMI, an application on a virtual machine (JVM) can request to call an object method on a JVM located in another place on the network. It is customary to call the virtual machine (JVM) that issues the call request as the (local) client, and the virtual machine (JVM) that accepts and executes the request as the (remote) server.


Code upload:


code hosting

(screenshot of the running result of the statistics.sh script)


learning progress bar

Lines of code (added/accumulated) Blog volume (new/cumulative) Study time (added/accumulated) important growth
Target 5000 lines 30 articles 400 hours
the first week 80/80 1/1 18/18 Learn to write simple JAVA applications
the second week 357/437 2/3 15/33 Master the use of arrays, symbols, and data
The third week 695/1132 2/5 20/53 Understand the basic structure and construction methods of classes and objects
the fourth week 765/1897 2/7 27/70 Understand subclassing and inheritance, interfaces and implementations
fifth week 1174/3071 2/9 15/85 Learned exception handling and understood the use and characteristics of file streams
Week 6 1175/4186 1/10 18/103 Learn about common utility classes and the generics and collections framework
Week 7 874/5060 3/13 14/117 How to create data sources and master JDBC connections
eighth week 950/6010 2/15 13/130 Understand the multi-threading mechanism of JAVA
ninth week 1063/7073 3/18 10/140 Understand JAVA network programming

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325019046&siteId=291194637