Executing a string related to source code, not the command line

Discussion in 'Java' started by Arun, Dec 30, 2004.

  1. Arun

    Arun Guest

    How can i execute a string, for example:

    int x = 2;
    int y = 4;
    int z;
    String command = " z = x*y "


    For some background on why i want to do this:


    I have an element tree.
    To add a certain element, i need to use the following command:
    element.getChild("bla").setContent(newElement);

    Problem is that the number of .getChild() corresponds to the element
    depth in the tree.
    So if its depth was two, then the command would be:
    element.getChild("bla's dad").getChild("bla").setContent(newElement);

    I can't do a for loop and then with every iteration get the child from
    the previous child, because when i add an element i won't be adding it
    to the whole element tree, il just be adding it to the previous
    element.

    I could build the whole tree again but that seems wasteful.
    Arun, Dec 30, 2004
    #1
    1. Advertising

  2. Arun

    Arun Guest

    Let me rephrase the third paragraph:

    I cant do a for loop because when i add an element, i will only be
    adding it to its parent (which now will exist as its own element).
    Instead i want to add the element to the whole tree.
    Arun, Dec 30, 2004
    #2
    1. Advertising

  3. Michael Borgwardt, Jan 3, 2005
    #3
  4. Arun wrote:

    > Let me rephrase the third paragraph:
    >
    > I cant do a for loop because when i add an element, i will only be
    > adding it to its parent (which now will exist as its own element).
    > Instead i want to add the element to the whole tree.


    I'm not sure what you mean with "add the element to the whole tree",
    but whatever you want to do with that tree, you DON'T need to
    compile any java code on the fly for it! Loops and recursion (or stacks)
    can do anything that can be done with a tree.
    Michael Borgwardt, Jan 3, 2005
    #4
  5. Arun

    anonymous Guest

    Michael Borgwardt wrote:
    > Arun wrote:
    >
    >> How can i execute a string, for example:
    >>
    >> int x = 2;
    >> int y = 4;
    >> int z;
    >> String command = " z = x*y "

    >
    >
    > Compile it, then load the resulting class.
    > http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/javac.html#proginterface
    >
    >
    > But that's really not what you need to solve your problem.


    Oh well, REXX has the interpret instruction. A life saver..
    anonymous, Jan 3, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sharp Tool
    Replies:
    7
    Views:
    19,549
    Andrew Thompson
    Jul 20, 2005
  2. Brad Pears

    Executing a command line applications...

    Brad Pears, Sep 28, 2004, in forum: ASP General
    Replies:
    18
    Views:
    424
    Brad Pears
    Oct 1, 2004
  3. Nick
    Replies:
    14
    Views:
    317
    Tad McClellan
    Oct 3, 2003
  4. Monkey Man

    executing from command line

    Monkey Man, Feb 5, 2004, in forum: Perl Misc
    Replies:
    8
    Views:
    169
    Eric SALGON
    Feb 11, 2004
  5. david

    executing source command from perl

    david, Feb 28, 2008, in forum: Perl Misc
    Replies:
    5
    Views:
    328
    Ben Morrow
    Feb 29, 2008
Loading...

Share This Page