Back to Browse

Learn Java Reflection | Class Class, getDeclaredFields(), setAccessible() & Method Invocation

May 15, 2026
21:10

🎯 Hook How does Spring inject dependencies into private fields? How does JUnit discover and run your @Test methods? The answer is Reflection — Java's ability to inspect and manipulate any class at runtime. This video teaches you the Reflection API from Class.forName() to dynamic method invocation, including when to use it and when to avoid it. 📌 Topics Covered • What is Reflection? — runtime self-inspection of Java classes • The Class class — the entry point to reflection • Three ways to get a Class object: .class, .getClass(), Class.forName() • Inspecting class metadata — getName(), getModifiers(), getSuperclass(), getInterfaces() • getDeclaredFields() vs getFields() — declared vs inherited members • Accessing private fields — setAccessible(true) and its security implications • Reading and writing field values at runtime — field.get(obj), field.set(obj, value) • getDeclaredMethods() — inspecting method signatures at runtime • Dynamic method invocation — method.invoke(obj, args) • Constructor inspection and dynamic object creation — constructor.newInstance(args) • Reading annotations at runtime — getAnnotation(), isAnnotationPresent() • Performance cost of Reflection — when it matters and how to minimize it • Practical use cases — dependency injection, serialization, testing frameworks, ORM • Module system (Java 9+) and reflection — open and exports impact 🗒️ What Makes This Video Different The complete Reflection cycle is demonstrated — define a private field, access it via reflection, modify it, and verify — showing exactly how frameworks like Spring and Hibernate work. ⏱️ Timestamps • 0:00 Introduction — What Reflection Is Used For • 0:40 The Class Class — 3 Ways to Get It • 10:10 Inspecting Class Metadata • 20:00 getDeclaredFields vs getFields • 28:00 Accessing Private Fields with setAccessible() • 38:00 Reading & Writing Field Values • 47:00 Inspecting & Invoking Methods Dynamically • 57:00 Constructor Inspection & Dynamic Instantiation • 1:06:00 Reading Annotations at Runtime • 1:13:00 Performance Implications • 1:19:00 Real-World Use Cases (DI, ORM, Testing) • 1:25:00 Java 9+ Module System & Reflection • 1:30:00 Summary & Best Practices 👥 Who Is This Video For? • Advanced Java developers who want to understand framework internals • Students covering the Reflection API in advanced Java modules • Developers building tools, ORMs, or test frameworks • Anyone preparing for advanced Java technical interview questions 🏷️ Hashtags #Java #ReflectionAPI #JavaReflection #DynamicInvocation #PrivateAccess #FrameworkInternals #JavaInterview #AdvancedJava #LearnJava #SpringInternals

Download

1 formats

Video Formats

360pmp413.6 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Learn Java Reflection | Class Class, getDeclaredFields(), setAccessible() & Method Invocation | NatokHD