lichMax
Level 40
Санкт-Петербург

Level 40

Published in the Random EN group
Level 40In fact, the following questions were at this level:
  1. What is an IP address?
  2. What is the difference between host and domain?
  3. What methods in HTTP do you know
  4. What is the difference between GET, POST and HEAD methods?
  5. What is REST?
  6. Why is the Calendar class needed in Java?
  7. How to convert date in java to desired format?
  8. What is the difference between URI and URL?
  9. What are sockets?
  10. Difference between Socket and URL classes?
And here are my answers:
  1. An IP address is a unique network address of a node in a computer network built on the TCP/IP protocol stack. The Internet requires global address uniqueness; in the case of working in a local network, the uniqueness of the address within the network is required. In the IPv4 protocol version, the IP address is 4 bytes long, and in the IPv6 protocol version, the IP address is 16 bytes long. Typically, an IP address in the IPv4 version of the protocol is written as four decimal numbers with values ​​from 0 to 255, separated by a dot, for example, 192.168.0.3.

  2. A domain is a website address or a specific zone that has its own name, unlike any other name in the domain name system. Domains are first level, second level, third level, etc. Usually, a first-level domain is not available to ordinary users for registration (examples of first-level domains are ".ru", ".com", ".net"). Usually domains of the third and following levels are called subdomains.
    A host is a specific computer or server connected to a local or global network. The host has a unique address in the TCP/IP service environment (IP address).

  3. GET, POST, PUT, DELETE, OPTIONS, HEAD, PATCH, TRACE, LINK, UNLINK, CONNECT.

  4. GET POST HEAD
    Request Body No Eat No
    Response Body Yes Yes No
    Query result caching Yes No Yes, headers
    Idempotency Yes No Yes

    The GET method is used to request the contents of the specified resource. The POST method is used to submit user data to a given resource. The HEAD method is typically used to retrieve metadata, check for the existence of a resource (URL validation), and see if it has changed since it was last accessed. The HEAD method is similar to the GET method, except that there is no body in the server response. The GET method is considered a simplified version of POST, because the GET method does not imply a full-fledged request, only a URL as such.

  5. REST is an architectural style for the interaction of distributed application components on a network. The term was coined by Roy Fielding in 2000. He also introduced the requirements that a distributed application must satisfy in order to comply with the REST architecture (such applications are also called RESTful). Here are the requirements:

    1. Client-Server model (means that the network should consist of a client and a server; the server is the one who has the resources, the client is the one that requests them))
    2. Stateless (meaning that neither the client nor the server keep track of each other's states)
    3. Caching (clients and intermediate nodes can cache the results of requests; accordingly, server responses must have an explicit or implicit indication that they are cacheable or not cacheable)
    4. Interface uniformity (means that there is a common language of interaction between clients and servers that allows them to be replaced or changed without violating the integrity of the system):
      • Resource definition (means that each resource must be identified by a permanent identifier)
      • Resource management through a view (means that the client stores the resource in the form of its representation, and if it wants to change the resource, it sends information to the server about how it would like to see this resource; the server considers this as a request as an offer, and decides what to do with the stored resource)
      • Self-contained messages (each message contains enough information to understand how to process it)
      • Hypermedia (means that clients change the state of the system only through actions that are dynamically defined in hypermedia on the server)
      • Layer system (means that the system can have more than two layers (client and server), and at the same time each such layer knows only about its neighboring layers, and does not know about the other layers, and interacts only with neighboring layers)
      • Code on demand (means that the functionality of the client can be extended by downloading code from the server in the form of applets or scripts)

      Satisfying these requirements allows you to achieve the following:

      • Reliability
      • Performance
      • Scalability
      • Transparency of interaction
      • Simplicity of interfaces
      • Component Portability
      • Ease of making changes
      • Ability to evolve to meet new requirements
  6. It is needed for more convenient work with date and time. It allows you to work with the date within the calendar, that is, it allows you to add and subtract days from a specific date, and leap years will also be taken into account. In addition, it allows you to represent time in milliseconds in a convenient form - year, month, day, hour, minute, second. There are also many methods for setting and getting various date and time parameters, for example: day of the week, day of the month, day of the year, week number in the month, week number in the year.
  7. There is a handy class for this SimpleDateFormat. An instance of this class can be passed a date representation template, and then it will return the date in this form (in the format of a string String), or read the date (from a string String). It all looks like this:

    Date date = new Date(); // получаем текущую date
    SimpleDateFormat formatter = new SimpleDateFormat("d-MM-yy HH:mm:ss"); //создаём экземпляр класса SimpleDateFormat
             								//и передаём ему шаблон представления даты и времени
    String dateAsString = formatter.format(date); //преобразуем date в строку заданного формата
    
    Date dateAfterConversion = formatter.parse(dateAsString); //преобразуем строку обратно в date
  8. URI stands for Uniform Resource Identifier and translates as "Uniform Resource Identifier". A URI is a sequence of characters that identifies an abstract or physical resource. URL stands for Uniform Resource Locator. That is, it is a kind of unified pointer to a resource that uniquely determines its location. A URL is a standardized way of recording the address of a resource on the Internet.
    Their differences are that the URI is some kind of resource identifier that allows this resource to be somehow identified, and the URL is a pointer to the resource, it gives information about where the resource is located. Thus, a URL is a URI that, in addition to identifying a resource, provides information about its location.

  9. Sockets are a bunch of IP address + port , which allows you to uniquely identify a program on a computer or server from an external network. Java has two socket classes Socketand ServerSocket. Instances of the first class play the role of a client, instances of the second class play the role of a server. The client can send and receive messages over the socket. The server constantly monitors user requests and responds to them.
    In order to send data via a socket, Socketthere is a class in the class getOutnputStream()that returns an outgoing stream, with which you can already work as usual. To receive information, you need to use the methodgetInputStream()An that returns the incoming stream. Further with this flow, you can work as usual with input later. It is also worth noting that when creating a client socket (class instance Socket), you need to pass the server ip-address and the port on which the receiving server program is running to the constructor.
    When creating a server socket (an instance of the class ServerSocket), you only need to specify the port through which the program will work. After that, the method is called accept(). This method waits for a client to connect, and then returns an instance of the class Socketrequired to interact with that client. Further work goes with an instance of the class Socket, as in the first case (in the case of the client).

  10. The main difference is that the URL class is designed to work with a URL string (URL string parsing), while the Socket is used to connect to a remote server and send information to the server and / or receive information from the server (although using the URL class, you can access the resource pointed to by the URL itself; but this is not done directly, but through an object of the URLConnection class). Also, generally speaking, a Socket is used to communicate with a server (another program), and a URL is used to access a resource (for example, a file). Also, URL and URLConnection are mostly HTTP oriented, while Socket can work with any protocol.
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION