- We'll talk a little about networking.
- We'll examine the client-server and three-tier architecture.
- We'll explore the HTTP/HTTPS protocols.
- We'll learn everything you need to know about Maven.
- We're talk about logging.
- About servlet containers.
- And finally, about MVC.
Part 1. We'll talk a little about networking.Let's start with what matters most by talking about what every social network, web service and web app, instant messenger and simple website is built on — the network ( in the context of this series of articles, the term "network" means the Internet). The network consists of a huge number of computers: they are interconnected and able to communicate. It is important to understand how they do this, because web applications send information from one computer to another.
OSI modelThe Open Systems Interconnection (OSI) model creates a tiered approach to building a network. It clearly shows how and at what layer entities of the same network can interact with each other. In all, this model contains 7 layers:
Physical layer — This layer deals with the laws of physics and how to use them for our purposes. For example, creating cables and laying them to entities in the network.
This layer does not interest us.
Data link layer — This layer is responsible for transmitting data to network nodes and creating data transmission channels for physical objects.
This layer does not interest us unless you want to write firmware for the hardware that establishes data links.
Network layer — This layer is for determining individual network users' addresses and the routes to them. There's value in learning more about the details of this layer, namely, network addresses.
Network addresses are defined by a special protocol: the most common is IPv4 (Internet Protocol version 4). This is the protocol that a web programmer needs to use to contact another network user.
An IPv4 address consists of four byte values separated by periods, for example: 192.0.2.235. You should remember that these values are bytes, which means that they lie within the range 0..255.
IP addresses, in turn, are divided into classes. We can't simply assign ourselves a beautiful combination of numbers, but we won't go very deep here. It's enough to understand that an IP address uniquely identifies a network user and can be used to contact that user.
Transport layer — This layer handles delivering information to an addressee. Various protocols are used to accomplish this. For now, we are not interested in them. We are much more interested in the concept of a port, which appears at this layer.
Ports are responsible for identifying a specific application on a computer. For example, suppose you write a chat app in Java, install it on 2 computers, and want to send a message to your buddy. Your message is packaged, sent to a specific IP address, and delivered to your buddy, but his computer doesn't know what to do with the information received, because it doesn't understand which application should process your message. When network entities communicate, ports are used to indicate which application should process the information.
The port is a number in the range from 0 to 65535. It is added to the IP address after a colon: 192.0.2.235:8080. But you cannot use all the ports in the specified range: some of them are reserved for the operating system, others are customarily used for specific purposes. We will not delve into the purposes of different ports. For now, it is enough to understand their role in the process of communication on the network.
Session layer — This layer creates and manages communication sessions. At this layer, it becomes possible for applications to interact, sending service-level requests. What we need to know is that at this layer a session is opened between two users, and we have to work with the session.
A session is an entity created when a connection is established between two users. It can store necessary information about a user and about the history of interaction with the user. An important detail is that when the exchange of information stops, the session does not disappear. Instead, it retains its state for a set period of time, so users can continue to exchange information after a break.
If an application is communicating with several users at the same time, then a corresponding number of connections (and thus sessions) are established. Each session has a unique identifier (ID), which allows the application to distinguish between the users with whom it is communicating.
Presentation layer — This layer is responsible for encoding/decoding data. Obviously, if we need to send the string "Hello web" to another user, it is first converted into (encoded as) binary code, and only then it is sent. Upon reaching the recipient, the message is converted back (decoded), and the recipient can see the original string. These actions take place at the presentation layer.
Application layer is the most interesting layer for us. It allows applications to communicate with the network. At this layer, we receive and send messages, and make requests to services and remote databases.
There are many protocols used at this layer: POP3, FTP, SMTP, XMPP, RDP, SIP, TELNET and, of course, HTTP/HTTPS. A protocol is a universal agreement that we adhere to when communicating. We will definitely provide a separate detailed discussion of HTTP/HTTPS.
- IP address — The user's address in the network
- Port — The address of a specific user's application
- Session — An entity that exists throughout the period of communication between two users
- Application protocols (HTTP/HTTPS) — These are rules that we will follow when composing and sending messages.