vikash talanki wrote:...I need to know whether this approach of creating,compiling & instantiating a new class is possible from a single existing java program.
The basic answer to your question is 'yes'. For the answer to your unasked (and possibly more important) question "is it a good idea?", we'd need to know a lot more about the requirements.
I guess my questions to you would be:
Why do you think you need to generate a program/class for each form?What do these form classes do?How do you plan on managing them?Could your gazillion form classes be replaced by a single, or a few, slightly more complex classes, that use reflection?Could you instead publish metadata that allows a single class to do the work of the reams you're banging out at the moment?
Without answers to those questions it's difficult to know what to advise, but your setup has a definite clunky feel to me.
I saw a few projects that went down this road back in the 80's and they were, almost uniformly, disasters. Program-writing programs (or Class-writing classes) have their uses, but I suspect they still belong mostly to the purview of research on Turing-completeness or other such nerdy pastimes. They are also, because of their explosive nature, a b*tch to manage, and probably even worse to test.
But I am not able to get .class file for the new class. Can I instantiate the new class in the same program?? I was stuck at this point. Can any please help me
Sounds like you need to look at ClassLoader and it's offspring, but I think Rob's already steered you that way.
Winston