☕ JAVA COMPILE-TIME vs RUNTIME RESOLUTION
✅ Compile-Time Resolution (Static Binding)
Happens during compilation.
Direct calls, no lookup, faster.
Methods:
static,private,final, constructors,supercalls
Variables:
staticvariables,finalconstants, locals, field offsets
Generics & Types:
Type erasure, bounds checking, wildcard resolution, method signatures
Initialization:
Static blocks order, static variable init, class structure, access control
⚡ FASTEST – resolved once, no runtime cost.
🔄 Runtime Resolution (Dynamic Binding)
Happens during execution.
Allows polymorphism & flexibility.
Methods:
Overridden (virtual) methods, interfaces, abstract methods, lambdas
Objects & Memory:
Object creation, type casting,
instanceof, array store checks
Reflection & Dynamic:
Method.invoke(),Field.get/set(),Class.forName(), proxies, annotations
Collections & Init:
Instance blocks, generic cast checks, auto-boxing/unboxing
🔁 FLEXIBLE – enables polymorphism & late binding.
📝 Quick Examples
Compile-Time:
static final int MAX = 100; // inlined
private final void helper() {} // fixed
Runtime:
Animal a = new Dog();
a.makeSound(); // dynamic dispatch
Method m = Dog.class.getMethod("makeSound");
m.invoke(a); // reflection
📌 Extra Notes
Performance: Compile-time = fast; Runtime = slower (JIT helps).
Bytecode Ops:
Compile:
invokestatic,invokespecialRuntime:
invokevirtual,invokeinterface,invokedynamic
Generics: Checked at compile, erased at runtime →
List<T>→List.Rule of Thumb:
Fixed = Compile-Time
Overridden / Dynamic / Reflection = Runtime


