File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes what is java reflection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what is java reflection" Watch "what is java reflection" New topic

what is java reflection

sudheer kiran
Ranch Hand

Joined: Jun 26, 2008
Posts: 237

what is java reflection and in which case it is useful..i am asking just for to know what is what.

Ryan Clark

Joined: Jun 23, 2008
Posts: 1
Hey Sudheer,

Java reflection is a technique your program can use to see and modify its own structure. If you don't know what kind of class you have or what its methods are, you can use reflection to find out, then instantiate and call methods on that object. And if I remember correctly, you can view method signatures through reflection, but you can't see the implementation.

As for practical application, I once had to write a web app that could test any kind of class (new classes could be added and we didn't want to change our app). To test them, I used reflection to instantiate the object and get a list of methods to show the user. Once they picked a method, I'd let them enter data, called the method, and returned the output to the user.

Hope this helps! (It's my first post!)
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46397
I think it's helpful, Ryan, and welcome to JavaRanch

Sudheer K please check your private messages about an important administrative matter.
sudheer kiran
Ranch Hand

Joined: Jun 26, 2008
Posts: 237

hi thanks for the info
Siddharth Naik
Ranch Hand

Joined: Apr 09, 2006
Posts: 35
Here is a good article on reflection:

Thanks<br />Sid
I agree. Here's the link:
subject: what is java reflection
jQuery in Action, 3rd edition