概念
结论与未来展望
从 JVM 基础到高级并发和测试的完整学习路径,梳理出下一步的专业发展路线。
Phase 1: The foundation
- The Java mindset: 我们了解了 JVM 如何将我们的代码转换为平台无关的字节码,从而实现“编写一次,随处运行”。
- Variables, types, and operators: 我们区分了基本类型和引用类型,以高效管理内存并进行精确计算。
- Control flow and methods: 我们使用循环、条件语句和可重用的方法来组织应用逻辑。
- Classes and objects: 我们通过封装状态和行为来建模现实世界中的实体,学习了访问控制的重要性。
- Inheritance and polymorphism: 我们使用抽象类和接口设计可扩展的系统,以在不同类型之间共享行为。
- Strings and arrays: 我们掌握了文本处理和固定大小数据存储,理解了 String 的不可变性。
Phase 2: The core toolkit
- Advanced OOP features: 我们使用 Enums、内部类和 Records 来优化模型,写出更具表现力的代码。
- Exception handling: 我们通过捕获运行时错误并优雅地管理调用栈,为应用程序增加了可靠性。
- File and data I/O: 我们与外部世界交互,学习了读取文件、管理路径以及序列化数据。
- Collections framework: 我们超越数组,使用 List、Set 和 Map 来管理动态对象组。
- Generics and type safety: 我们编写了灵活且可重用的组件,在编译时保持严格的类型安全。
Phase 3: Scale and concurrency
- Functional programming: 我们从命令式循环转向声明式 Lambdas 和 Streams,关注要处理的内容而非处理方式。
- Threads and concurrency: 我们进入多任务处理的世界,学习了线程的生命周期以及竞态条件的危险。
- Modern concurrency tools: 我们使用 Executors 和
CompletableFuture扩展应用,构建响应迅速、非阻塞的系统。 - Reflection and metadata: 我们学习了如何在运行时动态检查和修改代码结构,这是理解框架的关键技能。
- Testing, logging, and build tools: 我们专业化了工作流程,通过 JUnit 确保代码质量,并探索了构建生态系统。
1import java.util.List; 2import java.util.stream.Collectors; 3 4// 1. Records (Module 7): Immutable data carriers with minimal boilerplate 5record Order(int id, String status, double value) {} 6 7public class JavaJourneySynthesis { 8 public static void main(String[] args) { 9 // 2. Factory Methods (Module 10): Creating immutable collections 10 var orders = List.of( 11 new Order(101, "NEW", 50.0), 12 new Order(102, "SHIPPED", 120.0), 13 new Order(103, "CANCELED", 0.0), 14 new Order(104, "NEW", 200.0) 15 ); 16 17 processOrders(orders); 18 } 19 20 static void processOrders(List<Order> orders) { 21 System.out.println("Processing Orders Report:"); 22 23 // 3. Streams & Lambdas (Module 12): Declarative data processing 24 var report = orders.stream() 25 // Filter: Keep only active orders 26 .filter(o -> !o.status().equals("CANCELED")) 27 .map(o -> { 28 // 4. Switch Expression (Module 3): Logic as values 29 String priority = switch (o.status()) { 30 case "NEW" -> o.value() > 100 ? "HIGH" : "NORMAL"; 31 case "SHIPPED" -> "DONE"; 32 default -> "UNKNOWN"; 33 }; 34 35 // 5. Text Blocks & Formatting (Module 9): Clean output 36 return "Order #%d [%s]: $%.2f".formatted(o.id(), priority, o.value()); 37 }) 38 .collect(Collectors.joining("\n")); 39 40 System.out.println(report); 41 } 42}
...