• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Real Usage of java Reflection

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody,

I have gone through java reflection basics.Java reflection allows us to inspect classes. by going through articles I got this point
But by the way,

I have no idea how this reflection thing can help to enterprise scale software development.
Eventually, my question is this,

Q 1:How java reflection helps enterprise level software problems ?.

Q 2:Real world examples of using java reflection ?.

 
Sheriff
Posts: 7337
1404
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Reflection API is not something which helps you to make the things easier in general purposes. Generally, reflection is not used in the applications running in generic enterprise containers or platforms. Nevertheless, reflection will not work when there is a SecurityManager available, unless the policies are configured to allow the use of reflection. Reflection API could be helpfully used if you are working in a reflection-allowed environment, where the direct collaboration with the Java classes is essential. Developing your own container for a specific architecture is an example for such.
 
Nuwan Arambage
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Devaka,
I got your point: it is not used in general purpose programming.

Can you specifically say what popular frameworks java reflection is used and what problem framework implementers try to solve using java reflection ?
I'm expecting a high level answer.


 
Devaka Cooray
Sheriff
Posts: 7337
1404
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I said before, reflection is used when it is needed to get into the other classes in deeper level. So in most of the cases, these implementors have the container-behavior. For instance, dependency injection is mostly done with the use of reflection. If you need a framework as an example for that, Spring does it's dependency injection jobs with the help of reflection API.
 
Nuwan Arambage
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Devaka Cooray wrote:As I said before, reflection is used when it is needed to get into the other classes in deeper level. So in most of the cases, these implementors have the container-behavior. For instance, dependency injection is mostly done with the use of reflection. If you need a framework as an example for that, Spring does it's dependency injection jobs with the help of reflection API.




thanks very much.....because I use to work with spring framework but I really don't know what goes behind the sense. Now I realized I have to know lot more rather than using just the spring for dependency injection.


 
Nuwan Arambage
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nuwan Arambage wrote:

Devaka Cooray wrote:As I said before, reflection is used when it is needed to get into the other classes in deeper level. So in most of the cases, these implementors have the container-behavior. For instance, dependency injection is mostly done with the use of reflection. If you need a framework as an example for that, Spring does it's dependency injection jobs with the help of reflection API.




thanks very much.....because I use to work with spring framework but I really don't know what goes behind the sense. Now I realized I have to know lot more rather than using just the spring for dependency injection.





yes..... definitely right... Spring dependency injection uses the java reflection api. it is a one example. I found another real world usages of java reflection by reading onjava article. I will mention them as below . perhaps helpful to you.

Eclipse manage to do all that helpful auto-completion of method names using reflection
Tomcat go from a class name in a web.xml file to a running servlet fielding web requests by exercising reflection.
when mapping objects to tables in a database at runtime in hibernate


 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will also find reflections used behind the scenes in a large number of areas. For example, if you used JAXB, then a lot of the marshalling / unmarshalling of the XML will be done using reflections. Using Annotations in your code often results in reflections being used behind the scenes. When performing unit testing, particularly when mocking classes and/or methods, often has lots of reflections code being used.
 
Nuwan Arambage
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Andrew Monkhouse wrote:You will also find reflections used behind the scenes in a large number of areas. For example, if you used JAXB, then a lot of the marshalling / unmarshalling of the XML will be done using reflections. Using Annotations in your code often results in reflections being used behind the scenes. When performing unit testing, particularly when mocking classes and/or methods, often has lots of reflections code being used.



As you said before, Java reflection is working behind the scene for annotations.Now I have a doubt, How Java reflection take care of annotations........simply I would ask how annotation processing happens with use of Java reflection
 
Rototillers convert rich soil into dirt. Please note that this tiny ad is not a rototiller:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic