Maison > Java > javaDidacticiel > Présentation de l'écosystème Java

Présentation de l'écosystème Java

PHPz
Libérer: 2024-08-21 06:20:32
original
1048 Les gens l'ont consulté

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;
        }
    }
    
    Copier après la connexion
    Copier après la connexion

    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();
    
    Copier après la connexion
    Copier après la connexion

    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;
    }
    
    Copier après la connexion
    Copier après la connexion

    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.

public class Person {
    private String name;

    public void setName(String name) {
        this.name = name;
    }
}
Copier après la connexion
Copier après la connexion
Person p = new Person();
Copier après la connexion
Copier après la connexion
public void someMethod() {
    int a = 10;
    int b = 20;
    int sum = a + b;
}
Copier après la connexion
Copier après la connexion
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)
Copier après la connexion
Copier après la connexion
<🎝><🎝>Clés<🎝>Composants<🎝>du<🎝>du<🎝>JRE

  1. Exécution<🎝>Tâches
    Le<🎝>JRE<🎝>facilite<🎝>l'<🎝>exécution<🎝>des<🎝>Java<🎝>applications<🎝>en<🎝>fournissant<🎝>la<🎝>JVM<🎝>et< 🎝>les<🎝>bibliothèques<🎝>nécessaires<🎝>et<🎝>ressources.<🎝>JRE<🎝>assure<🎝>que<🎝>la<🎝>JVM<🎝>a<🎝>tout<🎝 >il<🎝>doit<🎝>effectuer<🎝>ces<🎝>tâches<🎝>sur<🎝>n'importe quelle<🎝>plateforme.<🎝>Pensez<🎝>au<🎝>le<🎝> JRE<🎝>en tant que<🎝>le<🎝>package<🎝>complet<🎝>qui<🎝>inclut<🎝>la<🎝>JVM,<🎝>qui<🎝>fait<🎝>le<🎝>gros <🎝>levage,<🎝>et<🎝>autres<🎝>composants<🎝>qui<🎝>supportent<🎝>l'<🎝>exécution<🎝>des<🎝>Java<🎝>applications.

  2. Classe<🎝>Bibliothèques
    JRE<🎝>comprend<🎝>un<🎝>ensemble<🎝>de<🎝>standard<🎝>Java<🎝>class<🎝>bibliothèques,<🎝>qui<🎝>fournissent<🎝>du code<🎝>réutilisable <🎝>pour<🎝>effectuer<🎝>des tâches<🎝>communes,<🎝>comme<🎝>des<🎝>structures de données,<🎝>E/S,<🎝>réseau,<🎝>accès simultané,<🎝> et<🎝>plus encore.

  3. Java<🎝>Native<🎝>Interface<🎝>(JNI)
    JNI<🎝>permet<🎝>aux applications<🎝>Java<🎝>d'<🎝>interagir<🎝>avec<🎝>le code<🎝>natif<🎝>écrit<🎝>dans<🎝>langues<🎝>comme< 🎝>C<🎝>ou<🎝>C++.<🎝>Cette<🎝>fonctionnalité<🎝>est<🎝>essentielle<🎝>pour<🎝>intégrer<🎝>des fonctionnalités<🎝>spécifiques à la plateforme<🎝>ou <🎝>en utilisant<🎝>des bibliothèques<🎝>natives<🎝>existantes.

  4. Sécurité<🎝>Responsable<🎝>
    Le <🎝>Security<🎝>Manager<🎝>applique<🎝>des<🎝>politiques<🎝>de sécurité<🎝>pour les<🎝>Java<🎝>applications,<🎝>restreignant<🎝>les actions<🎝>telles<🎝>que <🎝>l'accès<🎝>aux fichiers, aux<🎝>connexions<🎝>au réseau<🎝>et<🎝>l'<🎝>exécution<🎝>de<🎝>potentiellement<🎝>dangereux<🎝>code.

<🎝><🎝> <🎝><🎝> <🎝><🎝>JDK<🎝>(Java<🎝>Développement<🎝>Kit)

JDK<🎝>est<🎝>un<🎝>outils<🎝>qui<🎝>permet<🎝>aux développeurs<🎝>d'écrire,<🎝>compiler,<🎝>déboguer,<🎝> et<🎝>exécuter<🎝>Java<🎝>applications.<🎝>Il<🎝>est<🎝>un<🎝>sur-ensemble<🎝>de<🎝>JRE<🎝>et<🎝>comprend<🎝>des <🎝>outils<🎝>pour<🎝>Java<🎝>développement.

<🎝><🎝> <🎝><🎝> <🎝><🎝>Principales<🎝>Fonctionnalités<🎝>du<🎝>du<🎝>JDK

  • javac<🎝>(Java<🎝>Compilateur)
    javac<🎝>est<🎝>utilisé<🎝>pour<🎝>pour<🎝>convertir<🎝>Java<🎝>code source<🎝>(.java<🎝>fichiers)<🎝>en<🎝 >bytecode<🎝>(.class<🎝>fichiers).<🎝>Ce<🎝>bytecode<🎝>est<🎝>puis<🎝>exécuté<🎝>par<🎝>le<🎝>Java<🎝>Virtuel <🎝>Machine<🎝>(JVM).

  • java<🎝>(Java<🎝>Application<🎝>Lanceur)
    java<🎝>commande<🎝>lance<🎝>une<🎝>application Java<🎝>.<🎝>Elle<🎝>charge<🎝>les<🎝>classes<🎝>nécessaires,<🎝> interprète<🎝>le<🎝>bytecode,<🎝>et<🎝>démarre<🎝>l'<🎝>application.

  • jdb<🎝>(Java<🎝>Débogueur)
    jdb<🎝>est<🎝>le<🎝>débogueur<🎝>de ligne de commande<🎝>pour<🎝>Java<🎝>les programmes.<🎝>Il<🎝>permet<🎝>vous<🎝>de<🎝 >inspecter<🎝>et<🎝>déboguer<🎝>Java<🎝>applications<🎝>au<🎝>exécution.

  • jar<🎝>(Java<🎝>Archive<🎝>Outil)
    jar<🎝>outil<🎝>emballe<🎝>plusieurs<🎝>fichiers<🎝>dans<🎝>un<🎝>unique<🎝>archive<🎝>fichier,<🎝>généralement<🎝>avec<🎝>un <🎝>.jar<🎝>extension.<🎝>Ces<🎝>JAR<🎝>fichiers<🎝>sont<🎝>utilisés<🎝>pour<🎝>distribuer<🎝>Java<🎝>applications<🎝>et <🎝>bibliothèques.

  • javadoc<🎝>(Java<🎝>Documentation<🎝>Générateur)
    javadoc<🎝>génère<🎝>HTML<🎝>de la documentation<🎝>à partir du code<🎝>Java<🎝>source<🎝>,<🎝>en utilisant<🎝>le<🎝>spécial<🎝>/**<🎝 >*/<🎝>commentaires<🎝>connus<🎝>sous le nom<🎝>doc<🎝>commentaires.

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)
Copier après la connexion
Copier après la connexion

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

source:dev.to
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal