Java ninth week learning summary

The ninth week of Java learning summary

Code screenshot:

Learning Content:

URL class

The URL class is an important class in the java.net package. An instance of URL encapsulates a uniform resource locator. An application that uses URL to create an object is called a client program.
A URL object usually contains the most basic three parts of information: protocol, address, resource.

Construction method:

The URL class typically creates a URL object using the following constructor:
**public URL(String spec) throws MalformedURLException**

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

InetAddress class

  • Address representation: domain name, IP address
  • Get the host address on the Internet: use the static method getByName(String s) of the InterAddress class to return the domain name and IP address of the object containing the host address.

  • public String getHostName() Get the domain name contained in the object
  • getHostAddress() gets the IP address contained in the object.
  • Get the local address: Use the static method getLocalHost() of the InterAddress class, and the returned object contains the domain name and IP address of the local machine.

Broadcast datagram:

  • Class D addresses are not used to represent your location, i.e. you cannot use class D addresses to find computers on the network.
  • 224.0.0.0~224.255.255.255 are reserved addresses and are called class D addresses.
  • Hosts that want to broadcast or receive broadcasts must all be joined to the same class D address.

Code cloud link: https://gitee.com/BESTI-IS-JAVA-2018/20165213zqh

Guess you like

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