File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes The .class property Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "The .class property" Watch "The .class property" New topic

The .class property

Dmitriy Pavlyuk
Ranch Hand

Joined: Mar 25, 2001
Posts: 33
Explain me please, where from the .class property appears in any Object descendant. It's not in Object!
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
I am going to guess that you are asking about reflection.
The JVM creates the Class object for each class.
From the API for Class:

Class has no public constructor. Instead Class objects are constructed automatically by the Java Virtual Machine as classes are loaded and by calls to the defineClass method in the class loader.

"JavaRanch, where the deer and the Certified play" - David O'Meara
Junilu Lacar

Joined: Feb 26, 2001
Posts: 6529

Or perhaps you are referring to Class Literals, which are evaluated at compile time and evaluate to the Class object of the named type. Refer to JLS �15.8.2 Sample usage below:

[This message has been edited by JUNILU LACAR (edited June 28, 2001).]

Junilu - [How to Ask Questions] [How to Answer Questions]
rani bedi
Ranch Hand

Joined: Feb 06, 2001
Posts: 358
Whats the use of the Class Literal?

Cheers,<br />Rani<br />SCJP, SCWCD, SCBCD
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Well, it allows you to refer to a particular Class object directly, without having to create an instance of the class first. If I want a StringBuffer Class object, it's more efficient to say "StringBuffer.class" than "new StringBuffer().getClass()".

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: The .class property
It's not a secret anymore!