Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Newbie - what is the class Class?

Reply
Thread Tools

Newbie - what is the class Class?

 
 
zalek
Guest
Posts: n/a
 
      07-04-2008
I am looking on some code where I see the method getClass() is used.
From Java site I read that Class class is "Instances of the class
Class represent classes and interfaces in a running Java application.
As I understand instance of a class is an object - so what a point to
get a Class from an object?

Thanks,

Zalek

 
Reply With Quote
 
 
 
 
Arne Vajh°j
Guest
Posts: n/a
 
      07-04-2008
zalek wrote:
> I am looking on some code where I see the method getClass() is used.
> From Java site I read that Class class is "Instances of the class
> Class represent classes and interfaces in a running Java application.
> As I understand instance of a class is an object - so what a point to
> get a Class from an object?


Lookup the methods of the class in the docs, then its use should
be obvious.

The keyword is "reflection".

Arne
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      07-04-2008
On Fri, 4 Jul 2008 16:03:35 -0700 (PDT), zalek
<(E-Mail Removed)> wrote, quoted or indirectly quoted someone
who said :

> - so what a point to
>get a Class from an object?


see http://mindprod.com/jgloss/classforname.html

that will get you started.
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Reply With Quote
 
Joshua Cranmer
Guest
Posts: n/a
 
      07-05-2008
zalek wrote:
> I am looking on some code where I see the method getClass() is used.
> From Java site I read that Class class is "Instances of the class
> Class represent classes and interfaces in a running Java application.
> As I understand instance of a class is an object - so what a point to
> get a Class from an object?


The Class object is an object representing metadata about the class.
Most of the time, one doesn't need it. However, it is useful in two areas:
1. Generics reification hacks. It's the only way to do something like
"new T()" at this point.
2. A branch of programming called reflection. A simple description of
this is the ability to do dynamic operations, such as implementing a
scripting language in Java.

I do realize that the Generics reification hack is a special case of the
latter, but it is widely-used enough in its own sense (IMHO) to warrant
being listed separately. And this is by no means a complete list of
where one might want to use Class objects.


--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      07-06-2008
Jane, we were right. It *was* NewsMaestro!

--
Lew


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[NWO, degenerate, Zionism, fascism, genocide, Illuminati, Freemasons]

Listen to the Jewish banker, Paul Warburg:

"We will have a world government whether you like it or not.
The only question is whether that government will be achieved
by conquest or consent."

(February 17, 1950, as he testified before the US Senate).

 
Reply With Quote
 
Ian Shef
Guest
Posts: n/a
 
      07-11-2008
Joshua Cranmer <(E-Mail Removed)> wrote in news:wQybk.260$wa1.103
@trndny07:

> zalek wrote:
>> I am looking on some code where I see the method getClass() is used.
>> From Java site I read that Class class is "Instances of the class
>> Class represent classes and interfaces in a running Java application.
>> As I understand instance of a class is an object - so what a point to
>> get a Class from an object?

>
> The Class object is an object representing metadata about the class.
> Most of the time, one doesn't need it. However, it is useful in two areas:
> 1. Generics reification hacks. It's the only way to do something like
> "new T()" at this point.
> 2. A branch of programming called reflection. A simple description of
> this is the ability to do dynamic operations, such as implementing a
> scripting language in Java.


The book _Java Reflection in Action_ by Ira R. Forman and Nate Forman is
useful for a deeper understanding of metadata and reflection.

There is even a figure that will help understand how a Class object can
extend from Object and yet describe any Java object (including a Class
object).

Published prior to JDK 1.5, it doesn't have much about Generics. There is a
little in the back, based on what was known about Generics at the time.






 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      07-12-2008
On Fri, 4 Jul 2008 16:03:35 -0700 (PDT), zalek
<(E-Mail Removed)> wrote, quoted or indirectly quoted someone
who said :

>I am looking on some code where I see the method getClass() is used.
>From Java site I read that Class class is "Instances of the class
>Class represent classes and interfaces in a running Java application.
>As I understand instance of a class is an object - so what a point to
>get a Class from an object?


see http://mindprod.com/jgloss/classforname.html
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy constructor for a class that contains a pointer to a base class type (newbie) SzH C++ 1 10-27-2006 09:21 PM
Class A contains class B, class B points to class A Joseph Turian C++ 5 12-30-2005 03:24 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM
Newbie Question: Function of a class keeps "forgetting" data thats declared inside class Snoeys Andy C++ 2 09-12-2003 06:15 PM



Advertisments