Java Terminologies
1. JDK (Java Development Kit)
The Java Development Kit (JDK) is a comprehensive software development kit used for creating Java applications.
It encompasses a suite of tools, executables, and libraries necessary for Java development.
Beyond being a compiler, the JDK provides everything developers need to write, compile, and run Java code.
Components of JDK:
Compiler (javac): Transforms Java source code (.java files) into bytecode (.class files).
Java Virtual Machine (JVM): Executes bytecode on the target platform.
Java Runtime Environment (JRE): Includes libraries, binaries, and files essential for running Java applications.
JavaDoc: A tool for generating API documentation from source code comments.
Debugger, Profiler, and Other Tools: Aids in debugging and profiling Java applications.
2. JRE (Java Runtime Environment)
The Java Runtime Environment (JRE) is a subset of the JDK, designed solely for running Java applications.
It provides the minimal set of tools and libraries required for executing Java bytecode.
Users who only need to run Java applications can install the JRE without the full suite of development tools.
Components of JRE:
Java Virtual Machine (JVM): Executes Java bytecode.
Java Core Libraries: A set of libraries and APIs for common tasks.
Java Plugin: Facilitates the running of Java applets in web browsers.
Java Web Start: Enables the launching of Java applications directly from the web.
3. JVM (Java Virtual Machine)
The Java Virtual Machine (JVM) is a critical component of the Java platform.
It acts as an intermediary layer between Java bytecode and the underlying hardware and operating system.
JVM is responsible for executing Java bytecode, making Java a platform-independent language.
Key Functions of JVM:
Loading: Loading the bytecode (compiled Java source code) into memory.
Verification: Ensuring the bytecode adheres to Java's safety and security rules.
Execution: Executing Java bytecode line by line.
Garbage Collection: Managing memory by identifying and collecting unused objects.
JIT Compilation: Just-In-Time compilation translates bytecode into machine code for improved performance.
4. Bytecode
Java source code is compiled into an intermediate form called bytecode.
Bytecode is a set of instructions understood by the Java Virtual Machine (JVM).
It is platform-independent and can be executed on any device with a compatible JVM.
Advantages of Bytecode:
Portability: Bytecode can be executed on any device with a JVM, ensuring "write once, run anywhere" capability.
Security: Bytecode is verified by the JVM, reducing the risk of security vulnerabilities.
Performance: Bytecode is translated into machine code by the JVM's Just-In-Time compiler, optimizing execution.
5. Garbage Collection
- Garbage Collection is the automatic process in Java that manages the memory used by a program.
- In Java, developers do not explicitly deallocate memory instead, the Garbage Collector identifies and frees up memory occupied by objects that are no longer in use.
Key Aspects of Garbage Collection:
Mark and Sweep: The Garbage Collector identifies and marks objects that are still reachable. It then sweeps through and deallocates memory occupied by unreferenced objects.
Generational GC: Objects are divided into different generations (young and old). Young generation collects short-lived objects, while the old generation handles longer-lived objects.
Parallel and Concurrent GC: Garbage Collection can be executed concurrently with the application or in parallel with multiple threads, minimizing the impact on application performance.