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

Source: Internet
Author: User
Tags stub thread class

20165312 2017-2018-2 "Java program Design" 9th Week study summary last week wrong title summary

1. The basic status of the process is: new, running, blocked, dead.

A. True
B. False

Resolution: A

The topic I was doing when I was reading the story is that the new thread is going through 4 states in one complete life cycle: New, running, interrupted, and dead . So I chose B, but I did not read the problem carefully, the problem is that the thread rather than the process.

I went through the book again and looked again at the definition and the difference between the process and the thread. A process is a dynamic execution of a program that corresponds to a complete process from code loading to execution to completion. A thread is a smaller execution unit than a process, and a process produces multiple threads during its execution.

I searched the web for the basic status of the process, and there were five basic states of the process.

Create status : The process needs to request a blank PCB when it is created, fill in the information of the control and management process, and complete the resource allocation. If the creation of the work cannot be completed, such as the resources can not be satisfied, it can not be scheduled to run, the status of the process is called the creation State

Ready state : The process is ready, assigned to the required resources, and can be run as soon as it is allocated to the CPU
Execution state: After the process is ready, the process enters the execution state

Blocking Status : The process being executed is temporarily unable to run due to certain events (I/O requests, failed request buffers), and processes are blocked. Enter ready state to wait for system calls when the request is satisfied

Termination Status : The process ends, or an error occurs, or is terminated by the system and enters the terminating state. No more execution

After the end of the process, the JVM ends the Java application

D. The Java language uses the thread class and its child class objects to represent threads

Parsing: AD

This topic I originally selected is AD, the title answer is wrong. C option: If no other thread is created in the main method, the JVM ends the Java application when the main method finishes executing the last statement, and if another thread is created in the main method, the JVM will switch between the main thread and the other threads in turn.

Summary of learning contents of textbook
    • 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

public URL(String spec) throws MalformedURLException
public URL(String protocol, String host,String file) throws MalformedURLException

  • To read a resource in a URL:
    URL Object invocationInputStream 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:
    • Static methods of the InetAddress classgetByName(String s);
    • Gets a InetAddress object that contains the domain name and IP address of the host address
  • Get the address of the local machine: static method through the InetAddress classgetLocalHost()
  • 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{  
  • Mysocket Related methods
  • getInputStream()Get an input stream
  • getOutputStream()Get an output stream
  • getInputStream()stream the resulting input to another datainputstream data stream
  • getOutputStream()the resulting output flows 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  
  • 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:
    InetSocketAddress(InetAddress addr, int port)
  • 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)
  • Using the Datagramsocket class without parameters: DatagramSocket() Create 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 the same parameters as the port number of the packet to be received

  • The object mail_in then uses the method to accept the packet receive(DatagramPacket pack) .
  • Use another construction method of the Datagrampack class: DatagramPack(byte data[],int length) 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

Code Hosting Reference

Five basic states of the process

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