CodeGym /Java Blog /Java Developer /Part 1. What you need to know before learning Spring and ...

Part 1. What you need to know before learning Spring and JavaEE

Published in the Java Developer group
If you've already finished (or are close to) learning Java SE, then it's time to think about your next steps in conquering the profession of a Java developer. Part 1. What you need to know before learning Spring and JavaEE - 1 On the one hand, you already have a good understanding of Java: you know how to work with an IDE, write programs, and much more. But what should you do next with your programs? How do you make them cooler still and "unleash them on the world"? It's becoming obvious that it is time to take up the study of enterprise technologies. And now the fun begins. It doesn't matter which technology stack you decide to start with. Whether it is JavaEE or Spring, you are likely to come across a ton of things that are far, far beyond your comprehension. Between Java basics and advanced technologies there remains an intermediate step in knowledge that must be taken in order to retain what remains of your self-control and self-confidence as you read voluminous documentation. Therefore, the purpose of this series of articles is to give you the minimum theoretical knowledge necessary for your further study of JavaEE or Spring. This material is divided into 7 parts:
  1. We'll talk a little about networking.
  2. We'll examine the client-server and three-tier architecture.
  3. We'll explore the HTTP/HTTPS protocols.
  4. We'll learn everything you need to know about Maven.
  5. We're talk about logging.
  6. About servlet containers.
  7. 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 model

The 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:
7 Application
6 Presentation
5 Session
4 Transport
3 Network
2 Data link
1 Physical
Breaking the model into layers of abstraction allows developers working on the transport layer, for example, to not have to think about implementation details at the level of the network and session layers. This approach is also used in programming. Let's consider all the layers of the OSI model, and determine which ones are of interest to us:
  1. 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.

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

  3. 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: 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.

  4. 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: 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.

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

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

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

Part 1. What you need to know before learning Spring and JavaEE - 2We don't need to know how every layer of the model works. The main thing is to understand the principles behind the operation of the elements that we will have to work with when writing web applications, namely:
  • 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.
When we visit an online store, for example, we indicate its address and port. Upon our first visit, a session is created. The store can record information in the session. For example, the store might save information about items that we left in the shopping cart. If we close the tab with the online store and then go back into it later, our items will still be in the cart because they are saved in the session. Of course, all the information that we receive from the store we receive via the HTTP/HTTPS protocol, and our browser knows how to process it. You may object, saying that you never entered the address and port in the browser, and you would be partly right. What you did do was enter the domain name, which was converted by a DNS server. Let's take a better look at what's what here.

DNS (Domain Name System)

As we have already learned, each network user has a unique address. If we're talking about the application, then its unique address will be IPv4-address:port. If you know this address, you can directly access the application. Imagine that we wrote a web application that displays the average air temperature in all countries in real time. We deployed it on a server with the address, on port 8080. In order to be able to receive information from us, the user must enter 5 numbers in the browser: People don't like to memorize sets of numbers: many of us can't remember more than two phone numbers. That's why the Domain Name System was invented. We can create an "alias" for our address, for example, Instead of looking for us using an address consisting of five difficult-to-remember numbers, the user can enter our domain name in the address bar of the browser. There are DNS servers that map domain names to real addresses. For example, when a user enters in a browser, her request is sent to a DNS server, which converts it into the actual address. Part 1. What you need to know before learning Spring and JavaEE - 4This is important for us to understand, because our applications will call remote services both by domain names and by real addresses. We need to understand that in either case the services are the same. That's it for now! In this article, we looked at the basics of networking, which will come in handy as you begin to learn web programming. Next time we'll look at what a client-server architecture is and why it is so important to understand. Part 2. Let's talk a bit about software architecture Part 3. HTTP/HTTPS Part 4. The basics of Maven Part 5. Servlets and the Java Servlet API. Writing a simple web application Part 6. Servlet containers Part 7. Introducing the MVC (Model-View-Controller) pattern
Comments (1)
Andrei Level 41
6 August 2021
Nice article, thanks!