Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Events
Videos
Audiobooks
Packt Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Java Web Internals
Java Web Internals

Java Web Internals: Unlock the secrets of Java web servers, frameworks, and application architecture

Arrow left icon
Profile Icon Francisco Isidro Massetto
Arrow right icon
$32.39 $35.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (1 Ratings)
eBook Apr 2026 214 pages 1st Edition
eBook
$32.39 $35.99
Paperback
$43.99
eBook + Subscription
$29.99 Monthly
Arrow left icon
Profile Icon Francisco Isidro Massetto
Arrow right icon
$32.39 $35.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (1 Ratings)
eBook Apr 2026 214 pages 1st Edition
eBook
$32.39 $35.99
Paperback
$43.99
eBook + Subscription
$29.99 Monthly
eBook
$32.39 $35.99
Paperback
$43.99
eBook + Subscription
$29.99 Monthly

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Java Web Internals

1

Networks, Protocols, and Packets

The development of web applications has never been as popular as it is currently. Web systems, applications, and IoT devices are gaining more space in people's daily lives.

Therefore, the training of developers to master these technologies, languages, frameworks, and tools becomes essential – developers who are not only capable of delivering solutions to end users, but who also have in-depth knowledge of how this entire communication infrastructure works and enables this development.

For this reason, it is necessary to explore the entire infrastructure, communication models, architecture, and purpose of the services that are used to make this web environment increasingly available to end users.

Understanding how a web server works, the difference between a web server and an application server, the protocols involved, the handling of requests and responses, and the frameworks and their functioning is of paramount importance for your career. Current applications are developed as a set of pieces to be fitted together. For example, when you create a web application, lots of frameworks and libraries do the demanding work for you (database connection, some queries, request handling, response generation, etc.). But what about when things don't work? Is the error in your logic, in the misuse of the framework, or in the poor understanding of a communication protocol?

Finally, if you want to be an above-average developer, you will need to understand how technologies work behind the scenes. And that is exactly the purpose of this book: to show, step by step, how we can implement a "simple" web server, an application server, and a web framework, guaranteeing productivity, reliability, and speed in the development of your projects and applications.

Welcome to this journey, which will explore, demystify, and clarify the entire web infrastructure so you can become a developer well above the average.

In this chapter, we will cover the following main topics:

  • TCP/IP stack
  • The need for a protocol definition
  • Implementing a simple protocol using sockets

By the end of the chapter, you will understand how two applications running on different computers connected by a physical channel (a wired or wireless network) can exchange data. It's more complex than writing "Hello" to another user on a chat application. It requires several layers that control and handle different aspects to make this communication viable.

Your purchase includes a free PDF copy + code bundle

Your purchase includes a DRM-free PDF copy of this book, the code bundle, and additional exclusive extras. See the Free benefits with your book section in the Preface to unlock them instantly and maximize your learning.

Technical requirements

To understand the purpose of this chapter, we created a repository on GitHub to cover the technical aspects of protocol definition. The code corresponding to this chapter can be found on GitHub here:

https://github.com/PacktPublishing/Java-Web-Internals/tree/main/Chapter01

Java 25 is used to implement this code, and you can choose your preferred IDE, such as Eclipse, IntelliJ, or NetBeans.

Exploring the TCP/IP stack with an example

The TCP/IP stack is present in your day-to-day life, and you use connected applications extensively – your messaging app, the websites you visit, streaming apps, and more. The question is: what do they have in common?

The answer is simple, but the use can be complex and very sophisticated. They all use one or more communication channels to transfer data and, therefore, implement communication protocols. But how can this be explored in our reality? Let's understand how these techniques let us develop efficient and robust applications.

It all starts with the interconnection of computer networks (yes, your smartphone is also a computer), and because of this, we are able to develop applications that make use of this interconnection so that you can send and receive data, regardless of the medium (metallic cables, optical fiber, or even radio waves – the famous wireless).

We need to understand that for two different entities to exchange information, a series of rules need to be established. These rules range from the specifications of the sequences of bits and bytes that are transmitted, their respective meanings, and the actions that are taken depending on what is sent and received, among other things. We are talking about communication protocols.

Formally, a communication protocol is a set of rules, procedures, formats, and actions that are specified so that two or more entities can exchange information with each other. Of course, for this to happen, we need to ensure that many steps are completed, and therefore, it is necessary to separate responsibilities and ensure that certain parts of this entire process can be interchangeable and replaced.

What am I talking about? Let's think about a simple example.

Imagine a situation where the president of a Russian company wants to talk to the president of a Pakistani company to develop a new product together. How would this communication take place?

If both spoke in their respective local languages, neither of them would understand anything the other said, and so no product would be made.

So, let's think: what if we adopted a "communication protocol" between them? What if we used two translators who could respectively translate from Russian to English and from Urdu to English? Would it be easier? Certainly, translators could transmit the respective messages and translate them back to their interlocutors. Well, through this type of rule, we manage to establish communication between two different entities, as both follow this procedure and can understand what each one means. Furthermore, all communication between two entities takes place through packets. Imagine a conversation between two people: each phrase in this conversation can be considered a packet. One of these people wants to tell several facts to its interlocutor. If the text is too long, it can be sliced into phrases. Each phrase can be (metaphorically) equivalent to a packet. Formally, a packet is the smallest unit of transmission between two entities. An exceedingly long message (a download of a file) is fragmented into several packets so that we can have control over the transmission of each fragment (checking whether the fragment was transmitted and received in full, order of the fragments, confirmation of receipt of a given fragment, among others).

Now that we conceptually understand what a communication protocol is, let's turn to the more technical part of network communication today. Today, all communication is done through a stack of protocols (protocols responsible for rules at different levels). There is a reference model called Open Systems Interconnection (OSI). This is a model created by the International Organization for Standardization (ISO) and defines that communication between two entities is subdivided into seven different layers, each with its own responsibility and manipulating specific rules at each stage of communication.

The OSI model is the main model in the computing field for defining the communication standard between two distinct entities. Even though it is a reference model, it is fundamental to understanding the separation of responsibilities in each layer.

Image 1

Figure 1.1: The seven layers of the OSI model

Let's understand each of the layers:

  • Layer 1: Physical – This layer is responsible for the rules for transmitting digital signals in a physical medium (cable, optical fiber, or waves). Here, the main concern is how a set of bits is transmitted through these transmission media and at what transmission speeds.
  • Layer 2: Data Link – In this layer, the concern is to establish data delivery rules between two entities already connected by a physical medium. Among the functionalities of this layer are the identification of the peripheral that connects your entity (your computer's network card or your smartphone's antenna), ensuring that the datasets were transmitted correctly, through parity calculations, among others.
  • Layer 3: Network – Here, the protocol deals with issues related to identifying the machine that is connected to this network (it may have several communication peripherals – network cards, for example), its addressing, as well as the interconnection of several networks (the connection between your home's local network and the access provider's network), and which routes will be drawn for the message to leave its origin (your laptop) and reach its destination (the website you want to access, for example).
  • Layer 4: Transport – In this layer, the concern is whether the data will arrive consistently or not. Here, we can have two types of treatment: connected and unconnected protocols. In connected protocols, the delivery of the message, any retransmissions if the message has not been delivered, and the order of the messages are of crucial importance (an example of this is a website that needs to deliver all its content so that the browser can display the page on the screen). In non-connected protocols, concerns about possible packet losses (message fragments) are not so crucial. An example of this is streaming or video transmission, where any losses do not compromise the transmission (you just stop seeing or hearing a small part of your media)
  • Layer 5: Session – At the session layer, the rules are aimed at coordinating two connected applications. . For example, on a conference call, participants can define their conversation rules, such as: if they can talk at the same time or one of them talks and another one just listens, or if no one says anything for a period, the call finishes automatically. The OSI session layer provides a channel between entities that keeps communication active or capable of working if communication is broken without having to start it over.
  • Layer 6: Presentation – In the presentation layer, the main function is to define how the data will be presented or exchanged. For example, we can exchange data between two entities defining a common character encoding standard. In other words, the presentation layer can be a "translator" between data format representations.
  • Layer 7: Application – Here, we can find the most popular applications used on the internet, such as HTTP for web browsing, SMTP for email exchange, and FTP for file transfer. The application layer provides functions and interfaces that applications use to communicate over a network.

In this model, it is worth remembering that a given layer uses functions from the layer immediately below when transmitting data, and when receiving data, it delivers them to the layer immediately above. While the perception is that each layer of an entity communicates directly with the corresponding layer of the target entity, communication occurs from the application level to the physical level. Information is transmitted and received at the physical layer of the other entity, then delivered successively until it reaches the application layer, as shown in the following figure.

Image 2

Figure 1.2: Communication between layers

Now, in real life, this seven-layer model is implemented in a much simpler way, with a more compact model with only four layers, in addition to the application layer (where we can add functionality from the session, presentation, and application layers). The alternative model to OSI is the TCP/IP model, which has become the standard protocol of the internet. TCP/IP has the following layers:

  • Media Access layer – Encompassing the physical and data link layers of the OSI model
  • Network layer
  • Transport layer
  • Application layer – Encompassing the application, presentation, and session layers of the OSI model

Each layer's functions are the same as in the OSI model, and the TCP/IP model is currently the most used in connected applications, as it has two protocols in the transport layer. Figure 1.3 depicts the equivalence between the TCP/IP and OSI reference models:

Image 3

Figure 1.3: Equivalence between the OSI reference model and TCP/IP protocol

Considering the transport layer, TCP/IP has two protocols:

  • Transmission Control Protocol (TCP) is a reliable transport protocol that guarantees delivery and ordering of transmitted packets. Because it is reliable, each packet carries a lot of control information, adding additional overhead and impacting the effective payload size. It is widely used in most current applications, especially web applications, which we will discuss throughout this book.
  • User Datagram Protocol (UDP) is an unreliable transport protocol. This is a protocol that tolerates transmission failures. Due to this characteristic, little control information is needed in each packet, which means that the same packet compared to the TCP protocol has an increased payload size. This is very useful in real-time applications, such as video calls or Voice Over IP. Some online games use UDP as a protocol, such as Xbox Cloud Gaming and NVIDIA GeForce Now, as well as meeting tools (Zoom, Google Meet, or Microsoft Teams), and so on.

As we can see, protocols in both the seven-layer conceptual model and their implementation in the TCP/IP model are fundamental for building reliable applications. From this point on, we will focus on developing examples using the TCP connection-oriented protocol, as it provides the infrastructure for all communication between web servers and browsers.

It is important to note that this protocol stack is available and integrated into our operating systems. If you must implement an application that communicates with another, any operating system will provide a set of libraries your programming language will use. All this complexity is built in and available behind the scenes. You, as a programmer, do not need to access this entire protocol stack.

The need for application layer protocols

Okay, we understand how everything works, but what if we could implement our own application protocol? How should we think about an application? How do we plan a connected application?

To answer these questions, we will initially consider a "classical model" in the literature: the client-server communication model. This model will guide all our work throughout this book.

Basically, the application is divided into two entities: the client entity, responsible for requesting the information/resources it needs, and the server entity, responsible for providing these resources to the client. The client is an application that usually (but not necessarily) interacts with users through a proper interface (graphical or not) and needs data that is not available on it. So, it requests data from another entity: the server. For example, when you browse the internet, you are looking for information not available on your computer: news, articles, videos, or code hosted on other computers.

The server will always be a passive entity, which waits for the client to trigger communication and then respond. The client is responsible for activating the server by requesting data. We will call every request from the client a request and every return from the server a response. This way, our client/server model works with request/response-based communication, as shown in the following figure:

Image 4

Figure 1.4: Client/server request/response

Bringing this model into everyday life, the browser you use to access a website is your client, and the web server that delivers this content to be displayed in the browser is your server. Basically, the request is the address to be contacted (later, this will be much more detailed), and the response is the content of the page to be displayed.

Image 5

Figure 1.5: Browser/web server

Before exploring more complex aspects of communication between browsers and web servers, let's start a little simpler: let's understand how to fully define an application protocol between a client and a server.

Defining a very simple application protocol

Let's assume we are going to implement a remote calculator, initially, with the following six arithmetic operations:

  • Sum
  • Subtraction
  • Multiplication
  • Division
  • Power
  • Square root

In this case, to simplify things, let's define the structure of our request. Of the six operations, five expect two operands, and only one (square root) expects a single operand. Let's define a standard structure:

  • Request:
  • operand1: number
  • operand2: number
  • operator: text

An example of a sum operation can be viewed in the following code snippet. In defining the protocol that will be used, we will transmit serialized Java objects. This notation is a textual notation (in this case, the JSON format); however, the communication will be done by sending and receiving serialized Java objects.

Operation 2 + 3 → Request:
{
    "operand1": 2,
    "operand2": 3,
    "operator": "+"
}

Now, as an answer, you might be thinking that just returning a number with the result of the operation is enough, right? However, let's consider some restrictions:

  • The division cannot have the second operand with the value of 0
  • The square root cannot have the first operand with a negative value
  • We will not accept any operator other than those defined (+, -, *, /, ^, and sqrt)

Therefore, if we send data that violates some of these restrictions, our protocol needs to signal that the operation cannot be performed. Also, if we send a symbol other than the supported operators, we have to signal that the operation is not recognized.

So, our answer is as follows:

Response:

  • status: text
  • value: number

We will now see a table where our protocol handles valid and invalid requests.

Operation

Request

Response

Detail

2 + 3

{
  "op1": 2,
  "op2": 3,
  "oper": "+"
}
{
  "status":"Ok",
  "value": 5
}

Successful operation.

3 / 0

{
  "op1": 3,
  "op2": 0,
  "oper": "/"
}
{
  "status":"Invalid",
  "value": null
}

Operation failed. One of the operators violates the division constraint.

5 ** 8

{
  "op1": 5,
  "op2": 8,
  "oper": "**"
}
{
  "status":"Unsupported",
  "value": null
}

Operation failed. Informed that operation is not supported.

Once we understand this concept, we can translate it into a programming language. But first, we need to understand how to make this communication possible through sockets!

Understanding sockets

Sockets are operating system resources for communicating information between remote applications. They abstract the addressing of an application within the operating system and provide a bidirectional channel for this information exchange. To do this, we need to understand that there are two types of sockets:

  • Connected sockets use TCP as a transport protocol, ensuring communication delivery and reliability
  • Unconnected sockets use UDP as a transport protocol, providing no guarantee of delivery

The focus of this chapter is not to exhaust the subject of network communication using Java. It is just to show an example of how we can create a way for two entities to communicate through a connected protocol (TCP). If you want to delve deeper into network programming concepts, an excellent reference is the book Learning Network Programming with Java: Harness the hidden power of Java to build network-enabled applications with lower network traffic and faster processes, by Richard M. Reese, available in the Packt catalog. Also, if you are interested in Java fundamentals, a great reference is the book Learn Java 17 Programming: Learn the fundamentals of Java Programming with this updated guide with the latest features, Second Edition, by Nick Samoylov, also available in the Packt catalog.

In Java, the use of TCP sockets is simplified, allowing you to create very robust applications.

Observe the following figure, where we apply the concept of connected sockets to a client/server application.

Image 6

Figure 1.6: Socket and server socket

For us to correctly identify a process on a machine, we need two fundamental pieces of information – the machine's IP address (or its hostname) and the port:

  • The IP address identifies only the machine we want to connect.
  • The port identifies which application we want to communicate with. As a modern operating system can run multiple applications simultaneously, the port (which ranges from 1 to 65535) uniquely identifies the process on the machine)

In our example, CalcServer (as we will call our server application) creates a ServerSocket (step 1 in the preceding figure) by assigning it the port on which it will wait for connections. This function is exclusive to this class. The client application (which we will call CalcClient) also creates a socket (step 2) and assigns the remote server address (IP address and port) for connection (step 3). CalcServer receives the connection request and accepts it (step 4), creating another socket, which will be responsible for the effective exchange of messages (step 5), exactly as in the following scheme. Finally, both entities can send and receive messages by reading from and writing to sockets (step 6).

So, let's implement the code, starting with our communication protocol.

In this case, two classes are necessary: the Request class and the Response class to enable communication operations. Note that both classes implement the java.io.Serializable interface so that objects are converted to byte arrays when transmitted over the network. This is because, in this example, we are using a Java application to communicate with another Java application. If we eventually want something more flexible, allowing clients developed in other languages to communicate with our server made in Java, we will choose to serialize the objects to text (for example, a JSON format) rather than to bytes, to increase compatibility.

These conversions (from objects to byte arrays, and vice versa) are called marshaling and unmarshaling. We have the following details:

  • Marshaling – When you have an object or a data structure, you can encode it to a byte array (or a character array – a string).
  • Unmarshaling – You receive a byte (or character) array and parse it, decoding it to another structure; easier to handle in your code.

Let us explore the definition of our Request class in this code snippet:

Class Request.java
public record Request(Double op1, Double op2, String oper) {
}

Now, we can explore our Response class definition in the following code:

Class Response.java
public record Response(String status, Double value){
}

Now, let us understand how CalcServer works. In general terms, every server has a common behavior: it works in an infinite loop, accepting requests, manipulating their data, and generating responses, exactly like in the request/response model we saw earlier. The following algorithm depicts its behavior.

Create server socket to listen and bind it to a port number
while (true) {
Accepts new connections to a new socket
Reads data from new socket and assign to a request object
Creates a response object
Handle data (in this case analyzing operator and   operands
If operator is supported and operands are correct, performs the operation and sets the response status to "OK" and the operation result
If an operand is incorrect (e.g., division by zero), sets an "Invalid Operand error" on response and result is null
If an operand is not supported, sets an "Unsupported Operation" status and result is null
Sends the Response object to sender
}

The complete source code of this server is available in the following GitHub repository: https://github.com/PacktPublishing/Java-Web-Internals/tree/main/Chapter01.

If we analyze the source code, we can quickly identify each algorithm step. Every step is commented in the source code, and you can identify them easily:

// step 1
ServerSocket serverSocket = new ServerSocket(8350);
// step 2
while (true) {
    // step 2.1
    Socket socket = serverSocket.accept();
    // step 2.2
    ObjectInputStream in = new ObjectInputStream(
    socket.getInputStream());
    Request req = (Request)in.readObject();
    // step 2.3
    Response rep;;
    // step 2.4 - handling data
    switch(req.getOper()) {
        // other cases to handle ...
        case "/":
            // step 2.5
            if (req.getOp2() != 0) {
                rep = new Response("Ok",req.op1()/req.op2());
                rep.setStatus("Ok");
                rep.setValue(req.getOp1()/req.getOp2());}
            // step 2.6
            else {

                rep =  new Response("Invalid", null);
            }
            break;
        default:
            // step 2.7
            rep = new Response("Unsupported", null);
    }
    // step 2.8
    ObjectOutputStream out = new ObjectOutputStream(
    socket.getOutputStream());
    out.writeObject(rep);
}

Finally, let's explore our CalcClient class code. Its objective is only to interact with the user, receiving (according to the desired operation) the value of each operand, assembling the request, sending it, and waiting for the response to finally display it. The following algorithm describes the Client application:

  1. Reads data from the input (operation and first operand).
  2. Depending on the math operator, reads the second operand.
  3. Creates a Request object with that data.
  4. Connects to the Server application.
  5. Sends a Request object.
  6. Receives a response.
  7. Prints the result.

The complete source code is available on GitHub at https://github.com/PacktPublishing/Java-Web-Internals/tree/main/Chapter01/CalcClient/, and we can identify each step as follows:

void main(){
    // step 1
    String oper;
    Double op1, op2=null;
    oper = scanner.nextLine();
    op1 = Double.parseDouble(scanner.nextLine());
    // step 1.1
    switch(oper) {
        case "+":
        case "-":
        case "*":
        case "/":
        case "^":
            op2 = Double.parseDouble(scanner.nextLine());
            break;
    }
    // step 2
    Request req = new Request(op1, op2, oper);
    // step 3 – If you know your IP Address, you can use
    //          it. It proves the packet actually hits
    //          the whole network stack
    Socket socket = new Socket("localhost", 8350);
    // step 4
    ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
    out.writeObject(req);
    // step 5
    ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
    Response rep = (Response)in.readObject();
    // step 6
    System.out.println(rep);
}

Okay, the code is understandable. But how do we implement this in practice?

In Java, if you use an IDE such as Eclipse, NetBeans, or IntelliJ, I suggest you create three different projects:

  • One to maintain the classes that define your protocol (this could also be a library)
  • One for CalcServer
  • One for CalcClient

The key point is to reference, in both projects (CalcServer and CalcClient), the project (or library) that contains your protocol classes. This way, you maintain a single code base (without duplication) and can make communication between the server and the client compatible.

Setting up projects with an Eclipse IDE

You must import each project separately in your Eclipse IDE (protocol, server, and client). To make the server and client use the protocol classes (Request and Response), you configure the build path:

Project PropertiesBuild PathConfigure Build Path

On the screen, go to the Projects tab, and in the Classpath item, add the CalcProtocol project, as depicted in the following figure.

Image 7

Figure 1.7: Configuring the project build path on Eclipse

Remember that you must do the same operation on the CalcServer project.

Image 8

Figure 1.8: Project structure on Eclipse

Setting up a project manually

If you are not using an IDE to develop your applications, you can do it manually using command-line tools. It is necessary for you to have practice with CLI tools (bash, Windows command line, PowerShell, and others).

The protocol project (which contains Request and Response classes) is a common module for the other two projects (Server and Client). If you want to reuse it, the best alternative is to generate a JAR file for this project as follows. Step 1: you must go to your project.

Step 1: Generate a JAR file for your protocol

  1. Go to your protocol project root folder.
  2. Create (if it does not exist) a folder for your compiled classes (let's call it "bin").
  3. Compile your Java files (assuming that your files are in the src folder).
    javac -d bin *.java
  4. Generate a JAR file containing your compiled classes
    jar –create –file protocol.jar -C bin

Step 2: Compiling and Running your Server project

  1. Go to your protocol project root folder and create your bin folder.
  2. Compile your Java classes (this step is not necessary since Java 11, but if you want to ensure that your code is correct before running, you can do this). In this step (regardless of which way you choose), you must reference your protocol JAR file in the Classpath parameter.
    javac -cp <your protocol jar file> -d bin src/*.java
  3. Once your files are compiled, you have to run your Server main class (here we will assume that the filename is ServerClass).
    java -cp <your protocol jar file> bin/ServerClass

Step 3: Compiling and Running your Client project

Previously, open another terminal window.

  1. Go to your protocol project root folder and create your bin folder.
  2. Compile your Java classes (this step is not necessary since Java 11, but if you want to ensure that your code is correct before running, you can do this). In this step (regardless of which way you choose), you must reference your protocol JAR file in the Classpath parameter.
    javac -cp <your protocol jar file> -d bin src/*.java
  3. Once your files are compiled, you have to run your Server main class (here we will assume that the filename is ClientClass).
    java –cp <your protocol jar file> bin/ClientClass

Now, regardless of which option you choose, let us run our applications. You must first run the server project (because it creates the socket that listens for connections), followed by the client project to interact with the user and send/receive messages.

The following figures show both application behaviors. Figure 1.9 depicts the server showing no console interaction, waiting for the client's request:

Image 9

Figure 1.9: Server running showing no messages waiting for the client's request

Figure 1.10 shows the client interacting with the user, who inputs the operation (+) and two operands (3 and 8).

Image 10

Figure 1.10: Client interacting with the user

Figure 1.11 depicts the server receiving the client's request.

Image 11

Figure 1.11: Server receiving client's request and printing messages on the console

Figure 1.12 depicts the client printing the result output.

Image 12

Figure 1.12: Client receiving server's response and outputting the result

Summary

In this chapter, we learned about the fundamentals of communication between processes on different machines. The existence of a communication protocol is essential. In this case, we were able to understand the OSI reference model and the most popular implementation, TCP/IP. Furthermore, we created a client-server application where we were able to define everything from the protocol rules to its Java code.

In the next chapter, we will explore how the HTTP protocol works and start modeling our own web server to understand how web communication works.

Get this book's PDF copy, code bundle, and more

Scan the QR code (or go to packtpub.com/unlock). Search for this book by name, confirm the edition, and then follow the steps on the page.

Image 13
Image 14

Note: Have your invoice handy. Purchases made directly from the Packt website don't require an invoice.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Build a multithreaded HTTP server and application container using Java sockets
  • Understand and replicate the internal mechanics of Tomcat and Jakarta EE, and Spring features
  • Develop a modular Java framework with annotation-based routing and dependency injection
  • Purchase of the print or Kindle book includes a free PDF eBook

Description

Ever wondered how web servers like Tomcat process requests, or what really happens behind frameworks such as Spring? This book takes you beneath the surface of Java web development to uncover the why behind the tools you use every day. Rather than focusing solely on coding recipes, this book emphasizes the underlying concepts and design principles that govern how web servers and frameworks operate. Starting with low-level socket programming, you’ll build a multithreaded HTTP server from the ground up and extend it into a lightweight application server capable of handling dynamic content. Along the way, you’ll master HTTP request parsing, response generation, servlet-like request handling, and Java reflection and annotations for metaprogramming. As you progress, you’ll evolve this infrastructure into your own Java framework with embedded Tomcat, annotation-driven routing, object serialization with Jackson, and basic dependency injection modeled on Jakarta CDI. By the end of this journey, you’ll understand the principles behind them, enabling you to reason about system design, troubleshoot complex issues, and apply these concepts across frameworks and programming languages. *Email sign-up and proof of purchase required

Who is this book for?

Java developers, computer science students, and educators seeking a deep, hands-on understanding of web server internals and application framework design. Prior knowledge of Java and basic networking concepts is recommended.

What you will learn

  • Implement a multithreaded web server using Java sockets
  • Decode and construct HTTP requests and responses manually
  • Build an application container to serve dynamic Java classes
  • Serialize and deserialize JSON data using Jackson
  • Structure projects with modular static and dynamic content
  • Replicate the internal mechanics of Tomcat, Jakarta EE, and Spring features
  • Manage lightweight session handling and routing logic
  • Create and deploy a complete custom Java web framework

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 23, 2026
Length: 214 pages
Edition : 1st
Language : English
ISBN-13 : 9781835881491
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Apr 23, 2026
Length: 214 pages
Edition : 1st
Language : English
ISBN-13 : 9781835881491
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Table of Contents

14 Chapters
Chapter 1: Networks, Protocols, and Packets Chevron down icon Chevron up icon
Chapter 2: Workings of a Web Server – A Case Study Chevron down icon Chevron up icon
Chapter 3: Implementing a Simple Web Server Chevron down icon Chevron up icon
Chapter 4: Web Servers vs Application Servers Chevron down icon Chevron up icon
Chapter 5: Deep Dive into Simple Web Container Implementation Chevron down icon Chevron up icon
Chapter 6: Simple Web Container Improvements and Expansions Chevron down icon Chevron up icon
Chapter 7: Why Create a Web Framework Chevron down icon Chevron up icon
Chapter 8: Web Frameworks – The Necessary Abstraction for Professional Development Chevron down icon Chevron up icon
Chapter 9: Detailing the SimpleWebFramework Implementation Chevron down icon Chevron up icon
Chapter 10: The Emergence of Dependency Injection and Its Application in SimpleWebFramework Chevron down icon Chevron up icon
Chapter 11: Creating the First Application with SimpleWebFramework Chevron down icon Chevron up icon
Chapter 12: Unlock Your Exclusive Benefits Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(1 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Harish Padmanaban Jun 19, 2026
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Feefo Verified review Feefo
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.

Modal Close icon
Modal Close icon