What do you mean exactly by "creating a class definition at runtime", can you explain your question in more detail?
There are libraries that can help you to programmatically create class files and byte code, for example Apache BCEL (which stands for Byte Code Engineering Library). But this is very advanced and something that's only necessary for very specialistic applications. It's certainly not something that belongs in the "Beginning Java" forum...
Class Is not designed before I Run my code but It should be created by running code and dynamically I will create a Object from that class
?
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35223
7
posted
0
Two possible approaches are: a) Use a library like Jesper suggested. Instead of BCEL I'd go with Javassist, though, which makes it easy to create classes from code fragments.
b) Write the code to a ".java" file, compile it (there's an API for that in Java 6), and put the classes into the classpath of the application.
Well as Jesper said there are libraries for java to create the class files. Well i suppose when i had studied Programming with Components i.e COM there was something similar to that which created some files based on the signatures, but i think that is not at runtime. Its still during compiling, the class files are created after a successful compilation. May be i have forgot many things on that as it was some couple of years back. Just clarify on this please.