|
-
Aug 15th, 2001, 12:41 AM
#1
Thread Starter
New Member
class & classLoader
There are two classes i want to know about:
java.lang.Class
java.lang.ClassLoader
I have consulted the jdk documentation but the information was not satisfying. Please tell me what these classes do and mean.
-
Aug 17th, 2001, 08:58 PM
#2
Dazed Member
java.lang.Class
This class represents a Java class or interface,or,as of Java 1.1 any Java type. There is one class Object for each class that is loaded into the JVM, and as of Java 1.1 there are special class Objects that represent the primative Java types. The TYPE constants define Boolean, Integer, and other primative wraper classes hold these special Class objects. Array types are also represented by class objects in Java 1.1
There is no constructor for this class. You can obtain a class object by calling the getClass() method of any instance of the desired class. In Java 1.1 and later, you can also refer to a class object by appending .class to the name of the class. Finally, and most interestingly, a class can be dynamisally loaded by passing it's full qualfied name(ie package name plus class name) to the static Class.forName() method. This method loads the named class (if it is not already loaded) into the Java Interpeter and returns a Class object for it. Classes can also be loaded with the ClassLoader object.
The newInstance() method creates an instance of a given class; this allows you to create instances of dynamically loaded classes for which you cannot use the new key word. *~ note this method only works when the target class has a no argument constructor.
You can also use newInstance() in java.lang.reflect.Constructor for a more powerfull way to instantiate dynamically loaded classes.
getName() returns the name of the class. getSuperclass returns it's superclass. isInterface() tests whether the class object represents an interface, and the getInterfaces() returns an array of the interfaces that this class implements.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|