I would like to know if there is a possibility to create new classes and make use of them during the runtime of an application. I have heard about Java Reflection API, can it be used to solve my problem ?
Java reflection api is used for creating objects at rumtime , but the classes should be already available.It cannot create classes at runtime.It can load class , instantiate object and other related stuffs.
somewhere i read java file can created , compiled and executed at runtime using scripting languages
Giving up is the easiest thing in the world to do..but holding it together when everything seems like falling apart is true strength!!
with regards, Harish.T
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12271
1
posted
0
Yes, reflection gives you the methods for dynamically loading classes at runtime, and yes you can compile a class from within an application, so the parts are all there. It is not exactly simple.
You might find it a lot easier to use one of the scripting languages that can dynamically create scripts and be executed in the JVM. See Groovy, JPython, JRuby and probably a bunch more.
Thanks everybody. I'll look into those scripting languages. I wanted to know if there is a possibility to dynamically extend a Java program. [ August 27, 2007: Message edited by: Yohan Liyanage ]
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35256
7
posted
0
I've found the Javassist library very useful for this. Since it creates real Java classes, I'd think it would be much faster that anything that involves a scripting language (assuming that those are essentially interpreted, not compiled to bytecode).