20165209 2017-2018-2 "Java Programming" 9th Week study Summary

Source: Internet
Author: User
Tags thread class

20165209 2017-2018-2 "Java program Design" 9th Week study summary textbook learning content Summary URL class
    • ULR objects typically contain the most basic three-part information: protocols, addresses, and resources.
    • Construction Method:public URL(String spec) throws MalformedURLException
    • Read resource: The calling InputStream openStream() method can return an input stream.
InetAddress class
    • Address means: Domain name, IP address
    • Get host address on Internet: Use the static method of the Interaddress class getByName(String s) to return the domain name and IP address of the object containing the host address.
    • public String getHostName()Gets the domain name contained in the object, obtaining the IP address contained in the public String getHostAddress() object.
    • Get native address: Using the static method of the Interaddress class getLocalHost() , the returned object contains the domain name and IP address of the local machine.
Sockets
    • Use the socket class to establish a socket object and connect it together (a combination of port number and IP address to derive a network socket), so that two programs complete the communication.

    • Client sockets: Use to getOutputStream() get the output stream.

      //建立连接到服务器的套接字对象try { Socket clientSocket = new Socket("http://192.168.0.78",2010);}  //(IP,端口号)catch(IOException e) {}
    • ServerSocket object and server-side sockets

      //建立ServerSocket对象try{ ServerSocket serverForClient = new ServerSocket(2010);}//(端口号)catch(IOException e) {}//使用accept()方法将客户端和服务器端套接字连接起来try{ Socket sc = serverForClient.accept();}catch(IOException e) {}
    • Call the getInetAddress() method, the server side obtains the client IP address and the domain name, the client obtains the server side IP address and the domain name.

UDP datagram
    • Send Datagrams

    • Receiving datagrams

Broadcast Datagram Java Remote call
    • Remote objects and their proxies
    • RMI Design Details
      1. Extending the remote interface
      2. Remote Objects
      3. Stubs and proxies
      4. Start the registration
      5. Start the remote service object
      6. Running the client program
Problems in teaching materials learning and the solving process
    • Question 1: Why must I have a port number for my socket?

    • Issue 1 Solution: port number to facilitate inter-program communication, determine what to do.

Code Hosting

Last week's summary of the wrong quiz
    • Wrong question 1: The following statement is correct is a B D
      A. A major feature of the Java language is the built-in support for multithreading.
      E I When the main method returns, the JVM ends the Java application.
      C. After the first thread in a Java application ends, the JVM ends the Java application.
      D. The Java language uses the thread class and its child class objects to represent threads
    • Parsing: C. The JVM does not end the Java application until all the threads have finished.

    • Error 2: The following statement about the state of the thread and the life cycle, the wrong is B C
      A. Do not let the thread call the start () method again until the threads have finished the run () method, or the illegalthreadstateexception exception will occur.
      E I The run () method is responsible for notifying the JVM that a new thread waits for a switchover.
      C. After the execution of Sleep (), the thread goes into a running state and gets the use of the CPU.
      D. When the blocking state is entered, the thread cannot enter the queued queue.
    • Analytical:
      B: Should be the start () method.
      C: After the sleep is executed, the thread re-enters the thread queue to wait for CPU resources to be queued.

    • Error 3: The following description of common methods of threading, the wrong is C D
      A. After the Run method is executed, the thread becomes dead.
      E I If the thread is interrupted during hibernation, the JVM throws a Interruptedexception exception.
      C. When a running thread does not enter a dead state, if the thread is assigned an entity again, the previous entity is collected by the garbage collector.
      D. When a thread enters a dead state, the thread cannot call the IsAlive () method.
    • Analytical:
      C: The previous entity will become "junk" and will not be collected by the garbage collector.
      D: When the thread enters the dead state, the thread can also call the IsAlive () method, and the return value is False

Other (sentiment, thinking, etc., optional)

Because this chapter is a part of the network programming in Java, it synthesizes the knowledge of threads and windows, and is more comprehensive. The idea of design is more comprehensive, experience the importance of basic knowledge, and the test in class, the experiment under the class is also more difficult. Hope to be able to persist in learning, and be able to regularly consolidate the previous knowledge, improve their Java programming ability.

Learning progress Bar
lines of code (new/cumulative) Blog Volume (Add/accumulate) Learning Time (new/cumulative) Important Growth
Goal 5000 rows 30 Articles 400 hours
First week 37/37 1/1 20/20
Second week 654/691 3/4 18/38
Third week 477/1131 3/7 22/60
Week Four 657/1730 2/9 30/90
Week Five 1260/2515 1/10 30/120
Week Six 1022/3319 2/12 20/140
Seventh Week 1213/3803 1/13 20/160
Eighth Week 993/4796 4/17 30/190
Nineth Week 1584/5808 1/18 22/212
Resources
    • Java2 Practical Tutorial (5th Edition)

20165209 2017-2018-2 "Java Programming" 9th 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.