”工欲善其事,必先利其器。“—孔子《论语.录灵公》
首页 > 编程 > Java 生态系统概述

Java 生态系统概述

发布于2024-08-26
浏览:982

Table of Contents

  1. Introduction
  2. JVM (Java Virtual Machine)
    • Architecture of the JVM
      • Class Loader
      • JVM Memory
        • Method Area
        • Heap
        • Stack Area
        • Program Counter (PC) Register
        • Native Method Stack
      • Execution Engine
        • Interpreter
        • Just-In-Time (JIT) Compiler
        • Garbage Collector
  3. JRE (Java Runtime Environment)
    • Key Components of the JRE
      • Execution Tasks
      • Class Libraries
      • Java Native Interface (JNI)
      • Security Manager
  4. JDK (Java Development Kit)
    • Core Features of the JDK
      • javac (Java Compiler)
      • java (Java Application Launcher)
      • jdb (Java Debugger)
      • jar (Java Archive Tool)
      • javadoc (Java Documentation Generator)
  5. JVM vs JRE vs JDK: What's the Difference?
  6. JDK, JRE, JVM Hierarchy

Introduction

The Java ecosystem is the broad set of tools, technologies, libraries, and frameworks that surround and support the Java programming language. It encompasses everything needed to develop, deploy, and manage Java applications. It revolves around JDK, JRE, JVM

JVM (Java Development Kit)

The JVM acts like a translator that allows your computer to run Java programs and other languages compiled into Java bytecode. It translates the code into something your computer's hardware can understand and execute.

Architecture of the JVM

Java Ecosystem Overview

Class Loader

  1. Loading load
    Load .class files into memory. Locates, loads, and links class files (Java bytecode) for execution.

  2. Linking

    • Verification: Verifies the bytecode.
    • Preparation: Allocates memory for static variables and initializes the memory to default values.
    • Resolution: Resolves symbolic references to direct references.
  3. Initialization
    Initialization is the final step where the JVM prepares a class or interface for use. This step happens after the class has been loaded (into memory) and linked.

JVM Memory

  1. Method Area
    Method area Stores class-level data such as methods and variables, the runtime constant pool, and code for methods.

    public class Person {
        private String name;
    
        public void setName(String name) {
            this.name = name;
        }
    }
    

    When you define a class Person, the Method Area stores the structure of the Person class, including its methods (setName) and fields (name), and the runtime constant pool which contains references like method names and constant values.

  2. Heap
    Heap is where the runtime memory objects are allocated. The heap is shared among all threads and is where the garbage collection process occurs.

    Person p = new Person();
    

    When you create a new Person object, it is allocated on the Heap.

  3. Stack Area
    Stack area stores frames, which contain local variables, operand stacks, and references to the runtime constant pool of the class being executed. Each thread has its own stack.

    public void someMethod() {
        int a = 10;
        int b = 20;
        int sum = a   b;
    }
    

    Each time someMethod is called, a new frame is pushed onto the Stack Area. This frame includes local variables (a, b, and sum), an operand stack for intermediate calculations, and a reference to the method’s class in the Runtime Constant Pool.

  4. Program Counter (PC) Register
    PC contains the address of the current JVM instruction being executed. Each thread has its own PC register.

  5. Native Method Stack
    Similar to the Java stack, but used for native methods.

Execution Engine

  1. Interpreter
    Interpreter reads Java bytecode and executes it line by line, converting each bytecode instruction into a sequence of machine-level instructions that can be executed by the CPU.

  2. Just-In-Time (JIT) Compiler
    Converts bytecode into native machine code at runtime to improve performance.

  3. Garbage Collector
    Garbage collector is responsible for automatically managing memory in the JVM. It identifies and deallocates memory that is no longer in use, freeing it up for new objects.

JRE

JRE is a software package that provides the necessary environment to run Java applications. It is designed to execute Java bytecode on a machine, making it an essential part of the "write once, run anywhere" (WORA) principle of Java.

Key Components of the JRE

  1. Execution Tasks
    The JRE facilitates the execution of Java applications by providing the JVM and the necessary libraries and resources. JRE ensures that the JVM has everything it needs to perform these tasks on any platform. Think of the JRE as the complete package that includes the JVM, which does the heavy lifting, and other components that support the execution of Java applications.

  2. Class Libraries
    JRE includes a set of standard Java class libraries, which provide reusable code for performing common tasks, like data structures, I/O, networking, concurrency, and more.

  3. Java Native Interface (JNI)
    JNI allows Java applications to interact with native code written in languages like C or C . This feature is essential for integrating platform-specific features or using existing native libraries.

  4. Security Manager
    The Security Manager enforces security policies for Java applications, restricting actions such as file access, network connections, and the execution of potentially unsafe code.

JDK (Java Development Kit)

JDK is a tools that enables developers to write, compile, debug, and run Java applications. It is a superset of JRE and includes additional tools for Java development.

Core Features of the JDK

  • javac (Java Compiler)
    javac is use to for converting Java source code (.java files) into bytecode (.class files). This bytecode is then executed by the Java Virtual Machine (JVM).

  • java (Java Application Launcher)
    java command launches a Java application. It loads the necessary class files, interprets the bytecode, and starts the application.

  • jdb (Java Debugger)
    jdb is the command-line debugger for Java programs. It allows you to inspect and debug Java applications at runtime.

  • jar (Java Archive Tool)
    jar tool packages multiple files into a single archive file, typically with a .jar extension. These JAR files are used to distribute Java applications and libraries.

  • javadoc (Java Documentation Generator)
    javadoc generates HTML documentation from Java source code, using the special /** */ comments known as doc comments.

JVM vs JVE vs JDK, what's the difference?

Feature/Aspect JVM JRE JDK
Purpose Executes Java bytecode Provides the environment to run Java applications Provides tools to develop, compile, debug, and run Java applications
Includes JVM itself, which includes class loader, bytecode verifier, and execution engine JVM Core libraries (like java.lang, java.util, etc.), and other runtime components JRE Development tools (like javac, jdb, jar, etc.), documentation
Components - Class Loader
- Bytecode Verifier
- Execution Engine (Interpreter, JIT)
- JVM
- Core Java libraries
- Java Plug-in
- Java Web Start
- JRE
- Java Compiler (javac)
- JAR Tool (jar)
- Debugger (jdb)
- Documentation Generator (javadoc)
- Other development tools
Main Functionality Executes Java bytecode, enabling platform independence Provides the minimum requirements to run Java applications Allows developers to write, compile, and debug Java code
Who Uses It? End-users running Java applications End-users running Java applications Java developers writing and compiling Java applications
Installation Size Smallest Larger than JVM but smaller than JDK Largest (includes JRE and development tools)
Developer Tools No No Yes (includes compiler, debugger, profiler, etc.)
Required to Run Java Programs Yes Yes No (but needed to create Java programs)
Platform Independence Provides platform independence by abstracting the underlying hardware Yes, because it includes the JVM Yes, it includes everything from JRE
Examples of Usage - Running any Java application (e.g., desktop applications, servers) - Running Java applications in production or end-user environments - Writing and compiling Java code
- Packaging applications
- Debugging
Availability Part of JRE and JDK Standalone or part of JDK Standalone package

JDK, JRE, JVM hierarchy

JDK (Java Development Kit)
│
├── JRE (Java Runtime Environment)
│   │
│   ├── JVM (Java Virtual Machine)
│   │   ├── Class Loader
│   │   ├── Bytecode Verifier
│   │   ├── Execution Engine
│   │   │   ├── Interpreter
│   │   │   ├── Just-In-Time (JIT) Compiler
│   │   │   └── Garbage Collector
│   │   └── Runtime Libraries (core libraries like java.lang, java.util, etc.)
│   │
│   └── Java APIs (Core libraries and additional libraries)
│
├── Development Tools (like javac, jdb, jar, javadoc, etc.)
└── Documentation (API docs, guides)
版本声明 本文转载于:https://dev.to/chandra179/java-ecosystem-in-detail-5f5p?1如有侵犯,请联系[email protected]删除
最新教程 更多>
  • 浓缩咖啡;出发时间到了
    浓缩咖啡;出发时间到了
    过去的两周里,我用 Go 重写了我的基于 Rust 的 Java 构建工具,事情进展得更快。 Espresso 运行速度更快且更便携。 Espresso 最近还能够编译和打包它的第一个项目,即我的另一个项目 Kindling。 我希望能得到有关 Espresso 的任何反馈。有很多功能缺失,例如瞬态...
    编程 发布于2024-11-07
  • 为什么我的 JSFiddle 无法运行?
    为什么我的 JSFiddle 无法运行?
    调试无功能的 JSFiddle尝试在 JSFiddle 中运行简约代码片段时,用户可能会遇到意外的功能缺失。此问题通常是由于 JavaScript 设置中的疏忽而引起的。要解决此问题,请按照下列步骤操作:在 JavaScript 设置中找到“加载类型”下拉列表。选择“无换行 - 底部”。此设置可确...
    编程 发布于2024-11-07
  • GenAI Git 提交
    GenAI Git 提交
    生成 git 提交消息很快成为开发人员的经典 GenAI 应用程序。 为了解决这个问题,我们将制作一个 GenAIScript 脚本。 该脚本充当常规 Node.js 自动化脚本并使用 runPrompt 向 LLM 发出呼叫并要求用户确认生成的文本。 ? 解释脚本 脚本首先从 @...
    编程 发布于2024-11-07
  • 什么是 Webhook 以及如何有效使用它们
    什么是 Webhook 以及如何有效使用它们
    Webhooks 是集成不同系统并实时发送通知的强大工具。它们允许一个应用程序在事件发生时自动通知另一个应用程序,而无需像传统 API 那样不断发出请求来检查是否有新内容。在这篇文章中,我们将了解它们的工作原理、如何配置它们,并且我们将探索使用 Webhook.site 工具的实际示例,该工具有助...
    编程 发布于2024-11-07
  • 创建 JS 函数以删除给定字符串中的空格。 (使用核心js而不是内置的修剪功能。)
    创建 JS 函数以删除给定字符串中的空格。 (使用核心js而不是内置的修剪功能。)
    const trim = (string) => { let strArr = string.split(""); let trimedStr = []; strArr.forEach((item) => { if (item !== " ") { ...
    编程 发布于2024-11-07
  • GlobalErrorHandler:捕获从 ErrorBoundary 手中落下的错误!
    GlobalErrorHandler:捕获从 ErrorBoundary 手中落下的错误!
    ErrorBoundary 是一个出色的工具,可以捕获 React 组件抛出的错误。您可以根据错误本身的性质和位置提供自定义错误消息。但并非所有抛出的错误都由 ErrorBoundary 处理!你用这些做什么? 当考虑异步错误和从 React 外部抛出的错误时,ErrorBoundary 不够。为了...
    编程 发布于2024-11-07
  • 如何在Visual Studio 2008中设置可执行文件图标?
    如何在Visual Studio 2008中设置可执行文件图标?
    在 Visual Studio 2008 中设置可执行文件图标虽然提供的参考主要针对 Visual Studio 2010,但在 Visual Studio 中设置可执行文件图标的原则Studio 2008 基本上都适用。但是,需要记住一些具体的注意事项:使用 .ico 文件您必须为可执行图标使用 ...
    编程 发布于2024-11-07
  • 导入大型 SQL 文件:为什么使用 MySQL 控制台而不是 phpMyAdmin?
    导入大型 SQL 文件:为什么使用 MySQL 控制台而不是 phpMyAdmin?
    在 phpMyAdmin 中导入大型 SQL 文件:另一种方法尝试直接通过 phpMyAdmin 导入大量 SQL 文件可能会遇到限制。不过,有一个可靠的替代方法,即利用 MySQL 控制台。根据提供的建议,通过 MySQL 控制台导入 SQL 文件可以绕过 phpMyAdmin 中遇到的问题。此方...
    编程 发布于2024-11-07
  • 使用 JSON-LD 提升博客的 SEO:我如何使用结构化数据添加丰富的结果
    使用 JSON-LD 提升博客的 SEO:我如何使用结构化数据添加丰富的结果
    Introduction A few years ago in 2022, I attended SCaLE 19x. For those who are not aware, SCaLE is an acronym which stands for Southern Califo...
    编程 发布于2024-11-07
  • create-next-app 使用此包验证您的应用程序名称
    create-next-app 使用此包验证您的应用程序名称
    在本文中,我们分析 create-next-app 如何验证您的项目名称。 validate: (name) => { const validation = validateNpmName(basename(resolve(name))) if (validation.valid) { ...
    编程 发布于2024-11-07
  • 幕后反应:到底发生了什么?
    幕后反应:到底发生了什么?
    React 长期以来一直是首选的 JavaScript 库,并且很容易成为世界上最受欢迎的库之一。此外,随着 Next.js 和 Remix 等流行框架构建在 React 之上,以及使用 React-Native 进行移动开发的能力,这个库不会很快消失。然而,这样做的问题是,大多数初学者都涌向 Re...
    编程 发布于2024-11-07
  • 使用 Tinder Unblur 个人资料
    使用 Tinder Unblur 个人资料
    Tinder 取消模糊代码说明 以下 JavaScript 代码是一个脚本,旨在对“喜欢你”部分中的 Tinder 照片进行取消模糊处理。它的工作原理是从 Tinder 的 API 获取预告图像并动态更新 DOM 以用清晰的图像替换模糊的图像。 async function unb...
    编程 发布于2024-11-07
  • 如何确保网站安全:最佳实践和见解
    如何确保网站安全:最佳实践和见解
    在当今的数字时代,确保网站的安全至关重要。随着网络威胁变得越来越复杂,保护您的网站免受潜在漏洞的影响至关重要。以下是增强网站安全性的一些关键做法,以及特定网站 HouseOfParty.com 如何在其利基市场中举例说明安全做法。 使用 HTTPS 描述:HTTPS(安全超文本传输​​协议)对用户和...
    编程 发布于2024-11-07
  • 如何使用“adjustText”库解决 matplotlib 图中注释重叠的问题?
    如何使用“adjustText”库解决 matplotlib 图中注释重叠的问题?
    Matplotlib 中的重叠注释:综合解决方案在数据可视化领域,经常会遇到重叠注释的问题,其中文本标签彼此模糊,导致难以解释图表。为了应对这一挑战,人们提出了各种方法,但对于像线重叠的复杂图形,找到合适的解决方案可能很困难。这篇文章提出了一个使用“adjustText”库的全面解决方案,提供了比传...
    编程 发布于2024-11-07
  • 如何使用 GORM 检索列总计?
    如何使用 GORM 检索列总计?
    使用 GORM 检索列总计在 GORM 中,通过几个简单的步骤即可实现从数据库表中获取列的总和.首先,定义一个结构体来表示要检索的数据。在这种情况下,如果您只需要工资总和,您可以创建一个带有整数字段的简单结构体:type SalarySum struct { Sum float64 }接下来...
    编程 发布于2024-11-07

免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。

Copyright© 2022 湘ICP备2022001581号-3