SlideShare a Scribd company logo
Java Reflection API
@KonaTechAdda
Md Imran Hasan Hira
Software Engineer
Kona Software Lab Ltd.
http://bd.linkedin.com/in/imranhasanhira
https://www.facebook.com/KonaSoftware
https://www.linkedin.com/company/kona-software-lab-ltd-
Outlines
‱ Design of reflection API
‱ Getting class
‱ Encoding class names
‱ Examples
‱ Modifiers
‱ Drawbacks
What & Why
‱ Logics vs configurations
‱ Dependency Injections
‱ Methods param suggestion
‱ Build tools
‱ Spring

‱ Runtime Code generation
‱ Bytecode Manipulation
Java Reflection
JavaObject
Basic Idea
‱ Accessing a field in runtime
‱ Find a class
‱ Instantiate a object form the class
‱ Find it’s field
‱ Set value of the field on that object
‱ Calling a method in runtime
‱ Find a class
‱ Instantiate a object form the class
‱ Find it’s method
‱ Invoke the method (with/without parameter)
‱ Get the returned value
Necessary Classes
java.lang.Class
java.lang.reflection.Method
java.lang.reflection.Field
java.lang.reflection.Constructor
java.lang.reflection.Modifier
java.lang.reflection.Parameter
“Class” àŠ•à§àŠČàŠŸàŠ¶à§‡àŠ° public methods
Class
Including private
Including Inherited
Own + private, no inherited
Own + inherited, except private
“Constructor” & “Method”
Constructor
Method
“Field” & “Modifier”
Field
Modifier
Ways to get class
1. With the static field*
2. Providing full class path
3. getClass() method
Classpath encoding schema*
byte
char
MyClass
MyClass[]
byte[]
“B”
“C”
“Lcom.mypackage.MyClass;”
“[Lcom.myPackage.MyClass;”
“[B”
byte[][] “[[B”
Finding fields upto superclass
new Manager();
Data Parsing
Data Parsing (Dynamic)
Method Calling
Name: Default name, Age: 0
Name: Dynamic name, Age: 0
JavaObject
Reflection Drawbacks
‱ Performance overhead
‱ Dynamically type resolutions occlude JVM optimizations.
‱ Should be avoided in parts of code in performance sensitive applications
*Taken from a article of Dennis Sosnoski,
Reflection Drawbacks
‱ Performance overhead
‱ Dynamically type resolutions occlude JVM optimizations.
‱ Should be avoided in parts of code in performance sensitive applications
‱ Security Restrictions
‱ Requires a runtime permission, so your code may not run in a restricted
security context.
‱ Exposure of Internals
‱ Accessing private fields and methods
‱ Reflective code breaks abstractions*
References
Article from Oracle -
https://docs.oracle.com/javase/tutorial/reflect/
http://docs.oracle.com/javase/8/docs/api/index.html?java/lang/Class.
html
Dennis Sosnoski’s Article on Reflection -
http://www.ibm.com/developerworks/java/library/j-
dyn0603/index.html
Source Code Snippets -
https://github.com/imranhasanhira/java-reflection-annotation-test
Thank You 

More Related Content

PPTX
Java reflection
PPTX
Reflection in Java
PPT
Reflection in java
PDF
Java Reflection Explained Simply
PDF
Basics of reflection in java
PPTX
Diving into Java Class Loader
PDF
Understanding And Using Reflection
PPTX
OCP Java (OCPJP) 8 Exam Quick Reference Card
Java reflection
Reflection in Java
Reflection in java
Java Reflection Explained Simply
Basics of reflection in java
Diving into Java Class Loader
Understanding And Using Reflection
OCP Java (OCPJP) 8 Exam Quick Reference Card

What's hot (20)

PPTX
Java interview questions 1
PDF
Reflection in Ruby
PPTX
Java interview questions 2
PPTX
Java Reflection Concept and Working
PDF
Basics of reflection
PDF
1z0-808-certification-questions-sample
PPT
Object Oriented Programming with Java
PPTX
Introduction to Ruby’s Reflection API
PDF
A gentle introduction to reflection
DOCX
Basic java important interview questions and answers to secure a job
PPTX
Basics of Java
PPTX
Playing with Java Classes and Bytecode
PPTX
Statics in java | Constructors | Exceptions in Java | String in java| class 3
PDF
Advanced java interview questions
PPTX
OCA Java SE 8 Exam Chapter 5 Class Design
DOCX
Java questions for viva
PPTX
OCA Java SE 8 Exam Chapter 6 Exceptions
PPT
9781111530532 ppt ch10
PPTX
Java training in delhi
PPTX
Object+oriented+programming+in+java
 
Java interview questions 1
Reflection in Ruby
Java interview questions 2
Java Reflection Concept and Working
Basics of reflection
1z0-808-certification-questions-sample
Object Oriented Programming with Java
Introduction to Ruby’s Reflection API
A gentle introduction to reflection
Basic java important interview questions and answers to secure a job
Basics of Java
Playing with Java Classes and Bytecode
Statics in java | Constructors | Exceptions in Java | String in java| class 3
Advanced java interview questions
OCA Java SE 8 Exam Chapter 5 Class Design
Java questions for viva
OCA Java SE 8 Exam Chapter 6 Exceptions
9781111530532 ppt ch10
Java training in delhi
Object+oriented+programming+in+java
 
Ad

Similar to Java Reflection @KonaTechAdda (20)

PPTX
Digital Publishing with the OSCI Toolkit - Workshop MCN 2012
PDF
Ebay legacy-code-retreat
PPTX
Core java training in Marathahalli, Bangalore
 
PPTX
Core java training in Marathahalli, Bangalore
 
PPTX
Introduction to Module Development with Appcelerator Titanium
PPTX
Codestrong 2012 breakout session how to develop your own modules
PPTX
How to crack java script certification
PDF
Learn Java with Dr. Rifat Shahriyar
DOCX
Java se 8 fundamentals
PPT
Mastering OmniFaces - A Problem to Solution Approach
PPT
Power of introspection
PPTX
Constructors in java
PPTX
DF15 - Dynamic Apex Binding with design patterns
KEY
Attributes, reflection, and dynamic programming
PPT
Story ofcorespring infodeck
PPTX
Complete PPT about the Java lokesh kept it
PDF
"Framework Principal" pattern
PDF
Swift Micro-services and AWS Technologies
PDF
Spring framework
PDF
How to train the jdt dragon
Digital Publishing with the OSCI Toolkit - Workshop MCN 2012
Ebay legacy-code-retreat
Core java training in Marathahalli, Bangalore
 
Core java training in Marathahalli, Bangalore
 
Introduction to Module Development with Appcelerator Titanium
Codestrong 2012 breakout session how to develop your own modules
How to crack java script certification
Learn Java with Dr. Rifat Shahriyar
Java se 8 fundamentals
Mastering OmniFaces - A Problem to Solution Approach
Power of introspection
Constructors in java
DF15 - Dynamic Apex Binding with design patterns
Attributes, reflection, and dynamic programming
Story ofcorespring infodeck
Complete PPT about the Java lokesh kept it
"Framework Principal" pattern
Swift Micro-services and AWS Technologies
Spring framework
How to train the jdt dragon
Ad

Recently uploaded (20)

PPTX
L1 - Introduction to python Backend.pptx
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
System and Network Administration Chapter 2
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
 
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Digital Strategies for Manufacturing Companies
PPTX
Essential Infomation Tech presentation.pptx
L1 - Introduction to python Backend.pptx
Design an Analysis of Algorithms II-SECS-1021-03
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Upgrade and Innovation Strategies for SAP ERP Customers
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PTS Company Brochure 2025 (1).pdf.......
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Wondershare Filmora 15 Crack With Activation Key [2025
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Design an Analysis of Algorithms I-SECS-1021-03
How to Migrate SBCGlobal Email to Yahoo Easily
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
System and Network Administration Chapter 2
Odoo Companies in India – Driving Business Transformation.pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
 
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Operating system designcfffgfgggggggvggggggggg
Digital Strategies for Manufacturing Companies
Essential Infomation Tech presentation.pptx

Java Reflection @KonaTechAdda