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

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

Textbook learning content summary

Chapter Thirteen

URL class

  • A URL object contains three pieces of information: protocol, address, and resource
  • There are two ways to create a URL object:

    public URL (String spec) throws MalformedURLException

    public URL(String protocol,String host,String file) throws MalformedURLException
  • Initialize a URL object with a stringURL url=new URL("http://www.google.com")

InetAddress class

method name use
getByName(String s) Pass the domain name or IP address to the parameter s to get an InetAddress object
getHostName() Get the domain name contained in the InetAddress object
getHostAddress() Get the IP address contained in the InetAddress object
getLocalHost() Get the domain name and IP address containing the local machine

socket

  • Network sockets: a combination of port number and IP address
  • The port number identifies the process on the server
  • Client socket: The Socket class establishes a socket object responsible for connecting to the server. The construction method Socket(String host,int port), host is the IP address of the server, and port is the port number.
  • Server side: ServerSocket(int port)Construct the object, port is the same port as the port number called by the client.

UDP datagram

  • Features: fast but not accurate
  • step:
  1. Create a datagram to send: DatagramPacket(byte data[],int length,InetAddtress address,int port)orDatagramPack(byte data[],int offset,int length,InetAddtress address,int port)
  2. send datagram
  3. receive datagram

broadcast datagram

  • Four types of addresses include: Class A, Class B, Class C, Class D
  • A class D address is also called a multicast address, and both broadcast data or receiving broadcasts need to be added to the same class D address.

remote call

A remote object must implement the Remote interface in the java.rmi package, and only an instance of a class that implements this interface is considered a remote object by RMI

Problems and Solving Processes in Teaching Materials Learning

Question 1: The stub is mentioned in the book, what is its function and why should it be generated?

Solution 1: The stub class is a class that implements an interface, but each method after the implementation is empty.

Its role is: if an interface has many methods, if you want to implement this interface, you must implement all the methods. But a class may only need one or two of these methods from a business perspective. If you directly implement this interface, in addition to implementing the required methods, you also need to implement all other unrelated methods. And if the interface is implemented by inheriting the stub class, this trouble is avoided

code hosting

Summary of last week's exam mistakes

  1. 下面代码中共有()个线程?
    ```
    public class ThreadTest {
    public static void main(String args[]){
    MyThread myThread =new MyThread();
    Thread t1=new Thread(myThread);
    Thread t2=new Thread(myThread);
    t1.start();
    t2.start();
    }
    }
    class MyThread extends Thread {
    ...
    }

A. 1

B. 2

C. 3

D. 4

分析:这道题在第1次做时我选择了B,只考虑到了t1,t2,忽略了main所在的主线程。

2. 下列说法正确的是

A. One of the great features of the Java language is its built-in support for multithreading.

B. When the main method returns, the JVM will end the Java application.

C. After the first thread in the Java application ends, the JVM ends the Java application.

D. The Java language uses the Thread class and its subclass objects to represent threads.

分析:这道题在我查书时翻了断章取义的错误,书上说在main没有创建其他线程时,main方法返回时,JVM就会结束Java应用
3.

The basic states of a process are: newly created, running, blocked, and dead.

A. true

B. false
``
Analysis: I hesitate to do this question. The four states of the process mentioned in the textbook are: new, running, interrupted, and dead. When checking the information on the Internet, it shows that there are five states: create, ready, execute, block, and terminate. According to the analysis of the answers given, blocking and termination should be one.

References

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 36/36 4/4 30/30
the second week 464/500 1/5 18/48
The third week 832/1332 2/7 17/65
the fourth week 939/2271 2/9 17/65
fifth week 1163/3434 1/10 17/65
Week 6 1176/4610 1/11 15/65
Week 7 864/5474 2/12 15/80
eighth week 703/6177 2/14 15/80
ninth week 1488/7665 2/16 16/96

Guess you like

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