G1 Garbage Collector Explained G1 Garbage Collector Explained In G1 GC, the heap is divided into equal-sized regions. Each region can belong to one of the following categories: Eden : Where new objects are allocated. Survivor : Where objects that survive an initial garbage collection are moved. Old : Where objects that have survived multiple garbage collections are promoted. Humongous : Where very large objects that do not fit into a standard region are allocated. Key Concepts 1. Region-Based Memory Management : Each region is typically between 1 MB and 32 MB. The number of regions and their size can be controlled via the -XX:G1HeapRegionSize parameter. 2. Young and Old Generation : Unlike traditional generational collectors that have contiguous spaces for young and old generations, G1 has regions that can dynamically change their role. Young Ge
Software Engineering Principles: DRY, KISS, and YAGNI Software Engineering Principles: DRY, KISS, and YAGNI DRY (Don't Repeat Yourself) Principle: The DRY principle emphasizes the importance of reducing repetition within code. Repetition can lead to more errors, higher maintenance costs, and inconsistency. When the same piece of code or logic appears in multiple places, it should be abstracted out into a single location that can be reused. Example: Without DRY: public class Calculator { public int add(int a, int b) { return a + b; } public int subtract(int a, int b) { return a - b; } public int multiply(int a, int b) { return a * b; } public double divide(int a, int b) { return a / b; } public int addAndSubtract(int a, int b, int c) { return a + b - c; // repeated addition and subtraction logic } } With DRY: public class Ca