Posts

Showing posts from August, 2024

Collection Framework of Java

 The Java Collection Framework provides a set of interfaces and classes that allow you to work with groups of objects in a standardized way. The framework is divided into several interfaces and classes, including `List`, `Set`, `Queue`, `Map`, and their various implementations. Here’s an overview of the main interfaces and classes in the Java Collection Framework, along with examples for each: ### 1. **List Interface** - **Characteristics**: Ordered collection (sequence) that allows duplicates. Elements can be accessed by their index. #### Implementations: - **ArrayList**: Resizable array implementation of the `List` interface. - **LinkedList**: Doubly-linked list implementation of the `List` and `Deque` interfaces. - **Vector**: Synchronized, resizable array implementation. - **Stack**: A subclass of `Vector` that represents a last-in, first-out (LIFO) stack. #### Example: ```java import java.util.ArrayList; import java.util.LinkedList; import java.util.Vector; import java.util.St...

Compiler vs Interpreter vs JIT Compiler

 Interpreter : Interpreter is a program which translates code into the intermediate code(Byte code) and then  executes line by line at runtime . That's why Speed is low. * Initial Phase: Source code is executed directly. * Runtime Monitoring: Code is interpreted line by line or statement by statement.   * Execution Phase: Execution happens in real-time without a separate compilation step. * Advantages: Flexibility, immediate feedback. Compiler :  Compiler converts code into machine code before program runs.  * Initial Phase: Source code is compiled into machine code or intermediate form. * Compilation Phase: Entire program is compiled before execution starts. * Execution Phase: Executable or machine code is run directly by the CPU. * Advantages: Fast execution, extensive optimizations. JIT Compiler :   * Initial Phase: Source code is compiled to bytecode. * Runtime Monitoring: JIT compiler detects hot spots during runtime. * Co...