Saquib Aftab
5.8K posts

Saquib Aftab
@iamsaquibdev
Lead Software Engineer | ❤️ Programmer I demystify Java, Spring Boot, and System Design.
localhost:8080 Beigetreten Ekim 2023
462 Folgt4.3K Follower

What is a ClassLoader?
A ClassLoader is a component of the Java Virtual Machine responsible for loading .class files into memory when they are required.
When your program references a class, the JVM:
1. Checks if the class is already loaded.
2. If not, it asks a ClassLoader to load it.
3. The class is then verified, linked, and initialized
Bootstrap ClassLoader
↑
Platform ClassLoader
↑
Application ClassLoader
↑
Your Custom ClassLoader
English

Important Java Interview Question: What’s the difference between young generation and old generation GC in Java?
∙The JVM heap is split into generations based on the observation that most objects die young.
∙Young Generation is where all new objects are allocated. It’s further divided into Eden and two Survivor spaces (S0 and S1).
∙When Eden fills up, a Minor GC is triggered. It’s fast because it only scans the Young Generation, and most objects there are already dead by that point.
∙Objects that survive a Minor GC get moved to a Survivor space. They keep getting copied between S0 and S1 on each Minor GC cycle.
∙Each time an object survives a GC, its age counter increments. Once it crosses the tenuring threshold (default is 15, but the JVM can adjust it dynamically), it gets promoted to the Old Generation.
∙Old Generation holds long-lived objects like caches, static data, or objects that just kept surviving Minor GCs.
∙When the Old Generation fills up, a Major GC (or Full GC) is triggered. This is significantly more expensive because it has to scan a much larger memory region.
∙In G1GC (default since Java 9), the strict physical separation between Young and Old is replaced with a region-based model. Regions are logically assigned as Eden, Survivor, or Old, but any region can be reassigned. The generational concept still holds, just implemented differently.
∙Java 21 introduced Generational ZGC (and Generational Shenandoah is also in progress). These are low-pause collectors that now apply generational collection to ZGC’s region model, giving you both the throughput benefits of generational collection and ZGC’s sub-millisecond pause goals.
∙Minor GC is stop-the-world but very short. Major/Full GC is also stop-the-world (for most collectors) and noticeably longer.
∙The GC algorithm used for each generation can differ. For example, with G1, Young collections use an evacuating collector, while Old regions are handled through concurrent marking and mixed collections.
∙You can tune Young Gen size with -Xmn, or use -XX:NewRatio to set the ratio between Young and Old. But with G1 and ZGC, it’s usually better to let the JVM manage sizing dynamically.
English

Java Interview Question ✅
In a Java microservice, you occasionally see ClassNotFoundException or mysterious linkage errors only in production.
Locally, everything works, but in containers, some classes are missing at runtime.
The classpath looks long and messy, and multiple frameworks are involved.
How do you debug and stabilise class loading?
English

Your Java service runs smoothly after a fresh deploy, but memory usage slowly climbs over days until the process is restarted.
Heap dumps show many long-lived objects that you expected to be short-lived.
You suspect some caches or collections are growing unbounded. How do you locate and fix this memory leak?
English

JIT Compiler ✅
When you run a Java program, it doesn't execute your .java code directly.
It runs bytecode, a platform-neutral intermediate format.
The JVM initially interprets this bytecode line by line, which is slow.
The JIT compiler solves this by watching your program run and compiling frequently called methods into native machine code.
English

Stack Memory 👇 in Java
Stores method call frames, local variables, and references
Follows LIFO (Last In, First Out): Each method call pushes a frame, and return pops it
Fast allocation/deallocation (just a pointer move)
Thread-private: Each thread has its own stack
Fixed/limited size: Overflow causes StackOverflowError
Short-lived: data dies when the method returns
English

Interview Question: You use a fixed-size thread pool in your Java app, but during peak traffic requests start timing out.
CPU is not fully used, yet threads are always busy. After digging, you realise many tasks are waiting on blocking I/O calls.
How do you redesign thread usage to avoid starvation?
English

Your Java service runs fine at low load, but under heavy traffic, you see random latency spikes.
Heap usage looks normal, but GC logs show frequent stop-the-world pauses.
You can’t just throw more memory at it due to cost constraints.
How do you tune garbage collection to reduce these pauses?
English
Saquib Aftab retweetet

With Spring Boot 4, when you add a starter dependency now, you get exactly what that starter needs and nothing more.
Faster startup times: Less classpath scanning means your application boots quicker
Reduced memory footprint: Fewer configuration classes loaded into memory
Cleaner dependency trees: Easier to debug and understand what’s actually in your application
Better native image compilation: GraalVM doesn’t need to process unnecessary metadata
English






