JVM in Java – Java Virtual Machine Explained (जावा वर्चुअल मशीन)

What is JVM? (JVM क्या है?) 

The JVM (Java Virtual Machine) is an abstract machine that provides the runtime environment for executing Java bytecode. It acts as an interface between Java bytecode and the underlying operating system and hardware.

JVM (Java Virtual Machine) एक Abstract Machine है जो Java Bytecode को execute करने के लिए Runtime Environment प्रदान करती है। यह Java Bytecode और कंप्यूटर के Operating System तथा Hardware के बीच एक interface के रूप में कार्य करती है।

One of the most important features of Java is platform independence. Java source code is compiled into bytecode, which can run on any system that has a compatible JVM.

Java की सबसे महत्वपूर्ण विशेषताओं में से एक Platform Independence है। Java Source Code को Bytecode में compile किया जाता है, जिसे compatible JVM वाले किसी भी सिस्टम पर execute किया जा सकता है।

How Does JVM Work? (JVM कैसे कार्य करती है?)

When a Java program is compiled, the Java compiler (javac) converts the source code into bytecode and stores it in a .class file. The JVM loads, verifies and executes this bytecode.

जब Java प्रोग्राम को compile किया जाता है, तो Java Compiler (javac) Source Code को Bytecode में बदलकर .class फाइल में store करता है। इसके बाद JVM इस Bytecode को load, verify और execute करती है।

Basic execution process:

  1. Write Java source code (.java).

  2. Compile it using javac.

  3. Generate bytecode (.class).

  4. JVM loads and verifies the bytecode.

  5. JVM executes the bytecode using the interpreter and JIT compiler.

Java प्रोग्राम की Execution प्रक्रिया:

  1. Java Source Code (.java) लिखना।

  2. javac की सहायता से compile करना।

  3. Bytecode (.class) generate होना।

  4. JVM द्वारा Bytecode को load और verify करना।

  5. Interpreter और JIT Compiler की सहायता से Bytecode execute करना।

JVM Architecture (JVM की संरचना)

The JVM architecture consists of several important components that work together to execute Java programs efficiently.

JVM Architecture में कई महत्वपूर्ण components होते हैं, जो मिलकर Java प्रोग्राम को efficiently execute करते हैं।

1. Class Loader Subsystem (क्लास लोडर)

The Class Loader loads compiled Java class files into memory when they are required by the program. It also performs linking and class initialization.

Class Loader आवश्यकतानुसार compiled Java Class Files को memory में load करता है। यह Linking और Class Initialization का कार्य भी करता है।

2. Runtime Data Areas (रनटाइम डेटा एरिया)

Runtime Data Areas are memory areas used by the JVM during program execution.

Runtime Data Areas वे Memory Areas हैं जिनका उपयोग JVM प्रोग्राम के execution के दौरान करती है।

Important memory areas include:

  • Method Area: Stores class-level structures, method information and runtime constants.

  • Heap: Stores objects and arrays created during program execution.

  • Java Stack: Stores method call frames, local variables and intermediate results.

  • PC Register: Keeps track of the current JVM instruction for each thread.

  • Native Method Stack: Supports the execution of native methods.

मुख्य Memory Areas:

  • Method Area: Class-level structures, method information और runtime constants को store करता है।

  • Heap: प्रोग्राम execution के दौरान बनाए गए Objects और Arrays को store करता है।

  • Java Stack: Method calls, local variables और intermediate results को store करता है।

  • PC Register: प्रत्येक Thread के लिए वर्तमान JVM instruction को track करता है।

  • Native Method Stack: Native Methods के execution में सहायता करता है।

3. Execution Engine (एक्जीक्यूशन इंजन)

The Execution Engine executes the bytecode loaded into the JVM. It mainly uses an interpreter and JIT compiler to execute instructions.

Execution Engine JVM में load किए गए Bytecode को execute करता है। यह मुख्य रूप से Interpreter और JIT Compiler की सहायता से instructions को execute करता है।

  • Interpreter: Executes bytecode instructions one by one.

  • JIT Compiler: Converts frequently executed bytecode into native machine code to improve performance.

  • Garbage Collector: Automatically identifies and reclaims memory occupied by objects that are no longer reachable.

  • Interpreter: Bytecode instructions को एक-एक करके execute करता है।

  • JIT Compiler: बार-बार execute होने वाले Bytecode को Native Machine Code में बदलकर performance बेहतर करता है।

  • Garbage Collector: उन Objects की memory को automatically reclaim करता है जो अब program में reachable नहीं हैं।

4. Java Native Interface (JNI)

JNI allows Java code to interact with native applications and libraries written in languages such as C and C++.

JNI Java Code को C और C++ जैसी भाषाओं में लिखे गए Native Applications और Libraries के साथ interact करने की सुविधा प्रदान करता है।

5. Native Method Libraries

These are platform-specific libraries required for executing native methods through the JVM.

ये Platform-Specific Libraries होती हैं, जिनका उपयोग JVM के माध्यम से Native Methods को execute करने के लिए किया जाता है।

Simple JVM Execution Diagram

Java Source Code → Java Compiler (javac) → Bytecode (.class) → JVM → Machine Execution

Advantages of JVM (JVM के लाभ)

  • Platform Independence: Java bytecode can run on different systems with compatible JVM implementations.

  • Memory Management: Provides automatic memory management through garbage collection.

  • Security: Bytecode verification and runtime security mechanisms help protect the execution environment.

  • Performance: JIT compilation improves the execution speed of frequently used code.

  • Multithreading: Supports the execution of multiple threads.

  • Platform Independence: Compatible JVM वाले अलग-अलग सिस्टम पर Java Bytecode execute हो सकता है।

  • Memory Management: Garbage Collection द्वारा automatic memory management प्रदान करता है।

  • Security: Bytecode Verification और Runtime Security Mechanisms सुरक्षा में सहायता करते हैं।

  • Performance: JIT Compilation बार-बार execute होने वाले Code की speed बेहतर करता है।

  • Multithreading: Multiple Threads के execution को support करता है।

The JVM is an essential part of the Java platform. It loads, verifies and executes Java bytecode while managing memory and supporting runtime operations. It plays a major role in making Java platform-independent.

JVM, Java Platform का एक महत्वपूर्ण हिस्सा है। यह Java Bytecode को load, verify और execute करने के साथ-साथ memory management और अन्य runtime operations को support करती है। Java को Platform Independent बनाने में इसकी महत्वपूर्ण भूमिका है।

Comments

Popular posts from this blog

Java program to find length of given string and convert it in to upper or lower case.

Java program to implement file input stream class to read binary data from image file.