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

Source: Internet
Author: User
Tags stub

20165228 2017-2018-2 "Java program Design" 9th Week Study summary Textbook study summary
    • The URL class is an important class in the java.net package, where an instance of the URL encapsulates a Uniform Resource Locator (Uniform Resource Locator), and the application that uses the URL to create the object is called the client program
    • The most basic information for a URL object: protocol, address, resource
    • Create a URL object
    • To read a resource in a URL:
      URL Object invocation
InputStream openStream()

Returns an input stream that points to the resources contained by the URL object

  • Two ways for hosts on the internet to represent addresses: domain names, IP addresses
  • Get address
  • The address of the host on the Internet:
    1. static method of the InetAddress class Getbyname (String s);
    2. Gets a InetAddress object that contains the domain name and IP address of the host address
  • Get the address of the local machine: Getlocalhost () by the static method of the InetAddress class
  • Socket: The IP address identifies a computer on the Internet, and the port number identifies the process (program) that is running on the computer. The port number is defined as an integer between a 16-bit 0~65535, a combination of the port number and the IP address to derive a network socket. When two programs need to communicate, they can establish socket objects and join them by using the socket class.
  • To establish a socket object to connect to the server:

    try{  Socket mysocket=new Socket(“http://192.168.0.78”,1880); }catch(IOException e) {  
  • Mysocket Related methods
  • getInputStream () gets an input stream
  • Getoutputstream () gets an output stream
  • The input that is obtained with getInputStream () is streamed to another datainputstream data stream
  • The output from Getoutputstream () is streamed to another dataoutputstream data stream
  • The server must establish a ServerSocket object that connects the client's socket object to a socket object on the server side to achieve the purpose of the connection

      try{  ServerSocket  serverForClient =new ServerSocket(2010);  }  catch(IOException e){  
  • Accept () connects the client socket to the server-side socket:
    ···
    try{Socket sc= serverforclient. Accept ();
    }
    catch (IOException e) {}
    ···
  • Receive socket connections for customers: the Accept () method returns a socket object that is connected to the client socket object
  • The client socket gets the input \ Output stream and the server-side socket gets the output \ Input stream connected to each other.
  • Using the Socket class constructor without parameters socket () Creates a socket object that calls the

    public void connect(SocketAddress endpoint) throws IOException
  • Requests and parameters socketaddress the socket of the specified address to establish a connection
  • To use the Connect method, you can use SocketAddress's subclass inetsocketaddress to create an object, Inetsocketaddress is constructed by:

  • The basic mode of UDP-based communication is:
    1. Package the data, called a packet (like loading a letter into an envelope), and then send the packet to the destination.
    2. Accept packets sent by others (like receiving envelopes), and then view the contents of the packet.
  • Create an object, called a packet, with the Datagrampacket class
  • The following two construction methods of Datagrampacket create the packets to be sent:

    DatagramPacket(byte data[],int length,InetAddtress address,int port)
    DatagramPack(byte data[],int offset,int length,InetAddtress address,int port)
  • Use the Datagramsocket class's constructor with no parameters: Datagramsocket () Creates an object that is responsible for sending the packet.

    DatagramSocket  
  • Accept the packet:
  • Another construction method of Datagramsocket datagramsocket (int port) creates an object with parameters that must be the same as the port number of the packet to be received

  • The object mail_in then accepts the packet using method receive (Datagrampacket pack).
  • Use another construction method of the Datagrampack class: Datagrampack (Byte data[],int length) to create a packet to receive the packet

    byte data[]=new byte[100]; int length=90;       
  • Remote objects:
    The object residing on the (remote) server is the object that the customer wants to request, called the remote object.
  • The agent is characterized by the same interface that it implements with remote objects.
  • Stub: A special bytecode that causes the stub object to be the proxy for the remote object
  • Remote interface: RMI in order to identify an object that is a remote object, an object that can be requested by the client, the remote object must implement the Java.rmi in the package

    Problems in teaching materials learning and the solving process
  • 1: What are the different points of UDP-based communication and TCP-based communication?
  • Issue 1 Solution: UDP-based information delivery is faster, but does not provide reliability assurance

    Problems in code debugging and the resolution process
  • Question 1: When you hit the code, there is such a mistake, in the case of not carefully read the program, can not be based on the error to exclude the cause
  • Problem 1 Solution: After reading the code carefully, we find that this is an output statement, and the system loses a space in the middle of the error.

    Code Hosting

This week seems to have changed some of the previous code, so the amount of code for this week is counted. Actually, the code volume is 516.
(run result of statistics.sh script)

Last week's summary of the wrong quiz
    • Wrong question 1: Which narrative is correct for the following procedure? A
      A.JVM thinks the application has a total of two threads.
      B.JVM that the application has only one main thread.
      C.JVM that the application has only one thread thread.
      D. The program has a compilation error and cannot be run.
    • Error 2: The basic state of the process is: new, running, blocked, dead. A
      A.true
      B.false
Other (sentiment, thinking, etc., optional)

The knowledge I learned this week has made me realize that Java is not limited to local applications, and in addition to databases, it is possible to transmit and receive packets over the network and implement some operations.

Learning progress Bar
lines of code (new/cumulative) Blog Volume (Add/accumulate) Learning Time (new/cumulative) Important Growth
Goal 5000 rows 25 Articles 400 hours
First week 235/235 1/1 15/15
Second week 224/459 2/3 15/30
Third week 443/902 1/4 15/73
Week Four 577/1479 2/6 17/90
Week Five 1222/2360 1/7 14/104
Week Six 1527/3294 1/8 14/118
Seventh Week 591/3883 1/9 14/132
Eighth Week 1705/5158 1/10 12/144
Nineth Week 516/5674 1/11 14/158

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