Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Executing a string related to source code, not the command line

Reply
Thread Tools

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

 
 
Arun
Guest
Posts: n/a
 
      12-30-2004
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.

 
Reply With Quote
 
 
 
 
Arun
Guest
Posts: n/a
 
      12-30-2004
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.

 
Reply With Quote
 
 
 
 
Michael Borgwardt
Guest
Posts: n/a
 
      01-03-2005
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/...#proginterface

But that's really not what you need to solve your problem.
 
Reply With Quote
 
Michael Borgwardt
Guest
Posts: n/a
 
      01-03-2005
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.
 
Reply With Quote
 
anonymous
Guest
Posts: n/a
 
      01-03-2005
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/...#proginterface
>
>
> But that's really not what you need to solve your problem.


Oh well, REXX has the interpret instruction. A life saver..
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Executing Command Line In C# jerry8989 Software 0 12-04-2008 08:05 PM
executing source command from perl david Perl Misc 5 02-29-2008 07:49 PM
Executing a Java application from command line Sharp Tool Java 7 07-20-2005 12:10 AM
Executing a command line applications... Brad Pears ASP General 18 10-01-2004 08:07 PM
Perl CGI executing command line functions Nick Perl Misc 14 10-03-2003 03:05 PM



Advertisments