execute code from a string?

I have a Java program that draws lots of different types of curves.

I need to program how to save a drawing to a file.

It would be easiest to make a file that has the string of the code which recreates the drawing.

Is it possible to execute the content of a string?

A trivial example would be you declare an integer

int number

and you execute the string

"number = 10"

so that the value of number becomes 10.

Is this possible?

[487 byte] By [BrigitAnanyaa] at [2007-11-27 5:51:22]
# 1
JavaScript is part of 1.6 - ie you can execute a String that represents some valid JavaScript code. BeanShell is another scripting language, much closer (as in d@mn near identical with) Java.
pbrockway2a at 2007-7-12 15:40:25 > top of Java-index,Java Essentials,Java Programming...
# 2
However, how does your program draw the curve in the first place? What I mean is, if it draws the curve in response to some informatiion from the user, why not save that information as text and then draw the curve the same way when the text is read again later.
pbrockway2a at 2007-7-12 15:40:25 > top of Java-index,Java Essentials,Java Programming...