Dynamic class creation

C

Charles Fox

Could someone please point me to a good tutorial on dynamic class
creation? I'm building machine learning models, which need to invent
and their own classes as they go on. I seem to remember that Java can
do this somehow.
 
C

Chris Smith

Charles said:
Could someone please point me to a good tutorial on dynamic class
creation? I'm building machine learning models, which need to invent
and their own classes as they go on. I seem to remember that Java can
do this somehow.

You'll want to start out by reading the VM specification. You will end
up implementing your own ClassLoader, so look up java.lang.ClassLoader
in the API docs. Then take a look at:

http://java-source.net/open-source/bytecode-libraries

Many of those products almost certainly have tutorials and sample code.
The only one I've used is BCEL, so I can't give recommendations, but I
know Javassist and cglib are also generally popular.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
T

Tor Iver Wilhelmsen

Could someone please point me to a good tutorial on dynamic class
creation? I'm building machine learning models, which need to invent
and their own classes as they go on. I seem to remember that Java can
do this somehow.

I would recommend a different approach, where you dynamically create
sequences of "callable objects", perhaps following the Command or
Strategy pattern. Write (not synthesize) classes for the "atomic
operations", and make a class for a sequence of these atomic
operations. Then have the machine learning bit adjust parameters,
sequences etc. in these callable objects, instead of generating new
classes.
 
C

Chris Uppal

Charles said:
Could someone please point me to a good tutorial on dynamic class
creation? I'm building machine learning models, which need to invent
and their own classes as they go on. I seem to remember that Java can
do this somehow.

Assuming that you don't want to follow Tor's very sensible suggestion, and
adding to Chris's recommendations:

You will probably find some useful stuff in the GNU Kawa project -- a Scheme
system that dynamicaly compiles to Java bytecodes.

http://www.gnu.org/software/kawa/

I have seen comments to the effect that the bytecode generation library in Kawa
is easier to use than Apache BCEL, but I haven't used either of them myself.

You might also want to look for the book:

Programming for the Java Virtual Machine
Joshua Engel

which talks quite a lot about compiling non-Java to run on the JVM.

-- chris
 

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,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top