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

Source: Internet
Author: User
Tags stub thread class

20165208 2017-2018-2 "Java program design" Nineth Week study summary textbook Learning content summary 13th Chapter URL Class
    • The URL object contains three pieces of information: protocol, address, and resource
    • Two ways to create a URL object:

      public URL (String spec) throws MalformedURLException

      public URL(String protocol,String host,String file) throws MalformedURLException
    • Initializing 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 a InetAddress object
GetHostName () Gets the domain name contained in the InetAddress object
Gethostaddress () Gets the IP address contained by the InetAddress object
Getlocalhost () Get the domain name and IP address that contains the local machine
Sockets
    • Network sockets: A combination of port numbers and IP addresses
    • Port number identifies the process on the server
    • Client sockets: The socket class establishes a socket object that is responsible for connecting to the server, constructs a method Socket(String host,int port) , the host is the IP address of the server, and port is the port number.
    • Server-side: ServerSocket(int port) constructs the object, which is the same port number as the customer's call.
UDP datagram
    • Features: fast but not allowed
    • Steps:
    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 Datagrams
    3. Receiving datagrams
Broadcast Data Report
    • Four types of addresses include: Class A, Class B, Class C, Class D
    • The Class D address is also known as a multicast address, and the broadcast data or receive broadcast needs to be added to the same Class D address.
Remote Call

The remote object must implement the remoting interface in the Java.rmi package, and only the instance of the class that implements the interface is considered a remote object by RMI

Problems in teaching materials learning and the solving process

Question one: The book mentions the stub, what does it do, and why do you want to generate it?

Workaround One: The stub class is a class that implements an interface, but every method that is implemented is empty.

Its role is: If an interface has many methods, if you want to implement this interface, it is necessary to implement all the methods. But a class may require only one or two of these methods in terms of business. If you implement this interface directly, all other unrelated methods are implemented, in addition to implementing the required methods. And if you implement the interface by inheriting the stub class, you're relieved of the hassle.

Code Hosting
Last week's summary of the wrong quiz
    1. Does the following code have a () thread?
      ```
      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. A major feature of the Java language is the built-in support for multithreading.

B. 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.

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

The basic state of the process is: new, running, blocking, dying.

A. True

B. False
```
Analysis: The problem is very hesitant to do, the textbook said the process of the four states are: New, run, interrupted, dead. Check the data on the Internet to show that five states are created, ready, execute, block, terminate, according to the answer analysis, blocking and final break should be one.

Resources
    • "Java2 Practical Course (Fifth Edition)" Learning Guide
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 36/36 4/4 30/30
Second week 464/500 1/5 18/48
Third week 832/1332 2/7 17/65
Week Four 939/2271 2/9 17/65
Week Five 1163/3434 1/10 17/65
Week Six 1176/4610 1/11 15/65
Seventh Week 864/5474 2/12 15/80
Eighth Week 703/6177 2/14 15/80
Nineth Week 1488/7665 2/16 16/96

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

Related Article

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.