Dev1

Module 1 — Backend Development with Java

Module 1 — Introduction to Backend Development (Java)

Instructor note (professor-level): This module grounds students in backend principles and demonstrates how Java fits into server-side development. The emphasis is conceptual first, then practical: we’ll build a minimal Spring Boot REST endpoint, connect to a database, and verify behavior with HTTP tools.

Learning outcomes

  • Explain client–server architecture and HTTP fundamentals.
  • Set up a Java backend project (Maven/Gradle) and run a Spring Boot application.
  • Implement a simple REST API endpoint and test it using curl/Postman.
  • Understand basic database connectivity using JDBC/JPA.

1. Conceptual overview

Client–server model: clients (web browser, mobile app) issue HTTP requests to servers which implement application logic, access databases, and return responses. Key concepts: stateless requests, endpoints, resources, and representation (typically JSON).

Why Java for backend? Mature ecosystem, strong typing, excellent concurrency primitives, robust libraries (Spring), and widespread enterprise adoption. Java is a good choice for production-grade services.

2. HTTP and REST basics

  • Methods: GET, POST, PUT, DELETE, PATCH
  • Status codes: 2xx success, 4xx client error, 5xx server error
  • Headers, body, content-type (application/json)
  • Statelessness and idempotency

3. Java backend ecosystem (short survey)

  • Servlet API: low-level specification for handling HTTP in Java web containers.
  • Spring Framework / Spring Boot: dominant choice for rapid development of microservices and web APIs.
  • Jakarta EE: enterprise specification (former Java EE) for large systems.
  • Persistence: JDBC, JPA/Hibernate for ORM.
  • Build tools: Maven, Gradle.

4. Quick hands-on: Minimal Spring Boot REST service

Below is a minimal example showing a Spring Boot application with a single REST controller. This is intentionally succinct for teaching; in production we add layers, DTOs, validation, and tests.

pom.xml (minimal)

<project xmlns="http://maven.apache.org/POM/4.0.0" ...>
  <modelVersion>4.0.0</modelVersion>
  <groupId>edu.example</groupId>
  <artifactId>module1-demo</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.2.0</version>
  </parent>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
      <scope>runtime</scope>
    </dependency>
  </dependencies>
</project>

Application main (Java)

package edu.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Module1DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(Module1DemoApplication.class, args);
    }
}

Simple REST controller

package edu.example.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/hello")
public class HelloController {

    @GetMapping
    public String hello() {
        return "Hello from Java backend (Module 1)";
    }
}
Run: mvn spring-boot:run (or build with mvn package and run the jar). By default the service listens on http://localhost:8080. Test with curl http://localhost:8080/api/hello or Postman.

5. Database connectivity (intro)

For Module 1 we’ll demonstrate an embedded H2 datasource and JPA entity — enough to show persistence without external DB setup.

@Entity
public class Person {
  @Id
  @GeneratedValue
  private Long id;
  private String name;
  // getters/setters
}

public interface PersonRepository extends JpaRepository<Person, Long> { }

// Use the repository in a controller or service to perform CRUD operations.

6. Tools & workflow

  • IDE: IntelliJ IDEA (recommended) or Eclipse
  • Build: Maven or Gradle
  • HTTP testing: curl, Postman, or HTTPie
  • Logging: Logback (default in Spring Boot)

7. Security & best-practices (intro)

At this stage, be aware of input validation, use of HTTPS in production, and don’t store secrets in source. For authentication we will cover JWT and Spring Security in later modules.

8. Exercises (practical)

  1. Initialize a new Spring Boot project (start.spring.io) with Web and H2 dependencies. Run the application locally.
  2. Create the /api/hello endpoint and verify with curl.
  3. Create a Person entity and a repository. Implement endpoints to create and read Person records.
  4. Document one HTTP request and response (headers, body, status) and explain why the status code was chosen.

9. Assessment (professor’s rubric)

  • Pass: Runs the app, implements /api/hello, and demonstrates at least one persistent entity saved to H2.
  • Credit: Clean project layout, basic input validation, and README with run instructions.
  • Distinction: Adds unit tests for controller/repository and documents API with OpenAPI/Swagger.

10. Further reading & references

  • Spring Boot reference documentation (spring.io)
  • Baeldung tutorials on Spring and JPA
  • Oracle Java documentation

Prepared from a professor’s perspective — technical, concise, and focused on concrete skills. Use this page as the starter lecture and lab sheet for Module 1.

Latest Notes

View Archive [ -> ]