String Question...


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: String Question...

  1. #1
    Join Date
    Nov 2006
    Posts
    4

    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.

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    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.

  3. #3
    Join Date
    Dec 2006
    Location
    Kerala,India
    Posts
    51
    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 05:03 PM.

Similar Threads

  1. Input string was not in a correct format
    By mdengler in forum ASP.NET
    Replies: 0
    Last Post: 11-26-2002, 03:32 PM
  2. Re: App Object (fixes)
    By Rob Teixeira in forum .NET
    Replies: 129
    Last Post: 06-06-2002, 06:23 AM
  3. App Object
    By Rob Teixeira in forum .NET
    Replies: 15
    Last Post: 05-31-2002, 04:30 PM
  4. Replies: 1
    Last Post: 06-05-2001, 07:12 AM
  5. Database problems
    By Robert Rieth in forum VB Classic
    Replies: 1
    Last Post: 04-11-2000, 04: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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center