wood burning stoves*
The moose likes Java in General and the fly likes Real Usage of java Reflection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Real Usage of java Reflection" Watch "Real Usage of java Reflection" New topic
Author

Real Usage of java Reflection

Nuwan Arambage
Ranch Hand

Joined: May 05, 2010
Posts: 76
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 ?.



Thinker
Nuwan Arambage
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3028
    
  35

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.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Nuwan Arambage
Ranch Hand

Joined: May 05, 2010
Posts: 76
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
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3028
    
  35

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

Joined: May 05, 2010
Posts: 76
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

Joined: May 05, 2010
Posts: 76
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


Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

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.


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Nuwan Arambage
Ranch Hand

Joined: May 05, 2010
Posts: 76
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Real Usage of java Reflection
 
Similar Threads
Java class and Java Bean
Where to use Reflection in our program or realtime.
Some Questions from Mock Exam
Urgent : Creating a JavaBean dynamically
does java annotations uses the java refection.