Can we create a server in Java without Spring or any other framework?

Yes, it is completely possible to create a server in Java without using Spring, Jakarta EE, or any other framework. Java provides built-in APIs that allow developers to create TCP, UDP, and HTTP servers directly using core Java classes. Frameworks mainly simplify development, but they are not mandatory for building server applications.

Key Points

How Can We Create a Server in Core Java?

Java provides several options

1. ServerSocket

Used for creating TCP servers.

Common Use Cases

Example Flow

Client

|

Socket Connection

|

ServerSocket

|

Server Processes Request

2. HttpServer

Java provides a lightweight HTTP server implementation through

com.sun.net.httpserver.HttpServer

Common Use Cases

3. DatagramSocket

Used for UDP-based communication.

Common Use Cases

Example

Suppose we want to build a simple web server that returns

Hello World

This can be done using Java's built-in HttpServer without Spring Boot.

import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpExchange;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;

public class SimpleServer {

    public static void main(String[] args)
            throws IOException {

        HttpServer server =
                HttpServer.create(
                        new InetSocketAddress(8080),
                        0);
        server.createContext("/hello",
                (HttpExchange exchange) -> {

                    String response =
                            "Hello World";

                    exchange.sendResponseHeaders(
                            200,
                            response.length());

                    OutputStream os =
                            exchange.getResponseBody();

                    os.write(response.getBytes());

                    os.close();
                });

        server.start();

        System.out.println(
                "Server started on port 8080");
    }
}

Request

http://localhost:8080/hello

Response

Hello World

Creating a TCP Server Using ServerSocket

import java.net.ServerSocket;
import java.net.Socket;

public class TcpServer {

    public static void main(String[] args)
            throws Exception {

        ServerSocket serverSocket =
                new ServerSocket(8080);

        System.out.println(
                "Waiting for client...");

        Socket client =
                serverSocket.accept();

        System.out.println(
                "Client Connected");
    }
}

This creates a basic TCP server that waits for client connections.

Core Java Server vs Spring Boot

Feature Core Java Spring Boot

HTTP Server Manual Built-In

Dependency Injection No Yes

REST API Support Manual Automatic

Configuration Manual Simplified

Learning Curve Lower Higher

Development Speed Slower Faster

Enterprise Features Limited Rich

When Should You Use Core Java?

When Should You Use Spring Boot?

Real-World Example

Spring Boot itself does not create networking concepts from scratch.

Internally it relies on

This means frameworks simplify development, but the underlying server concepts still come from Java.

Interview Tip

A concise interview answer is

Yes, a server can be created in pure Java without any framework. Java provides built-in APIs such as ServerSocket for TCP communication and HttpServer for HTTP services. Frameworks like Spring Boot simplify server development by providing additional features such as dependency injection, REST support, and configuration management, but they are not required to create a server.

Last updated: 11 November 2026

Previous question: What is the Java Memory Model, and how is it related to threads?

Next question: What is the transient keyword in Java?

More Core Java - Level II interview questions

All Core Java - Level II questions