SlideShare a Scribd company logo
1 of 17
Download to read offline
Reflection - The most
important feature in
Java
Sarath Soman
@sarathsom4
sarathsoman.wordpress.com
About Me
Software Engineer @ Hifx
What is Reflection?
Reflection is the ability of a program to examine itself, modify its structure,
modify state using the structural information and generate new state and
structure.
How is reflection possible?
Representation of the source (metadata) should be available at runtime (The
compiler should bake the required meta information).
Runtime should provide APIs to reflect.
How does javac & jvm makes Reflection
possible?
Class file format
Class(.class) & the Class loader
Let’s see the bytecode of Contact.java
Let’s reflect on Contact.java
Why should I learn this?
Types of Programmers
Application Programmers - frameworks, libs, common design patterns
Library Designers - DSA, Design principles and patterns, API design
System Programmers - JVM, CLR, CPU, Native code programming, Cross
platform programming
Do you want to die as an average application
programmer ?
Let’s build a small Object Serialization lib
Limitations of Java Reflection
Cannot manipulate & generate code
Deep introspection on code is not possible
Solution : Need bytecode manipulation support.
Third party options : ASM, Javassist, BCEL, CGLIB
What is not covered
MethodHandles
Java 9 Changes
Few Articles
SimplifyJSPServlet - A web framework on top of Servlet, this makes use of
reflection
https://sarathsoman.wordpress.com/2014/05/29/making-simplifyjspservlet-thr
ead-safe/
PVSContainer - A dependency injection container, uses ASM to get class meta
data and reflection for dependency injection
https://sarathsoman.wordpress.com/category/java/pvscontainer/
Reflections in Golang -
https://sarathsoman.wordpress.com/2016/12/27/reflections-in-golang-example
Few Articles
The Class & The ClassLoader -
https://sarathsoman.wordpress.com/2014/01/15/the-class-the-classloader/
Java Reflection Example -
https://sarathsoman.wordpress.com/2014/01/12/invoking-methods-annotated-
with-the-time-for-invokation-using-java-reflection
Java Proxy -
https://sarathsoman.wordpress.com/2014/01/10/decoupling-cross-cutting-con
cerns-using-java-proxy-an-example
Github links
PVSContainer - https://github.com/nsarathsoman/PVSContainer
ObjectSerialization -
https://github.com/nsarathsoman/ObjectSerialization-KJUG-Demo
SimplifyJSPServlet - https://github.com/nsarathsoman/SimplifyJSPServlet
Proxy Demo - https://github.com/nsarathsoman/KJUG-Demo-Sep-Proxy
Slang Compiler
https://github.com/nsarathsoman/SlangCompiler
https://github.com/nsarathsoman/slang4JVM
A higher order function in Slang
function (int,int)->int adder()
var z = 10;
var x = lambda int (int x, int y)
println x;
println y;
return ( x + y ) * z;
endlambda
return x;
end
Thank You

More Related Content

Similar to Reflections the most important feature in java

Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language Hitesh-Java
 
Session 02 - Elements of Java Language
Session 02 - Elements of Java LanguageSession 02 - Elements of Java Language
Session 02 - Elements of Java LanguagePawanMM
 
Avoid Drowning
Avoid DrowningAvoid Drowning
Avoid DrowningLynn Root
 
Introduction To Building Enterprise Web Application With Spring Mvc
Introduction To Building Enterprise Web Application With Spring MvcIntroduction To Building Enterprise Web Application With Spring Mvc
Introduction To Building Enterprise Web Application With Spring MvcAbdelmonaim Remani
 
Lunch and learn as3_frameworks
Lunch and learn as3_frameworksLunch and learn as3_frameworks
Lunch and learn as3_frameworksYuri Visser
 
The Art of Metaprogramming in Java
The Art of Metaprogramming in Java  The Art of Metaprogramming in Java
The Art of Metaprogramming in Java Abdelmonaim Remani
 
Unit1 introduction to Java
Unit1 introduction to JavaUnit1 introduction to Java
Unit1 introduction to JavaDevaKumari Vijay
 
What's new in Java 8
What's new in Java 8What's new in Java 8
What's new in Java 8jclingan
 
Functional Programming In Jdk8
Functional Programming In Jdk8 Functional Programming In Jdk8
Functional Programming In Jdk8 Bansilal Haudakari
 
java web framework standard.20180412
java web framework standard.20180412java web framework standard.20180412
java web framework standard.20180412FirmansyahIrma1
 
Reverse Engineering: Protecting and Breaking the Software (Workshop)
Reverse Engineering: Protecting and Breaking the Software (Workshop)Reverse Engineering: Protecting and Breaking the Software (Workshop)
Reverse Engineering: Protecting and Breaking the Software (Workshop)Satria Ady Pradana
 
Java questions and answers jan bask.net
Java questions and answers jan bask.netJava questions and answers jan bask.net
Java questions and answers jan bask.netJanbask ItTraining
 
Introduction Java Web Framework and Web Server.
Introduction Java Web Framework and Web Server.Introduction Java Web Framework and Web Server.
Introduction Java Web Framework and Web Server.suranisaunak
 
Core java learning path for beginners
Core java learning path for beginnersCore java learning path for beginners
Core java learning path for beginnersJobbackingCodeHelpMe
 
(Workshop) Reverse Engineering - Protecting and Breaking the Software
(Workshop) Reverse Engineering - Protecting and Breaking the Software(Workshop) Reverse Engineering - Protecting and Breaking the Software
(Workshop) Reverse Engineering - Protecting and Breaking the SoftwareSatria Ady Pradana
 

Similar to Reflections the most important feature in java (20)

Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language
 
Session 02 - Elements of Java Language
Session 02 - Elements of Java LanguageSession 02 - Elements of Java Language
Session 02 - Elements of Java Language
 
Avoid Drowning
Avoid DrowningAvoid Drowning
Avoid Drowning
 
Raptor 2
Raptor 2Raptor 2
Raptor 2
 
Introduction To Building Enterprise Web Application With Spring Mvc
Introduction To Building Enterprise Web Application With Spring MvcIntroduction To Building Enterprise Web Application With Spring Mvc
Introduction To Building Enterprise Web Application With Spring Mvc
 
Lunch and learn as3_frameworks
Lunch and learn as3_frameworksLunch and learn as3_frameworks
Lunch and learn as3_frameworks
 
Java1
Java1Java1
Java1
 
Java
Java Java
Java
 
The Art of Metaprogramming in Java
The Art of Metaprogramming in Java  The Art of Metaprogramming in Java
The Art of Metaprogramming in Java
 
Unit1 introduction to Java
Unit1 introduction to JavaUnit1 introduction to Java
Unit1 introduction to Java
 
Java 8
Java 8Java 8
Java 8
 
What's new in Java 8
What's new in Java 8What's new in Java 8
What's new in Java 8
 
Functional Programming In Jdk8
Functional Programming In Jdk8 Functional Programming In Jdk8
Functional Programming In Jdk8
 
java web framework standard.20180412
java web framework standard.20180412java web framework standard.20180412
java web framework standard.20180412
 
Java Programming.pdf
Java Programming.pdfJava Programming.pdf
Java Programming.pdf
 
Reverse Engineering: Protecting and Breaking the Software (Workshop)
Reverse Engineering: Protecting and Breaking the Software (Workshop)Reverse Engineering: Protecting and Breaking the Software (Workshop)
Reverse Engineering: Protecting and Breaking the Software (Workshop)
 
Java questions and answers jan bask.net
Java questions and answers jan bask.netJava questions and answers jan bask.net
Java questions and answers jan bask.net
 
Introduction Java Web Framework and Web Server.
Introduction Java Web Framework and Web Server.Introduction Java Web Framework and Web Server.
Introduction Java Web Framework and Web Server.
 
Core java learning path for beginners
Core java learning path for beginnersCore java learning path for beginners
Core java learning path for beginners
 
(Workshop) Reverse Engineering - Protecting and Breaking the Software
(Workshop) Reverse Engineering - Protecting and Breaking the Software(Workshop) Reverse Engineering - Protecting and Breaking the Software
(Workshop) Reverse Engineering - Protecting and Breaking the Software
 

More from Sarath Soman

Zero hype intro to machine learning
Zero hype intro to machine learningZero hype intro to machine learning
Zero hype intro to machine learningSarath Soman
 
Java virtual machine 101
Java virtual machine 101Java virtual machine 101
Java virtual machine 101Sarath Soman
 
Introduction to jvm with asm
Introduction to jvm with asmIntroduction to jvm with asm
Introduction to jvm with asmSarath Soman
 
A peek into the implementation of lambda expression
A peek into the implementation of lambda expressionA peek into the implementation of lambda expression
A peek into the implementation of lambda expressionSarath Soman
 
Java virtual machine 101
Java virtual machine 101Java virtual machine 101
Java virtual machine 101Sarath Soman
 
Kmug 21-jan-2017-presentation.pptx
Kmug 21-jan-2017-presentation.pptxKmug 21-jan-2017-presentation.pptx
Kmug 21-jan-2017-presentation.pptxSarath Soman
 
Byte code engineering 21st May Saturday 2016
Byte code engineering   21st May Saturday 2016Byte code engineering   21st May Saturday 2016
Byte code engineering 21st May Saturday 2016Sarath Soman
 

More from Sarath Soman (7)

Zero hype intro to machine learning
Zero hype intro to machine learningZero hype intro to machine learning
Zero hype intro to machine learning
 
Java virtual machine 101
Java virtual machine 101Java virtual machine 101
Java virtual machine 101
 
Introduction to jvm with asm
Introduction to jvm with asmIntroduction to jvm with asm
Introduction to jvm with asm
 
A peek into the implementation of lambda expression
A peek into the implementation of lambda expressionA peek into the implementation of lambda expression
A peek into the implementation of lambda expression
 
Java virtual machine 101
Java virtual machine 101Java virtual machine 101
Java virtual machine 101
 
Kmug 21-jan-2017-presentation.pptx
Kmug 21-jan-2017-presentation.pptxKmug 21-jan-2017-presentation.pptx
Kmug 21-jan-2017-presentation.pptx
 
Byte code engineering 21st May Saturday 2016
Byte code engineering   21st May Saturday 2016Byte code engineering   21st May Saturday 2016
Byte code engineering 21st May Saturday 2016
 

Recently uploaded

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 

Recently uploaded (20)

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 

Reflections the most important feature in java

  • 1. Reflection - The most important feature in Java Sarath Soman @sarathsom4 sarathsoman.wordpress.com
  • 3. What is Reflection? Reflection is the ability of a program to examine itself, modify its structure, modify state using the structural information and generate new state and structure.
  • 4. How is reflection possible? Representation of the source (metadata) should be available at runtime (The compiler should bake the required meta information). Runtime should provide APIs to reflect.
  • 5. How does javac & jvm makes Reflection possible? Class file format Class(.class) & the Class loader
  • 6. Let’s see the bytecode of Contact.java
  • 7. Let’s reflect on Contact.java
  • 8. Why should I learn this? Types of Programmers Application Programmers - frameworks, libs, common design patterns Library Designers - DSA, Design principles and patterns, API design System Programmers - JVM, CLR, CPU, Native code programming, Cross platform programming
  • 9. Do you want to die as an average application programmer ?
  • 10. Let’s build a small Object Serialization lib
  • 11. Limitations of Java Reflection Cannot manipulate & generate code Deep introspection on code is not possible Solution : Need bytecode manipulation support. Third party options : ASM, Javassist, BCEL, CGLIB
  • 12. What is not covered MethodHandles Java 9 Changes
  • 13. Few Articles SimplifyJSPServlet - A web framework on top of Servlet, this makes use of reflection https://sarathsoman.wordpress.com/2014/05/29/making-simplifyjspservlet-thr ead-safe/ PVSContainer - A dependency injection container, uses ASM to get class meta data and reflection for dependency injection https://sarathsoman.wordpress.com/category/java/pvscontainer/ Reflections in Golang - https://sarathsoman.wordpress.com/2016/12/27/reflections-in-golang-example
  • 14. Few Articles The Class & The ClassLoader - https://sarathsoman.wordpress.com/2014/01/15/the-class-the-classloader/ Java Reflection Example - https://sarathsoman.wordpress.com/2014/01/12/invoking-methods-annotated- with-the-time-for-invokation-using-java-reflection Java Proxy - https://sarathsoman.wordpress.com/2014/01/10/decoupling-cross-cutting-con cerns-using-java-proxy-an-example
  • 15. Github links PVSContainer - https://github.com/nsarathsoman/PVSContainer ObjectSerialization - https://github.com/nsarathsoman/ObjectSerialization-KJUG-Demo SimplifyJSPServlet - https://github.com/nsarathsoman/SimplifyJSPServlet Proxy Demo - https://github.com/nsarathsoman/KJUG-Demo-Sep-Proxy
  • 16. Slang Compiler https://github.com/nsarathsoman/SlangCompiler https://github.com/nsarathsoman/slang4JVM A higher order function in Slang function (int,int)->int adder() var z = 10; var x = lambda int (int x, int y) println x; println y; return ( x + y ) * z; endlambda return x; end