SlideShare a Scribd company logo
3
Most read
4
Most read
5
Most read
Java Reflection
Agenda
What is Reflection?
How to get the object Class class
Reflection vs Metaprogramming
Why do we need reflection?
Demo
Real Usage Examples
What is Reflection?
Reflection is used for observing and modifying program execution at runtime.
A reflection-oriented program component can monitor the execution of an
enclosure of code and can modify itself according to a desired goal related to that
enclosure.
Reflection is one of those things like multi-threading where everyone with experience of
it says “Don’t use it unless you absolutely have to”.
Example:
// without reflection
Foo foo = new Foo();
foo.hello();
// with reflection
Object foo = Class.forName("complete.classpath.and.Foo").newInstance();
// Alternatively: Object foo = Foo.class.newInstance();
Method m = foo.getClass().getDeclaredMethod("hello", new Class<?>[0]);
m.invoke(foo);
How to get the object of Class class
forName() method of Class class
Class c=Class.forName("Simple")
System.out.println(c.getName())
getClass() method of Object class
Class c=obj.getClass();
System.out.println(c.getName());
the .class syntax
Class c2 = Test.class;
System.out.println(c2.getName());
Reflection vs Metaprogramming
Metaprogramming is "programs which write programs". This includes programs
that read the text of programs (arguably including themselves but that is rather
rare), analyze that code, and make changes.
Reflection is the ability for a program to inquire about its own structure.
Why do we need reflection?
Examine an object’s class at runtime
Construct an object for a class at runtime
Examine a class’s field and method at runtime
Invoke any method of an object at runtime
Demo
Real Usage Example
Code analyzer tools
Eclipse (Other IDEs) auto completion of method names
Spring Framework for creating the beans
Parsing annotations by ORMs like hibernate entity
Somewhere I read this quote:
“When you will need reflection; you will know it”.
For live project example
https://github.com/NexThoughts/ReflectionDemo
References
http://tutorials.jenkov.com/java-reflection/index.html
http://www.javatpoint.com/java-reflection
http://www.programmerinterview.com/index.php/java-questions/java-reflection-
example/
http://howtodoinjava.com/core-java/annotations/complete-java-annotations-
tutorial/
http://howtodoinjava.com/core-java/related-concepts/real-usage-examples-of-
reflection-in-java/
Thanks You

More Related Content

What's hot (20)

PPTX
Java 8 - Features Overview
Sergii Stets
 
PPTX
Java 8 lambda
Manav Prasad
 
PPT
Java adapter
Arati Gadgil
 
PPT
Java interfaces & abstract classes
Shreyans Pathak
 
PDF
Java Collection framework
ankitgarg_er
 
PPT
C# Exceptions Handling
sharqiyem
 
PPTX
Collections and its types in C# (with examples)
Aijaz Ali Abro
 
PPTX
Polymorphism in java
Elizabeth alexander
 
PPTX
Exception handling
PhD Research Scholar
 
PPT
Java multi threading
Raja Sekhar
 
PPTX
Java database connectivity with MySql
Dhyey Dattani
 
PPTX
C# Delegates
Raghuveer Guthikonda
 
PPT
Core java concepts
Ram132
 
PDF
Polymorphism In Java
Spotle.ai
 
PDF
Java 8 Workshop
Mario Fusco
 
PDF
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Edureka!
 
PPTX
Delegates and events in C#
Dr.Neeraj Kumar Pandey
 
PPT
Exception Handling in JAVA
SURIT DATTA
 
Java 8 - Features Overview
Sergii Stets
 
Java 8 lambda
Manav Prasad
 
Java adapter
Arati Gadgil
 
Java interfaces & abstract classes
Shreyans Pathak
 
Java Collection framework
ankitgarg_er
 
C# Exceptions Handling
sharqiyem
 
Collections and its types in C# (with examples)
Aijaz Ali Abro
 
Polymorphism in java
Elizabeth alexander
 
Exception handling
PhD Research Scholar
 
Java multi threading
Raja Sekhar
 
Java database connectivity with MySql
Dhyey Dattani
 
C# Delegates
Raghuveer Guthikonda
 
Core java concepts
Ram132
 
Polymorphism In Java
Spotle.ai
 
Java 8 Workshop
Mario Fusco
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Edureka!
 
Delegates and events in C#
Dr.Neeraj Kumar Pandey
 
Exception Handling in JAVA
SURIT DATTA
 

Viewers also liked (20)

PPTX
Grails custom tag lib
NexThoughts Technologies
 
PPT
Bootcamp linux commands
NexThoughts Technologies
 
PDF
Grails internationalization-160524154831
NexThoughts Technologies
 
PPTX
Meta Programming in Groovy
NexThoughts Technologies
 
ODP
Groovy intro
NexThoughts Technologies
 
PPTX
Introduction to mongo db
NexThoughts Technologies
 
PPTX
Spring boot
NexThoughts Technologies
 
PDF
Unit test-using-spock in Grails
NexThoughts Technologies
 
PPTX
Actors model in gpars
NexThoughts Technologies
 
PPTX
MetaProgramming with Groovy
NexThoughts Technologies
 
PPT
Grails Controllers
NexThoughts Technologies
 
PPTX
Grails services
NexThoughts Technologies
 
PPTX
Grails with swagger
NexThoughts Technologies
 
PPTX
Groovy DSL
NexThoughts Technologies
 
ODP
Command objects
NexThoughts Technologies
 
Grails custom tag lib
NexThoughts Technologies
 
Bootcamp linux commands
NexThoughts Technologies
 
Grails internationalization-160524154831
NexThoughts Technologies
 
Meta Programming in Groovy
NexThoughts Technologies
 
Introduction to mongo db
NexThoughts Technologies
 
Unit test-using-spock in Grails
NexThoughts Technologies
 
Actors model in gpars
NexThoughts Technologies
 
MetaProgramming with Groovy
NexThoughts Technologies
 
Grails Controllers
NexThoughts Technologies
 
Grails services
NexThoughts Technologies
 
Grails with swagger
NexThoughts Technologies
 
Command objects
NexThoughts Technologies
 
Ad

Similar to Java reflection (20)

PPT
Reflection in java
upen.rockin
 
PPTX
Reflection in Java
Nikhil Bhardwaj
 
PPTX
Java Reflection Concept and Working
Software Productivity Strategists, Inc
 
PPTX
Java Reflection @KonaTechAdda
Md Imran Hasan Hira
 
PDF
Java Reflection Explained Simply
Ciaran McHale
 
PDF
Understanding And Using Reflection
Ganesh Samarthyam
 
PPTX
Cuối cùng cũng đã chuẩn bị slide xong cho seminar ngày mai. Mai seminar đầu t...
Khoa Nguyen
 
PDF
Reflection and Introspection
adil raja
 
PDF
Pharo: a reflective language A first systematic analysis of reflective APIs
ESUG
 
PDF
Metaprograms and metadata (as part of the the PTT lecture)
Ralf Laemmel
 
PPT
Reflection
Piyush Mittal
 
PDF
Advanced Reflection in Pharo
Pharo
 
PPT
10 reflection
The World of Smalltalk
 
PDF
Scala reflection
David Pichsenmeister
 
PDF
Java reflection
Ranjith Chaz
 
PDF
Антон Бикинеев, Reflection in C++Next
Sergey Platonov
 
PDF
Reflections the most important feature in java
Sarath Soman
 
PDF
Pharo: A Reflective System
Pharo
 
PDF
Java Reflection
Hamid Ghorbani
 
PDF
Dynamic Proxy by Java
Kan-Han (John) Lu
 
Reflection in java
upen.rockin
 
Reflection in Java
Nikhil Bhardwaj
 
Java Reflection Concept and Working
Software Productivity Strategists, Inc
 
Java Reflection @KonaTechAdda
Md Imran Hasan Hira
 
Java Reflection Explained Simply
Ciaran McHale
 
Understanding And Using Reflection
Ganesh Samarthyam
 
Cuối cùng cũng đã chuẩn bị slide xong cho seminar ngày mai. Mai seminar đầu t...
Khoa Nguyen
 
Reflection and Introspection
adil raja
 
Pharo: a reflective language A first systematic analysis of reflective APIs
ESUG
 
Metaprograms and metadata (as part of the the PTT lecture)
Ralf Laemmel
 
Reflection
Piyush Mittal
 
Advanced Reflection in Pharo
Pharo
 
10 reflection
The World of Smalltalk
 
Scala reflection
David Pichsenmeister
 
Java reflection
Ranjith Chaz
 
Антон Бикинеев, Reflection in C++Next
Sergey Platonov
 
Reflections the most important feature in java
Sarath Soman
 
Pharo: A Reflective System
Pharo
 
Java Reflection
Hamid Ghorbani
 
Dynamic Proxy by Java
Kan-Han (John) Lu
 
Ad

More from NexThoughts Technologies (20)

PDF
Alexa skill
NexThoughts Technologies
 
PDF
Docker & kubernetes
NexThoughts Technologies
 
PDF
Apache commons
NexThoughts Technologies
 
PDF
Microservice Architecture using Spring Boot with React & Redux
NexThoughts Technologies
 
PDF
Solid Principles
NexThoughts Technologies
 
PDF
Introduction to TypeScript
NexThoughts Technologies
 
PDF
Smart Contract samples
NexThoughts Technologies
 
PDF
My Doc of geth
NexThoughts Technologies
 
PDF
Geth important commands
NexThoughts Technologies
 
PDF
Ethereum genesis
NexThoughts Technologies
 
PPTX
Springboot Microservices
NexThoughts Technologies
 
PDF
An Introduction to Redux
NexThoughts Technologies
 
PPTX
Google authentication
NexThoughts Technologies
 
Docker & kubernetes
NexThoughts Technologies
 
Apache commons
NexThoughts Technologies
 
Microservice Architecture using Spring Boot with React & Redux
NexThoughts Technologies
 
Solid Principles
NexThoughts Technologies
 
Introduction to TypeScript
NexThoughts Technologies
 
Smart Contract samples
NexThoughts Technologies
 
My Doc of geth
NexThoughts Technologies
 
Geth important commands
NexThoughts Technologies
 
Ethereum genesis
NexThoughts Technologies
 
Springboot Microservices
NexThoughts Technologies
 
An Introduction to Redux
NexThoughts Technologies
 
Google authentication
NexThoughts Technologies
 

Recently uploaded (20)

PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit
 
PDF
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit
 
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Digital Circuits, important subject in CS
contactparinay1
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 

Java reflection