FindClass

A

aa

Hallo,

what is the return value of 'findClass' exactly? Is
it a pointer to the memory which contains executable
code of the class? Can I feed this pointer myself with
a byte stream that contains a class file (*.class)? My
problem is this, that I don't have any JAR file to load
my classes from it, I get the executable class code
in a byte stream and want call some methods of it...

Hava anbody any idea?

Thanks in advance,
Anahita
 
D

Daniel Pitts

Hallo,

what is the return value of 'findClass' exactly? Is
it a pointer to the memory which contains executable
code of the class? Can I feed this pointer myself with
a byte stream that contains a class file (*.class)? My
problem is this, that I don't have any JAR file to load
my classes from it, I get the executable class code
in a byte stream and want call some methods of it...

Hava anbody any idea?

Thanks in advance,
Anahita

If you have a byte stream that represents a class, you have to load the
class into the JVM (look at ClassLoader). Once it is loaded into the
JVM, the ClassLoader will give you a Class object. You can use the
Reflection API to instantiate and use objects of that class.
 
M

Mark Rafn

what is the return value of 'findClass' exactly?

You mean the findClass(String) method in ClassLoader? The return value is a
Class object. Is that not clear from the javadoc?
Is it a pointer to the memory which contains executable code of the class?

Kind of. defineClass() turns a byte array containing JVM bytecode into a
Class object. findClass() finds the bytecode, calls defineClass() on it, and
returns the result.
Can I feed this pointer myself with a byte stream that contains a class
file (*.class)? My problem is this, that I don't have any JAR file to load
my classes from it, I get the executable class code in a byte stream and
want call some methods of it...

Yup. Create your own subclass of ClassLoader (usually of URLClassLoader), and
override the appropriate method for what level of control you need. See the
source for URLClassLoader for reference.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,270
Messages
2,571,102
Members
48,773
Latest member
Kaybee

Latest Threads

Top