-
String Question...
How can i change a String to actual code? I.E. when i want to make a variable randomly?
like...
String tmp = "variable";
for (int i = 0; i<26; i++) {
ArrayList tmp+i = new ArrayList();
}
or having an array filled with random lines of code and picking them randomly and having them work?
sorry if it's not clear... i'm not sure how to word it myself.
-
Back up a bit and think about what you are proposing, then explain it better. How do you picture this program will run? Will the "randomly generated code" be self executing ... or placed in a file which will then be compiled and run? I don't know if you are proposing an on-the-fly self modifying program or a compiler.
-
This is more or less like storing a class defenition is a String variable and execute that..
This is not possible in Java. Once a class defenition is in place, we can instantiate that class and call its methods using reflection API.
But changing the variable name dynamically,defining the class dynamically, defining a class/method in a variable and create instance out of it etc. are not possible.
Still you can execute other scripts like javascripts (provided you have a script engine registered with the JRE, and it is there. mozilla rhino which is bundled with J2SE 6.0 does this..) in J2SE 6.0 . But execute Java program itself is not possible.(It is possible if a script engine for java itself registered in the JRE )
hope this clarifies
Last edited by sudheerprem; 12-15-2006 at 04:03 PM.
Similar Threads
-
By mdengler in forum ASP.NET
Replies: 0
Last Post: 11-26-2002, 02:32 PM
-
By Rob Teixeira in forum .NET
Replies: 129
Last Post: 06-06-2002, 05:23 AM
-
By Rob Teixeira in forum .NET
Replies: 15
Last Post: 05-31-2002, 03:30 PM
-
By Fred Mayes in forum Java
Replies: 1
Last Post: 06-05-2001, 06:12 AM
-
By Robert Rieth in forum VB Classic
Replies: 1
Last Post: 04-11-2000, 03:21 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks