」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > Java 生態系概述

Java 生態系概述

發佈於2024-08-26
瀏覽:940

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]刪除
最新教學 更多>
  • 導入大型 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 進行行動開發的能力,這個函式庫不會很快消失。然而,這樣做的問題是,大多數初學者...
    程式設計 發佈於2024-11-07
  • 使用 Tinder Unblur 個人資料
    使用 Tinder Unblur 個人資料
    Tinder 取消模糊程式碼說明 以下 JavaScript 程式碼是一個腳本,旨在對「喜歡你」部分中的 Tinder 照片進行取消模糊處理。它的工作原理是從 Tinder 的 API 獲取預告圖像並動態更新 DOM 以用清晰的圖像替換模糊的圖像。 async function ...
    程式設計 發佈於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
  • 如何存取名稱中帶有空格的類別屬性?
    如何存取名稱中帶有空格的類別屬性?
    存取類別物件中帶有空格的屬性本問題探討如何存取名稱中包含空格的類別屬性。考慮以下範例,其中stdClass 物件具有名為「[Sector]」和「[Date Found]」的屬性:<p>stdClass Object ([Sector] =&gt; Manufacturing [D...
    程式設計 發佈於2024-11-07
  • Bootstrap 4 Beta 中的列偏移發生了什麼事?
    Bootstrap 4 Beta 中的列偏移發生了什麼事?
    Bootstrap 4 Beta:列偏移的刪除和恢復Bootstrap 4 在其Beta 1 版本中引入了重大更改柱子偏移了。然而,隨著 Beta 2 的後續發布,這些變化已經逆轉。 從 offset-md-* 到 ml-auto在 Bootstrap 4 Beta 1 中, offset-md-*...
    程式設計 發佈於2024-11-07
  • 如何在 C++ 中正確釋放透過 Placement New 分配的記憶體?
    如何在 C++ 中正確釋放透過 Placement New 分配的記憶體?
    placement new 和delete 難題placement new 和delete 難題在C 中,當使用placement new 運算子分配記憶體時,會出現關於取消分配的適當方法的困境那個記憶。讓我們探討兩個可能的解決方案:const char* charString = "He...
    程式設計 發佈於2024-11-07
  • 單元測試:綜合指南
    單元測試:綜合指南
    单元测试是软件开发的基本实践之一,确保系统的各个单元或组件按预期运行。这些测试隔离小段代码,例如函数或方法,并验证它们在给定特定输入的情况下是否产生正确的输出。本文将深入概述单元测试、其优点、最佳实践和局限性。 什么是单元测试? 单元测试是一种软件测试技术,其中程序的各个单元(最小的可测试部分)被...
    程式設計 發佈於2024-11-07
  • 你應該盲目地用 MySQLi_ 取代 MySQL 函數:一個警世故事嗎?
    你應該盲目地用 MySQLi_ 取代 MySQL 函數:一個警世故事嗎?
    盲目地用mysqli_ 取代mysql_ 函數:一個警示故事在PHP 5.5 中,mysql_ 函數已被棄用,並已在PHP中刪除7. 這就提出了一個問題,是否可以簡單地將所有mysql_ 函數替換為mysqli_函數,而不會遇到任何不利影響。 答案是響亮的不。 功能差異雖然 mysql_ 和 mys...
    程式設計 發佈於2024-11-07
  • 了解 JavaScript 提升:簡單指南
    了解 JavaScript 提升:簡單指南
    如果您是 JavaScript 新手,您可能會遇到令人困惑的情況,即變數似乎未定義或意外彈出 ReferenceError 等錯誤。這通常可以追溯到一個稱為提升的概念。但是什麼是提升,它如何影響您的程式碼? 在本指南中,我們將詳細介紹提升的概念及其在 JavaScript 中的工作原理。最後,您將...
    程式設計 發佈於2024-11-07
  • PHP中如何在指定時間後自動重定向網頁?
    PHP中如何在指定時間後自動重定向網頁?
    使用PHP 在指定時間後自動重新導向網頁PHP 提供了一個方便的功能,可以將網頁自動重新導向到新位置在指定的時間間隔後。此功能通常用於在使用者登入或在網站上執行其他操作後將使用者重新導向到特定頁面。 用於此目的的函數是 header()。 header() 函數可讓您控制傳送到瀏覽器的 HTTP 標...
    程式設計 發佈於2024-11-07

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3