7. JVM Architecture, JDBC, Maven, JUnit & HTTP

Chapters 25-29: JVM Stack vs Heap & Garbage Collection, JDBC PreparedStatement, Maven build lifecycle, JUnit testing & HttpClient

Module 1: JVM Architecture, Memory & Garbage Collection

Class loading, runtime data areas, stack vs heap allocation, JIT compiler, and garbage collection.

🇬🇧 English Definition

JVM loads bytecode, manages Stack (local frames) and Heap (shared objects), performs JIT compilation into native machine code, and executes automatic Garbage Collection.

🇮🇳 Hinglish Definition

JVM bytecode ko load karta hai. Stack me local primitive execution frames rehte hain aur Heap me objects. Garbage collector unreachable memory automatically free karta hai.

Core Concepts & Rules

  • Stack vs Heap: Local variables reside on Stack; Objects and arrays are allocated on Heap.
  • JIT (Just-In-Time): Compiles frequently executed bytecode into optimized native machine code at runtime.

🔍 Line-by-Line Code Breakdown

  1. Line 1: Demonstrates class loading and Heap memory allocation when creating object.

🎯 Interview Focus & Questions

  • Q: Heap vs Stack memory?
    A: Stack stores thread execution frames and local variables; Heap stores shared objects and arrays.
  • Q: What is Garbage Collection?
    A: Automatic reclamation of heap memory occupied by unreachable objects.
💻 Practical Java Code Example - JVM Architecture, Memory & Garbage Collection
public class JVMDemo {
    public static void main(String[] args) {
        // Stack stores local variable 'value'
        int value = 100;
        // Heap allocates String object
        String str = new String("JVM Memory");
        System.out.println(str + ": " + value);
    }
}
📤 Compiled Execution Output:
JVM Memory: 100

Module 2: JDBC Database Connectivity, Maven & JUnit Testing

Connecting to SQL databases safely with PreparedStatement, managing dependencies with Maven, and writing JUnit unit tests.

🇬🇧 English Definition

JDBC interacts with SQL databases via PreparedStatement to prevent SQL injection. Maven manages dependencies via pom.xml. JUnit tests code using Arrange-Act-Assert (AAA) pattern.

🇮🇳 Hinglish Definition

JDBC PreparedStatement parameter binding se SQL Injection rokta hai. Maven dependencies pom.xml se manage karta hai. JUnit method results verify karta hai.

Core Concepts & Rules

  • PreparedStatement: String sql = 'SELECT * FROM users WHERE id=?'; (Prevents SQL Injection).
  • JUnit AAA Pattern: Arrange (setup), Act (execute method), Assert (verify expected result).

🔍 Line-by-Line Code Breakdown

  1. Line 1: // Arrange: set inputs int a=10, b=20.
  2. Line 2: // Act: int result = a + b.
  3. Line 3: // Assert: assertEquals(30, result).

🎯 Interview Focus & Questions

  • Q: Why use PreparedStatement over Statement?
    A: PreparedStatement supports parameter binding, pre-compiles SQL, and prevents SQL injection attacks.
  • Q: What is pom.xml in Maven?
    A: Project Object Model XML configuration file listing project dependencies, plugins, and build settings.
💻 Practical Java Code Example - JDBC Database Connectivity, Maven & JUnit Testing
// JUnit AAA Pattern Example
// Arrange
int a = 10, b = 20;
// Act
int result = a + b;
// Assert
if (result == 30) {
    System.out.println("JUnit Test Passed (30 == 30)");
}
📤 Compiled Execution Output:
JUnit Test Passed (30 == 30)