JDK, JVM and JRE in Java
Java Virtual Machine(JVM):-
JVM Architecture:-
Class Loader
- Role: The class loader is responsible for dynamically loading Java classes into the JVM. It loads classes from the filesystem, network, or other sources as needed.
- Types:
- Bootstrap Class Loader: Loads core Java libraries located in the
<JAVA_HOME>/lib
directory. - Extension Class Loader: Loads classes from the
<JAVA_HOME>/lib/ext
directory. - Application Class Loader: Loads classes from the application's classpath, typically specified by the
CLASSPATH
environment variable or command-line options.
- Bootstrap Class Loader: Loads core Java libraries located in the
Runtime Data Areas
- Method Area: Stores class-level data, including field and method information, constant pool, method bytecode, and static variables.
- Heap: The runtime data area from which memory for all class instances and arrays is allocated. The heap is managed by the garbage collector.
- Stack: Stores method call frames, local variables, and intermediate results. Each thread has its own stack.
- PC Registers: Each thread has its own program counter (PC) register, which keeps track of the JVM instruction currently being executed.
- Native Method Stack: Used for native method calls, which are implemented in languages other than Java, typically C or C++.
Execution Engine
- Interpreter: Executes bytecode instructions directly. It's simple but relatively slow.
- Just-In-Time (JIT) Compiler: Translates bytecode into native machine code at runtime. This approach significantly improves performance compared to interpretation alone.
- Garbage Collector: Automatically manages memory by reclaiming memory occupied by objects that are no longer in use, preventing memory leaks and optimizing memory usage.
Native Interface
- Java Native Interface (JNI): Provides a way for Java code to interact with native applications and libraries written in other languages like C or C++.
Java Development Kit(JDK):-
The JDK is a software development environment used for developing Java applications and applets. It includes the JRE (Java Runtime Environment), an interpreter/loader (Java), a compiler (javac), an archiver (jar), a documentation generator (javadoc), and other tools needed for Java development.
Java Compiler (javac)
- Role: The Java compiler converts Java source code (.java files) into bytecode (.class files) that can be executed by the JVM.
- Usage: You can compile a Java file using the command
javac MyClass.java
, which generates aMyClass.class
file.
Java Runtime Environment (JRE)
- Role: The JRE provides the libraries, Java Virtual Machine (JVM), and other components needed to run Java applications. It's a subset of the JDK, tailored for end-users who want to run Java applications.
- Components: Includes the JVM, core libraries, and other runtime components.
Development Tools
- javap: A disassembler tool used to view the bytecode of class files.
- javadoc: A tool for generating API documentation from Java source code comments.
- jar: A tool for creating, viewing, and extracting files from Java Archive (JAR) files.
- jdb: A command-line debugger for Java classes.
Libraries and APIs
- Core Libraries: Provide essential functionality, such as data structures (java.util), networking (java.net), file I/O (java.io), and concurrency (java.util.concurrent).
- Additional APIs: Include libraries for XML parsing, database connectivity (JDBC), and more.
Java Mission Control
- Role: A suite of tools for monitoring, managing, and profiling Java applications.
- Components: Includes JDK Flight Recorder, a tool for collecting diagnostic and profiling data about running Java applications.
Most Popular JDKs:
- Oracle JDK: the most popular JDK and the main distributor of Java11,
- OpenJDK: Ready for use: JDK 15, JDK 14, and JMC,
- Azul Systems Zing: efficient and low latency JDK for Linux os,
- Azul Systems: based Zulu brand for Linux, Windows, Mac OS X,
- IBM J9 JDK: for AIX, Linux, Windows, and many other OS,
- Amazon Corretto: the newest option with the no-cost build of OpenJDK and long-term support.
Java Runtime Environment(JRE):-
The Java Runtime Environment (JRE) is a comprehensive suite that includes the JVM, core class libraries, extension libraries, deployment technologies, and tools necessary for running Java applications. Each component plays a vital role in ensuring the smooth execution, performance, and security of Java applications across various platforms.
Understanding the components of the JRE provides a solid foundation for appreciating how Java applications run and interact with the underlying system. Whether you're a developer or an end-user, knowing these components helps in better managing and troubleshooting Java applications.
Comments
Post a Comment