permaculture playing cards*
The moose likes Java in General and the fly likes Real use case example for reflection in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Real use case example for reflection in java" Watch "Real use case example for reflection in java" New topic
Author

Real use case example for reflection in java

Nishanth Hampali
Greenhorn

Joined: Dec 07, 2010
Posts: 1
Hi All,

I was going through the reflection concept in java.
From the tutorial i could understand that it allows the running java program to get to know its internal properties..

Now i could not think any real examples for this scenario. Can you please help me with one such real example?

Thanks in advance
Ramon Anger
Ranch Hand

Joined: Apr 19, 2011
Posts: 56

Hi Nishanth,

the simplest example I could think of is registering a JDBC database driver by using Class.forName(String className) before you can establish a database connection.

See http://www.jdbc-tutorial.com/.

Cheers,
Ramon


Blackbelt on BlackBeltFactory.com.
Aditya Jha
Ranch Hand

Joined: Aug 25, 2003
Posts: 227

Every component-container mechanism is built using reflection. Examples are plenty - Servlet container, EJB container, Spring IoC container, even Struts and all externally configured web frameworks.

Basically, whenever we configure a Java object in XML (or any external medium) and try to set any properties on it from config itself, reflection is in the picture. Though it is hidden from application programmers and is implemented in the container itself.
Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 1212
    
    1

Hi

Posting one real case scenario where java reflection can be handy.

For eg - finding details of java class of which you have no source code access. only .class file is present with you.

There you can use java reflection code which can take fully qualified class name and print all its instance variables and methods signature. In this way you will be able to get some details around that class.

Thanks
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

http://www.coderanch.com/t/518546/java/java/Real-Usage-java-Reflection
 
 
subject: Real use case example for reflection in java