File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes A question on reflection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "A question on reflection" Watch "A question on reflection" New topic
Author

A question on reflection

Velmurugan Periasamy
Ranch Hand

Joined: Nov 09, 2000
Posts: 95
The following is a quote from Sun tutorial on reflection API.

If you know the name of the class at compile time, you can retrieve its Class object by appending .class to its name. In the next example, the Class object that represents the Button class is retrieved:


What's the mechanism behind appending the word class with the name of the class? How does that work?
Thanks.


------------------
Velmurugan Periasamy
Sun Certified Java Programmer
----------------------
Study notes for Sun Java Certification
http://www.geocities.com/velmurugan_p/


------------------------------------------------------------------------------------<BR>Velmurugan Periasamy<BR>Sun Certified Java Programmer for Java 2 Platform<BR>Sun Certified Web Component Developer for J2EE platform<BR>Sybase Certified EAServer Developer (similar to jCert level 3)<BR>------------------------------------------------------------------------------------<BR>Study notes for Sun Java Certification<BR><A HREF="http://www.geocities.com/velmurugan_p/" TARGET=_blank rel="nofollow">http://www.geocities.com/velmurugan_p/</A><BR>------------------------------------------------------------------------------------
Velmurugan Periasamy
Ranch Hand

Joined: Nov 09, 2000
Posts: 95
BTW, The above quote is taken from the following URL:
http://java.sun.com/docs/books/tutorial/reflect/class/getClass.html
Thanks.
------------------
Velmurugan Periasamy
Sun Certified Java Programmer
----------------------
Study notes for Sun Java Certification
http://www.geocities.com/velmurugan_p/
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
That's called a class literal - it's part of the language specification, right here. Basically that means that any Java compiler is required to recognize that if I type "Frame.class" for example, it should substitute a reference for the Class object representing a Frame. Much the way if I type a string literal enclosed in quotes, the compiler will interpret that as a reference to a String object.

"I'm not back." - Bill Harding, Twister
Velmurugan Periasamy
Ranch Hand

Joined: Nov 09, 2000
Posts: 95
Thanks Jim.
------------------
Velmurugan Periasamy
Sun Certified Java Programmer
----------------------
Study notes for Sun Java Certification
http://www.geocities.com/velmurugan_p/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A question on reflection