Java Overview & Environment Setup (JDK 21)
What Java is, why it dominates backend development, how the JVM works, and a step-by-step JDK installation with your first Hello World program.
Why Learn Java for Backend Development
Java is a strongly typed, object-oriented language that runs on the Java Virtual Machine (JVM). Write once, run anywhere: the same compiled bytecode runs on Windows, Linux and macOS, which made Java the default choice for enterprise backend systems since the late 1990s.
- Huge ecosystem: Spring Boot, MyBatis, Kafka, Hadoop, Elasticsearch are all JVM-first.
- Strong engineering: static typing, mature tooling, excellent IDE support (IntelliJ IDEA).
- High performance: the JIT-compiled JVM is far faster than most interpreted languages.
- Job market: banks, e-commerce, telecom and government systems run on Java everywhere.
How the JVM Works
Java source files (.java) are compiled by javac into bytecode (.class), which the JVM interprets and Just-In-Time compiles to native machine code at runtime. The JVM also manages memory: objects live in the heap, garbage collection (GC) reclaims unused objects automatically.
# 编译与运行全过程
javac Hello.java # 源码 -> 字节码 Hello.class
java Hello # JVM 启动,加载并执行字节码
# 查看 JDK 版本
java -version
javac -version
Installing the JDK
Download a JDK build from your provider of choice — Oracle JDK, OpenJDK, Amazon Corretto, Eclipse Temurin or Alibaba Dragonwell all work. LTS versions are 8, 11, 17 and 21; new projects should start on 21.
# Windows: 下载 zip 解压后设置环境变量
setx JAVA_HOME "C:\Program Files\Java\jdk-21"
setx PATH "%JAVA_HOME%\bin;%PATH%"
# Linux (apt / yum)
sudo apt install openjdk-21-jdk
java -version # 验证安装
Verify the installation with java -version and javac -version in a new terminal. Then pick an IDE: IntelliJ IDEA Community Edition is free and the industry standard; VS Code with the Java extension pack also works well.
Your First Java Program
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, BackendWiki!");
}
}
- The file must be named Hello.java, matching the public class name exactly.
- main is the entry point; String[] args receives command-line arguments.
- Compile with javac Hello.java, run with java Hello.
What to Learn Next
- Core syntax: variables, control flow, methods in this tutorial series.
- Object-oriented programming: classes, inheritance, interfaces.
- Collections Framework: List, Set, Map and generics.
- Concurrency: threads, thread pools, CompletableFuture.
- Ecosystem: Maven/Gradle build, Spring Boot framework, databases, microservices.
为什么后端开发要学 Java
Java 是一门运行在 JVM(Java 虚拟机)上的强类型面向对象语言。「一次编写,到处运行」——同一份编译后的字节码可以在 Windows、Linux、macOS 上运行,这让 Java 从上世纪 90 年代末起就成为企业级后端系统的默认选择。
- 生态极其庞大:Spring Boot、MyBatis、Kafka、Hadoop、Elasticsearch 都是 JVM 优先。
- 工程化强:静态类型、成熟工具链、IDE 支持极好(IntelliJ IDEA)。
- 性能出色:JIT 分层编译后的 JVM 远快于绝大多数解释型语言。
- 就业面广:银行、电商、通信、政务系统几乎都在用 Java。
JVM 是如何工作的
Java 源文件(.java)由 javac 编译成字节码(.class),JVM 在运行时解释并以 JIT(即时编译)方式把热点代码编译为机器码。JVM 还负责内存管理:对象分配在堆上,垃圾回收器(GC)自动回收无用的对象。
# 编译与运行全过程
javac Hello.java # 源码 -> 字节码 Hello.class
java Hello # JVM 启动,加载并执行字节码
# 查看 JDK 版本
java -version
javac -version
安装 JDK
从任意发行版下载 JDK:Oracle JDK、OpenJDK、Amazon Corretto、Eclipse Temurin(Adoptium)、阿里 Dragonwell 都可以。LTS 版本为 8、11、17、21,新项目建议直接用 21。
# Windows: 下载 zip 解压后设置环境变量
setx JAVA_HOME "C:\Program Files\Java\jdk-21"
setx PATH "%JAVA_HOME%\bin;%PATH%"
# Linux (apt / yum)
sudo apt install openjdk-21-jdk
java -version # 验证安装
在新的终端里执行 java -version 和 javac -version 验证安装。然后选择 IDE:IntelliJ IDEA 社区版免费且是行业标准;VS Code 搭配 Java 扩展包也够用。
第一个 Java 程序
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, BackendWiki!");
}
}
- 文件名必须与公开类名完全一致,命名为 Hello.java。
- main 方法是程序入口;String[] args 接收命令行参数。
- 用 javac Hello.java 编译,用 java Hello 运行。
下一步学习路线
- 核心语法:变量、控制流、方法(本系列后续文章)。
- 面向对象:类、继承、接口。
- 集合框架:List、Set、Map 与泛型。
- 并发编程:线程、线程池、CompletableFuture。
- 生态工具:Maven/Gradle 构建、Spring Boot 框架、数据库、微服务。