Ecosystem
Ecosystem
Introduction
In this lesson, you'll learn about ecosystem in Java. Coming from TypeScript, you already have a foundation for understanding this concept. We'll build on that knowledge while highlighting the key differences.
In TypeScript, you're familiar with ecosystem.
Java has its own approach to ecosystem, which we'll explore step by step.
The Java Way
Let's see how Java handles this concept. Here's a typical example:
// pom.xml (Maven) or build.gradle (Gradle) — dependency management
// Dependencies pulled from Maven Central
// Spring Boot web server
@RestController
public class HelloController {
@GetMapping("/")
public String hello() {
return "Hello";
}
}
// JUnit 5 testing
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
class AddTest {
@Test
void sumsTwoNumbers() {
assertEquals(3, add(1, 2));
}
}Comparing to TypeScript
Here's how you might have written similar code in TypeScript:
// package.json — dependency management
// npm install express axios jest
import express from "express";
const app = express();
app.get("/", (req, res) => res.send("Hello"));
app.listen(3000);
// Testing with Jest
import { describe, it, expect } from "@jest/globals";
describe("add", () => {
it("sums two numbers", () => {
expect(add(1, 2)).toBe(3);
});
});You may be used to different syntax or behavior.
npm → Maven Central (via Maven pom.xml or Gradle build.gradle)
You may be used to different syntax or behavior.
Express.js → Spring Boot (dominant Java web framework)
You may be used to different syntax or behavior.
Jest/Vitest → JUnit 5 + Mockito
You may be used to different syntax or behavior.
Node.js runtime → JVM (runs on servers, Android, embedded systems)
Step-by-Step Breakdown
1. Maven vs npm
Maven uses pom.xml (XML) to declare dependencies. Gradle uses build.gradle (Groovy/Kotlin DSL). Both download from Maven Central, the equivalent of the npm registry.
// package.json
"dependencies": {
"express": "^4.18"
}<!-- pom.xml -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>3.2.0</version>
</dependency>2. Spring Boot = Express + More
Spring Boot is the most popular Java web framework. It provides dependency injection, REST APIs, database access (JPA), security, and more out of the box.
app.get("/users/:id", async (req, res) => {
const user = await db.findUser(req.params.id);
res.json(user);
});@GetMapping("/users/{id}")
public User getUser(@PathVariable int id) {
return userService.findUser(id);
}3. JUnit 5 Testing
JUnit 5 is the standard Java testing framework. @Test marks test methods. Assertions use static imports. Mockito handles mocking.
it("returns user", async () => {
expect(await getUser(1)).toEqual({ id: 1 });
});@Test
void returnsUser() {
assertEquals(new User(1), userService.getUser(1));
}4. JVM Use Cases
The JVM powers Android development (Kotlin/Java), enterprise backends, big data (Hadoop/Spark), and financial systems. TypeScript dominates web front-ends and serverless. They often coexist in the same architecture.
// Node.js: web APIs, serverless, real-time, CLI tools// JVM: enterprise APIs, Android, big data,
// financial systems, microservices at scaleCommon Mistakes
When coming from TypeScript, developers often make these mistakes:
- npm → Maven Central (via Maven pom.xml or Gradle build.gradle)
- Express.js → Spring Boot (dominant Java web framework)
- Jest/Vitest → JUnit 5 + Mockito
Key Takeaways
- Maven (pom.xml) or Gradle (build.gradle) replaces npm for dependency management
- Spring Boot is the dominant Java web framework
- JUnit 5 + Mockito is the standard testing stack
- JVM powers enterprise, Android, and big data workloads