20165236 2017-2018-2 "Java Programming" ninth week study summary

20165236 2017-2018-2 "Java Programming" ninth week study summary

1. Chapter 13 Summary of Textbook Contents

1. URL class

     The URL class is an important class in the java.net package. Applications that use URLs to create objects are called client programs. A URL object usually contains the most basic three parts of information: protocol, address and resource.

     URL constructor: Create a URL object by using public URL(String spec) throws MalformedURLException.

2. InetAddress class

     Representation of address: domain name, IP address;

     Get the address of the host on the Internet: Use the static method getByName( String s) of the InetAddress class to obtain an InetAddress object, which contains the domain name and IP address of the host address.

3. Socket

The client program uses the Socket class to create a socket object responsible for connecting to the server;

The construction method of Socket is Socket(String host, int port), where host is the IP address of the server, and port is a port number.

In order for the client to successfully connect to the server, the server must establish a ServerSocket object, the constructor of ServerSocket is ServerSocket(int port), and port is a port number.

Use multi-threading technology: After the server receives a client's socket, it should start a thread dedicated to serving the client.

4. UDP datagram

 

The basic modes of UDP-based communication are:

 

Pack the data, called a packet, and send the packet to the destination;

 

Receive incoming packets (like receiving envelopes), and look at the contents of the packets.

Send data packets: Pack the data with the DatagramPacket class;

Receive data packets: Create an object with another constructor of DatagramSocket, DatagramSocket( int port), whose parameters must be the same as the port number of the data packet to be received; the object mail_in uses the method receive(DatagramPacket pack) to accept the data packet; use DatagramPack Another constructor of the class DatagramPack(byte data[], int length) creates a data packet for receiving data packets.

5. Broadcast datagram

6. Java remote call

Design details of remote objects and their proxies, RMI.

Second, last week's test error summary

3. The following (AB) methods will cause the thread to enter the blocking state?
 
A.Thread.sleep()
B.wait()
C.notify()
D.interrupt()
 
5. When the interrupt() method of the thread is called, will a (CD) exception object be thrown?
 
A.IllegalStateException
B.RuntimeException
C.InterruptedException
D.SecurityException
 
12. The following statements about thread state and life cycle are wrong (BC)
 
A. Do not let the thread call the start() method again before the thread ends the run() method, otherwise an IllegalThreadStateException will occur.
The B.run() method is responsible for notifying the JVM that there are new threads waiting to switch.
C. After executing sleep(), the thread enters the running state and obtains the right to use the CPU.
D. When entering the blocking state, the thread cannot enter the queue.
 
Three, this week's learning summary
This week, I focused on learning Java network programming, and mastered the important roles of URL, Socket and other classes in network programming, which gave me a lot of gains.

 

 

 

 

 

Guess you like

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